nullpo-head/wsl-distrod

[Bug]: cannot access '/proc/sys/fs/binfmt_misc': Too many levels of symbolic links

akuropka opened this issue ยท 5 comments

Describe the bug

/proc/sys/fs/binfmt_misc cannot be accessed due too many levels of symbolic links.

Steps to reproduce

Install a WSL distro through distrod_wsl_launcher or update one through install script.

Expected behavior

/proc/sys/fs/binfmt_misc is still available.

Windows version

Microsoft Windows [Version 10.0.22000.466]

Linux kernel version

Linux 5.10.93.3-microsoft-WSL2 #1 SMP Sun Jan 23 18:53:16 CET 2022 x86_64 GNU/Linux

Distro

archlinux

How did you install that distro?

Enabled distrod in an existing WSL2 distro

Logs

[andi@ANDI distrod_wsl_launcher-x86_64]$ ls -al /proc/sys/fs/binfmt_misc
ls: cannot access '/proc/sys/fs/binfmt_misc': Too many levels of symbolic links

additional comment

Should be the same issue as in DamionGans/ubuntu-wsl2-systemd-script#17.

I stopped having this issue when I installed clang, I think it installs a package called binfmt-support. So as a workaround you could install this package to resolve this issue.

This seems to solve the problem:
sudo apt install binfmt-support

wslview also works without complaining.

I'm currently having the same issue with the Arch image and the wslu tools. Unfortunately there doesn't seem to be a binfmt-support package in the Arch repos.

From arkane-systems/genie#142 sudo mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc seems to work for me, but it only solves the issue for the current session. Is there anything that solves the problem across sessions?

YJ2CS commented

I'm currently having the same issue with the Arch image and the wslu tools. Unfortunately there doesn't seem to be a package in the Arch repos.binfmt-support

From arkane-systems/genie#142 seems to work for me, but it only solves the issue for the current session. Is there anything that solves the problem across sessions?sudo mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc

I am aware of this solution provided by genie, and inspired by it, I have adopted the following solution:
Create a new /etc/systemd/system/rc-local.service

sudo vim /etc/systemd/system/rc-local.service

The modifications are as follows, mainly to add Install field information

# SPDX-License-Identifier: LGPL-2.1+
#
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

[Install]
WantedBy=multi-user.target

The Unit field mainly describes the startup sequence and dependencies of the service, the Service field mainly describes how to start, and the Install field describes how to install the service.

Manually create a /etc/rc.local

sudo vim /etc/rc.local

Write the commands that need to be executed at startup to a file, for example

#!/bin/bash
# Note the line above
ls /proc/sys/fs/binfmt_misc > /dev/null 2>&1 || \
  mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc

Also, don't forget to add executable permissions to /etc/rc.local

sudo chmod a+x /etc/rc.local

Then enable rc-local.service and let it start automatically at boot

sudo systemctl enable rc-local

Then start the service and check its status

sudo systemctl start rc-local.service
sudo systemctl status rc-local.service

At this point, rc-local.service should work properly.

Then edit systemd-binfmt.service

sudo systemctl edit systemd-binfmt.service

in the position shown in the figure below
image

Fill in the following to start rc-local.service first, then systemd-binfmt.service

[Unit]
After=rc-local.service

Then press ctrl+x and a prompt related to saving will appear,

Then press Enter to successfully save the configuration

restart WSL

sudo systemctl reboot

success

Can confirm that this solution fixed the issue for me. Thank you very much!