Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't cat /proc/sys/fs/binfmt_misc/WSLInterop Too many levels of symbolic links #11

Open
QAston opened this issue Jul 10, 2021 · 2 comments · May be fixed by #12
Open

can't cat /proc/sys/fs/binfmt_misc/WSLInterop Too many levels of symbolic links #11

QAston opened this issue Jul 10, 2021 · 2 comments · May be fixed by #12

Comments

@QAston
Copy link
Contributor

QAston commented Jul 10, 2021

While in the environment cat /proc/sys/fs/binfmt_misc/WSLInterop produces this error

Too many levels of symbolic links

This breaks wslu

@QAston
Copy link
Contributor Author

QAston commented Jul 10, 2021

Looks like this was solved in another project by disabling some systemd services and explictly mounting binfmt_misc:
DamionGans/ubuntu-wsl2-systemd-script#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.

@QAston
Copy link
Contributor Author

QAston commented Jul 11, 2021

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant