subsystemctl
subsystemctl copied to clipboard
can't cat /proc/sys/fs/binfmt_misc/WSLInterop Too many levels of symbolic links
While in the environment cat /proc/sys/fs/binfmt_misc/WSLInterop
produces this error
Too many levels of symbolic links
This breaks wslu
Looks like this was solved in another project by disabling some systemd services and explictly mounting binfmt_misc: https://github.com/DamionGans/ubuntu-wsl2-systemd-script/issues/15 https://github.com/DamionGans/ubuntu-wsl2-systemd-script/pull/17/files
It'd be great to have these changes ported here, as disabling the service alone doesn't fix the issue.
I resolved the issue locally by mounting binfmt:
diff --git a/src/bottle.rs b/src/bottle.rs
index f04804a..cbb4768 100644
--- a/src/bottle.rs
+++ b/src/bottle.rs
@@ -243,6 +243,14 @@ fn exec_systemd2_child(systemd_bin: CString) -> Result<(), error::Error> {
)
.expect("proc mount failure");
+ nix::mount::mount(
+ Some(OsStr::new("binfmt_misc")),
+ OsStr::new("/proc/sys/fs/binfmt_misc"),
+ Some(OsStr::new("binfmt_misc")),
+ MsFlags::MS_NOSUID | MsFlags::MS_NODEV | MsFlags::MS_NOEXEC,
+ OS_NONE,
+ )
+ .expect("binfmt mount failure");
nix::unistd::chdir("/").unwrap();
nix::unistd::setgid(nix::unistd::Gid::from_raw(0)).unwrap();
nix::unistd::setuid(nix::unistd::Uid::from_raw(0)).unwrap();
and disabling binfmt mount related services
sudo mkdir -p /etc/systemd/wsl2-incompatible/user/sockets.target.wants/ /lib/systemd/wsl2-incompatible/system/sysinit.target.wants/ /usr/lib/systemd/wsl2-incompatible/system/
# remove binfmt mounting done by systemd because it doesn't work and triggers 'too many simlinks error
sudo mv /lib/systemd/system/sysinit.target.wants/proc-sys-fs-binfmt_misc.automount /lib/systemd/wsl2-incompatible/system/sysinit.target.wants/
sudo mv /lib/systemd/system/sysinit.target.wants/systemd-binfmt.service /lib/systemd/wsl2-incompatible/system/sysinit.target.wants/
sudo mv /usr/lib/systemd/system/proc-sys-fs-binfmt_misc.automount /usr/lib/systemd/wsl2-incompatible/system/
sudo mv /usr/lib/systemd/system/proc-sys-fs-binfmt_misc.mount /usr/lib/systemd/wsl2-incompatible/system/