Score:5

WSL2 exits with code 1 on mount

nf flag

I'm a noob in both Windows and Linux, so please bear with me.

After playing with some commands, among others rm -rf bin my WSL2 distro exited and now I get the following when I try to boot it up through Windows Terminal:

Processing fstab with mount -a failed.

<3>WSL (10) ERROR: CreateProcessEntryCommon:570: execvpe /bin/bash failed 2
<3>WSL (10) ERROR: CreateProcessEntryCommon:579: Create process not expected to return

[process exited with code 1 (0x00000001)]

I have only one distro insalled.

Ubuntu 20.04 
Windows 11 Version 10.0.22000 Build 22000

WSL version:

PS C:\Users\Andreas> wsl -v
WSL version: 1.0.3.0
Kernel version: 5.15.79.1
WSLg version: 1.0.47
MSRDC version: 1.2.3575
Direct3D version: 1.606.4
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22000.1335

I am not using Docker and my /etc/passwd looks like:

PS C:\Users\Andreas>  wsl --system -d Ubuntu-20.04 -u root cat /mnt/wslg/distro/etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
systemd-timesync:x:102:104:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
messagebus:x:103:106::/nonexistent:/usr/sbin/nologin
syslog:x:104:110::/home/syslog:/usr/sbin/nologin
_apt:x:105:65534::/nonexistent:/usr/sbin/nologin
tss:x:106:111:TPM software stack,,,:/var/lib/tpm:/bin/false
uuidd:x:107:112::/run/uuidd:/usr/sbin/nologin
tcpdump:x:108:113::/nonexistent:/usr/sbin/nologin
sshd:x:109:65534::/run/sshd:/usr/sbin/nologin
landscape:x:110:115::/var/lib/landscape:/usr/sbin/nologin
pollinate:x:111:1::/var/cache/pollinate:/bin/false
bunny:x:1000:1000:,,,:/home/bunny:/bin/bash
postgres:x:112:120:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash
fwupd-refresh:x:113:121:fwupd-refresh user,,,:/run/systemd:/usr/sbin/nologin

I have tried

wsl --update

Can I fix the issue or do I need to re-install?

NotTheDr01ds avatar
vn flag
Welcome to Ask Ubuntu! Sorry to hear about that! Instead of checking the `passwd` file, try `wsl --system -d Ubuntu-20.04 -e ls /mnt/wslg/distro/bin`. Is there anything in the main distro's `/bin`?
AndyOh avatar
nf flag
Thanks. There's a wslpath
NotTheDr01ds avatar
vn flag
Okay, then you definitely erased the `/bin` :-(. The only recovery will be reinstall. Do you need to recover any files from the damaged one? I'm away from the PC at the moment, so instructions for that will be a bit delayed if you do need them.
AndyOh avatar
nf flag
Yes, I have a few files I'd like to recover but not that many. The settings are more valuable to me I think. On another forum someone suggested spinning up a new distro with the same Ubuntu version and copy over the bin folder. Any idea if that is viable? I hope I'm allowed to post this: https://www.reddit.com/r/bashonubuntuonwindows/comments/zuwiv9/wsl2_exits_with_code_1_on_mount/
NotTheDr01ds avatar
vn flag
Let me think if there's a way to do that without causing issues. A straight-up copy will be missing anything that was installed via `apt` after the initial installation.
AndyOh avatar
nf flag
Thanks for your help. I'm creating a new distro either way. I don't have any vitally important data.
Score:0
vn flag

You will likely need to reinstall, but let's go through the issue:

  • The problem started after an rm -rf bin. Well, that could be disastrous depending on exactly how it was done.

    For instance, if you are in your home directory and execute that command, then only the contents of the ~/bin directory (if it existed) would be removed.

    Even if you were in the root directory when you issued the command, your normal user shouldn't have been able to delete /bin. You would normally get:

    rm: cannot remove 'bin': Permission denied
    

    However, if you:

    • Were in the root directory, or used /bin and ...
    • Were running as the root user, or used sudo rm -rf /bin

    Well that would be unrecoverable without a reinstall. However, if you have critical files that you need to recover, that's possible (see the "File Recovery" section below).

    The fact that WSL is having an issue running the default shell (/bin/bash) is a strong indicator that you actually did delete the directory.

  • Side-note:

    You show the output from the command:

    wsl --system -d Ubuntu-20.04 -u root cat /mnt/wslg/distro/etc/passwd
    

    I'd be curious (via comment) where you came up with that command. That's an interesting method to attempt recovery that I hadn't thought of. But what you really should try is:

    wsl --system -d Ubuntu-22.04 -e ls /mnt/wslg/distro/bin
    

    If the /bin directory in the main distribution (mounted in the system distro as /mnt/wslg/distro) is empty, then you truly have corrupted the distribution. (Confirmed via comments)

File recovery

If you'd like to access files in the or settings in the old distro, you can back it up before reinstalling and access it later.

To do so:

  • From PowerShell, wsl --shutdown

  • Run the following from PowerShell to determine the location of the virtual drive:

    Get-ChildItem HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss\ |
        ForEach-Object {
            (Get-ItemProperty $_.PSPATH) | Select-Object DistributionName,BasePath
        }
    

    In the resulting location, you'll find a LocalState directory with the ext4.vhdx file. This is the virtual drive that contains all of the Ubuntu/WSL2 files.

  • Copy the ext4.vhdx to a safe location.

  • Optionally, check that the hash of the backed up file matches the original.

  • From PowerShell again, wsl --unregister Ubuntu-20.04 (adjust this if your distro name varies)

  • Re-run ubuntu2004.exe, which will re-create a fresh ext4.vhdx file and create a user/password in that distro.

  • In the new distro, sudo apt update && sudo apt upgrade -y

  • Exit back to PowerShell.

  • In PowerShell, run wsl --mount --name olddistro <path_to_backed_up>\ext4.vhdx --vhd

  • Start Ubuntu again

  • The files from your old distro are available at /mnt/wsl/olddistro/. For instance, you should find the files from your old home directory at /mnt/wsl/olddistro/home/<username>.

When done copying the old files over to the new distro, you can simply delete the old (backed up) ext4.vhdx.

AndyOh avatar
nf flag
Checking etc/passwd was a suggestion to an similar issue on microsoft's wsl github: https://github.com/microsoft/WSL/issues/9018
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.