Skip to content

Startup fails with "unshare: mount ... on ... failed: Invalid argument" #292

@nzbr

Description

@nzbr

Bug description

When trying to start NixOS-WSL, it fails with an error like

[ERROR] systemd startup failed!
[ERROR] stderr:
unshare: mount /proc/455/ns/mnt on /run/nixos-wsl/ns/mount failed: Invalid argument
+ grep -q binfmt_misc /proc/filesystems
+ mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc
+ exec systemd
[ERROR] stdout:

To Reproduce

Update WSL to the new 2.0.0.0 release and try to start NixOS using syschdemd

Resolution

Run the following commands to update to the latest NixOS-WSL version and switch to native systemd:

wsl -d NixOS -e /nix/var/nix/profiles/system/sw/bin/bash

This shoudl give you a root shell in the NixOS distro. From there run:

/nix/var/nix/profiles/system/activate
. /etc/set-environment

Now update NixOS-WSL by running

rm -rf /etc/nixos/nixos-wsl
curl -L https://api.github.com/repos/nix-community/nixos-wsl/tarball/main | tar -xzv
mv nix-community-NixOS-WSL-* /etc/nixos/nixos-wsl
nix-channel --add https://nixos.org/channels/nixos-23.05 nixos
nix-channel --update

Use an Editor (nano/vim) to edit /etc/nixos/configuration.nix and set the option

    wsl.nativeSystemd = true;

Save the file and run (this will print some errors, but that's fine)

nixos-rebuild switch

After that, exit back to your windows shell and run

wsl -t NixOS
wsl -d NixOS

If this gives you a shell as the default user, everything should be working again

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions