init: use findmnt instead of mountpoint, fixing compatibility with old distributions. Fix #370

Signed-off-by: Luca Di Maio <luca.dimaio1@gmail.com>
This commit is contained in:
Luca Di Maio
2022-09-30 18:28:40 +02:00
parent bb496cd4e3
commit 819b782a1c
3 changed files with 5 additions and 16 deletions

View File

@@ -180,7 +180,7 @@ mount_bind() (
! [ -d "${source_dir}" ] && ! [ -f "${source_dir}" ] && return 0
# if target_dir exists, check if it is a mountpoint and umount it.
if [ -e "${target_dir}" ] && mountpoint "${target_dir}"; then
if [ -e "${target_dir}" ] && findmnt "${target_dir}" > /dev/null; then
umount "${target_dir}"
fi
# if the source_dir exists, then create the target_dir
@@ -846,7 +846,7 @@ if [ -d "/etc/dpkg/dpkg.cfg.d/" ]; then
printf "distrobox: Setting up apt hooks...\n"
printf "" > /etc/apt/apt.conf.d/00_distrobox
for init_mount in ${HOST_MOUNTS_RO_INIT}; do
printf 'DPkg::Pre-Invoke {"if mountpoint %s; then umount %s; fi";};\n' \
printf 'DPkg::Pre-Invoke {"if findmnt %s >/dev/null; then umount %s; fi";};\n' \
"${init_mount}" "${init_mount}" >> /etc/apt/apt.conf.d/00_distrobox
printf 'DPkg::Post-Invoke {"if [ -e /run/host/%s ]; then mount --rbind /run/host/%s %s; fi";};\n' \
"${init_mount}" "${init_mount}" "${init_mount}" >> /etc/apt/apt.conf.d/00_distrobox
@@ -866,7 +866,7 @@ if [ -d "/usr/share/libalpm/scripts" ]; then
printf "#!/bin/sh\n" > /usr/share/libalpm/scripts/02_distrobox_post_hook.sh
chmod +x /usr/share/libalpm/scripts/*distrobox*.sh
for net_mount in ${HOST_MOUNTS_RO}; do
printf "if mountpoint %s; then umount %s; fi\n" \
printf "if findmnt %s >/dev/null; then umount %s; fi\n" \
"${net_mount}" "${net_mount}" >> /usr/share/libalpm/scripts/00_distrobox_pre_hook.sh
printf "if [ -e /run/host/%s ]; then mount --rbind -o ro /run/host/%s %s; fi\n" \
"${net_mount}" "${net_mount}" "${net_mount}" >> /usr/share/libalpm/scripts/02_distrobox_post_hook.sh
@@ -1035,7 +1035,7 @@ if [ "${init}" -eq 0 ]; then
# We only do this, if the file is a bind mount in the first place.
# This could be useful for init-hooks that involve umounting those
# files so that can be separated from the host.
mountpoint "${file_watch}" &&
findmnt "${file_watch}" > /dev/null &&
umount "${file_watch}" &&
mount_bind "/run/host${file_watch}" "${file_watch}" rw
fi
@@ -1051,7 +1051,7 @@ printf "distrobox: Setting up init system...\n"
# the init system. If they're mounts, there might
# be problems. Let's unmount them.
for host_mount in ${HOST_MOUNTS_RO_INIT}; do
if mountpoint "${host_mount}"; then umount "${host_mount}"; fi
if findmnt "${host_mount}" > /dev/null; then umount "${host_mount}"; fi
done
if command -v systemctl 2> /dev/null; then
# Cleanup systemd to not interfere with the host

View File

@@ -79,7 +79,6 @@ graphical apps (X11/Wayland), and audio.
- [Using init system inside a distrobox](useful_tips.md#using-init-system-inside-a-distrobox)
- [Using distrobox as main cli](useful_tips.md#using-distrobox-as-main-cli)
- [Using a different architecture](useful_tips.md#using-a-different-architecture)
- [Improve distrobox-enter performance](useful_tips.md#improve-distrobox-enter-performance)
- [Slow creation on podman and image size getting bigger with distrobox-create](useful_tips.md#slow-creation-on-podman-and-image-size-getting-bigger-with-distrobox-create)
- [Container save and restore](useful_tips.md#container-save-and-restore)
- [Check used resources](useful_tips.md#check-used-resources)

View File

@@ -15,7 +15,6 @@
- [Using init system inside a distrobox](#using-init-system-inside-a-distrobox)
- [Using distrobox as main cli](#using-distrobox-as-main-cli)
- [Using a different architecture](#using-a-different-architecture)
- [Improve distrobox enter performance](#improve-distrobox-enter-performance)
- [Slow creation on podman and image size getting bigger with distrobox create](#slow-creation-on-podman-and-image-size-getting-bigger-with-distrobox-create)
- [Container save and restore](#container-save-and-restore)
- [Check used resources](#check-used-resources)
@@ -296,15 +295,6 @@ aarch64
![image](https://user-images.githubusercontent.com/598882/170837120-9170a9fa-6153-4684-a435-d60a0136b563.png)
## Improve distrobox enter performance
If you are experiencing a bit slow performance using `podman` you should enable
the podman socket using
`systemctl --user enable --now podman.socket`
this will improve a lot `podman`'s command performances.
## Slow creation on podman and image size getting bigger with distrobox create
For rootless podman 3.4.0 and upward, adding this to your `~/.config/containers/storage.conf`