diff --git a/distrobox-init b/distrobox-init index d5bd955a3b..2bc2f86bd9 100755 --- a/distrobox-init +++ b/distrobox-init @@ -349,12 +349,37 @@ if [ "${shell_pkg}" = "ash" ]; then shell_pkg="bash" fi +# Check dependencies in a list, and install all if one is missing +missing_packages=0 +dependencies=" + bc + chpasswd + curl + diff + find + findmnt + less + lsof + mount + passwd + pinentry + ps + script + sudo + time + umount + useradd + wc + wget + ${shell_pkg} +" +for dep in ${dependencies}; do + ! command -v "${dep}" && missing_packages=1 && break +done + # Check if dependencies are met for the script to run. -if [ "${upgrade}" -ne 0 ] || ! command -v find || ! command -v mount || ! command -v passwd || - ! command -v sudo || ! command -v useradd || ! command -v diff || - ! command -v pinentry || ! command -v wget || ! command -v curl || - ! command -v less || ! command -v bc || ! command -v time || ! command -v lsof || - ! command -v "${shell_pkg}" || +if [ "${upgrade}" -ne 0 ] || + [ "${missing_packages}" -ne 0 ] || { [ -n "${container_additional_packages}" ] && [ ! -e /.containersetupdone ]; }; then # Detect the available package manager @@ -1835,6 +1860,23 @@ if [ -e /dev/console ]; then fi fi +if [ -e /etc/inittab ]; then + # Cleanup openrc to not interfere with the host + sed -i 's/^\(tty\d\:\:\)/#\1/g' /etc/inittab + sed -i \ + -e 's/#rc_env_allow=".*"/rc_env_allow="\*"/g' \ + -e 's/#rc_crashed_stop=.*/rc_crashed_stop=NO/g' \ + -e 's/#rc_crashed_start=.*/rc_crashed_start=YES/g' \ + -e 's/#rc_provide=".*"/rc_provide="loopback net"/g' \ + /etc/rc.conf + rm -f /etc/init.d/hwdrivers \ + /etc/init.d/hwclock \ + /etc/init.d/hwdrivers \ + /etc/init.d/modules \ + /etc/init.d/modules-load \ + /etc/init.d/modloop +fi + if command -v systemctl 2> /dev/null; then # Cleanup systemd to not interfere with the host UNIT_TARGETS=" @@ -1887,7 +1929,6 @@ ExecStart=sh -c "ln -sf /run/host/run/user/\$(id -ru)/keyring/ /run/user/\$(id - ln -sf /run/host/run/user/\$(id -ru)/.mutter* /run/user/\$(id -ru)/" Slice=user-%i.slice EOF - fi # Now we can launch init diff --git a/docs/usage/distrobox-create.md b/docs/usage/distrobox-create.md index cb1b0bc881..93dc6ad787 100644 --- a/docs/usage/distrobox-create.md +++ b/docs/usage/distrobox-create.md @@ -169,6 +169,15 @@ Note that enabling `--init` **will disable host's process integration**. From within the container you will not be able to see and manage host's processes. This is needed because `/sbin/init` must be pid 1. +If you want to use a non-pre-create image, you'll need to add the additional package: + + distrobox create -i alpine:latest --init --additional-packages "openrc" -n test + distrobox create -i debian:stable --init --additional-packages "systemd libpam-systemd" -n test + distrobox create -i ubuntu:22.04 --init --additional-packages "systemd libpam-systemd" -n test + distrobox create -i archlinux:latest --init --additional-packages "systemd" -n test + distrobox create -i registry.opensuse.org/opensuse/tumbleweed:latest --init --additional-packages "systemd" -n test + distrobox create -i registry.fedoraproject.org/fedora:38 --init --additional-packages "systemd" -n test + The `--home` flag let's you specify a custom HOME for the container. Note that this will NOT prevent the mount of the host's home directory, but will ensure that configs and dotfiles will not litter it. diff --git a/docs/useful_tips.md b/docs/useful_tips.md index 3545d70108..c8b8817ddd 100644 --- a/docs/useful_tips.md +++ b/docs/useful_tips.md @@ -187,8 +187,8 @@ Simply use: ## Export to the host -Distrobox supports exporting to the host either binaries, applications or systemd -services. [Head over the usage page to have an explanation and examples.](usage/distrobox-export.md) +Distrobox supports exporting to the host either binaries or applications. +[Head over the usage page to have an explanation and examples.](usage/distrobox-export.md) ## Execute commands on the host @@ -248,8 +248,11 @@ You can use such feature using: If you want to use a non-pre-create image, you'll need to add the additional package: -`distrobox create -i debian:unstable --init --additional-packages "systemd" -n test` -`distrobox create -i ubuntu:18.04 --init --additional-packages "systemd" -n test` +`distrobox create -i alpine:latest --init --additional-packages "openrc" -n test` +`distrobox create -i debian:stable --init --additional-packages "systemd libpam-systemd" -n test` +`distrobox create -i ubuntu:22.04 --init --additional-packages "systemd libpam-systemd" -n test` +`distrobox create -i archlinux:latest --init --additional-packages "systemd" -n test` +`distrobox create -i registry.opensuse.org/opensuse/tumbleweed:latest --init --additional-packages "systemd" -n test` `distrobox create -i registry.fedoraproject.org/fedora:38 --init --additional-packages "systemd" -n test` Note however that in this mode, you'll not be able to access host's processes