From 3a65cbea0e066ed2aa2f5fb73e4593a53df25d09 Mon Sep 17 00:00:00 2001 From: Pablo ROMERO QUINTEROS Date: Wed, 2 Dec 2020 12:51:11 +0100 Subject: [PATCH 1/3] Change systemd target to multi-user This run a lot of needed services as cron and fix the snap mounting after reboot, which is also a "all snap packages broken" issue. --- start-systemd-namespace | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start-systemd-namespace b/start-systemd-namespace index 6218ef7..7264813 100755 --- a/start-systemd-namespace +++ b/start-systemd-namespace @@ -1,6 +1,6 @@ #!/bin/sh -SYSTEMD_EXE="/lib/systemd/systemd --unit=basic.target" +SYSTEMD_EXE="/lib/systemd/systemd --unit=multi-user.target" SYSTEMD_PID="$(ps -eo pid=,args= | awk '$2" "$3=="'"$SYSTEMD_EXE"'" {print $1}')" if [ "$LOGNAME" != "root" ] && ( [ -z "$SYSTEMD_PID" ] || [ "$SYSTEMD_PID" != "1" ] ); then export | sed -e 's/^declare -x //;/^IFS=".*[^"]$/{N;s/\n//}' | \ From 5871f270775a303c913935adeea67b6a9a810dc0 Mon Sep 17 00:00:00 2001 From: Pablo ROMERO QUINTEROS Date: Wed, 2 Dec 2020 12:51:42 +0100 Subject: [PATCH 2/3] Change systemd target to multi-user This run a lot of needed services as cron and fix the snap mounting after reboot, which is also a "all snap packages broken" issue. --- enter-systemd-namespace | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/enter-systemd-namespace b/enter-systemd-namespace index d7a949d..d1b25d4 100755 --- a/enter-systemd-namespace +++ b/enter-systemd-namespace @@ -24,7 +24,7 @@ if ! command -v /usr/bin/unshare > /dev/null; then exit 1 fi -SYSTEMD_EXE="/lib/systemd/systemd --unit=basic.target" +SYSTEMD_EXE="/lib/systemd/systemd --unit=multi-user.target" SYSTEMD_PID="$(ps -eo pid=,args= | awk '$2" "$3=="'"$SYSTEMD_EXE"'" {print $1}')" if [ -z "$SYSTEMD_PID" ]; then "$DAEMONIZE" /usr/bin/unshare --fork --pid --mount-proc bash -c 'export container=wsl; mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc; exec '"$SYSTEMD_EXE" From c7a27fda75f712afddcc578043f27cdd24c483b5 Mon Sep 17 00:00:00 2001 From: Pablo ROMERO QUINTEROS Date: Wed, 2 Dec 2020 15:37:19 +0100 Subject: [PATCH 3/3] Disable systemd to change WSL name resolution Disable systemd services from overwrite original WSL /etc/resolv.conf file --- ubuntu-wsl2-systemd-script.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ubuntu-wsl2-systemd-script.sh b/ubuntu-wsl2-systemd-script.sh index 5c32f2a..880868e 100755 --- a/ubuntu-wsl2-systemd-script.sh +++ b/ubuntu-wsl2-systemd-script.sh @@ -76,6 +76,9 @@ sudo rm -f /etc/systemd/user/sockets.target.wants/gpg-agent*.socket sudo rm -f /lib/systemd/system/sysinit.target.wants/proc-sys-fs-binfmt_misc.automount sudo rm -f /lib/systemd/system/sysinit.target.wants/proc-sys-fs-binfmt_misc.mount sudo rm -f /lib/systemd/system/sysinit.target.wants/systemd-binfmt.service +sudo rm -f /etc/systemd/system/multi-user.target.wants/systemd-resolved.service +sudo rm -f /etc/systemd/system/dbus-org.freedesktop.resolve1.service + if [ -f /proc/sys/fs/binfmt_misc/WSLInterop ] && [ "$(head -n1 /proc/sys/fs/binfmt_misc/WSLInterop)" == "enabled" ]; then "$(interop_prefix)$(sysdrive_prefix)"/Windows/System32/cmd.exe /C setx WSLENV BASH_ENV/u