Snapd shows up as unavailable inside WSL

This is a cross-posting from WSL-2 issues

snapd shows up as unavailable inside WSL however snap appears to be working for me:

sudo snap install firefox
snap "firefox" is already installed, see 'snap help refresh'
mwoodpatrick@westie-k0s:~$ sudo snap  refresh firefox
snap "firefox" has no updates available

systemctl says it’s running:

sudo systemctl status snapd
● snapd.service - Snap Daemon
     Loaded: loaded (/lib/systemd/system/snapd.service; enabled; preset: enabled)
     Active: active (running) since Sat 2023-02-25 06:49:52 PST; 35min ago
TriggeredBy: ● snapd.socket
   Main PID: 323 (snapd)
      Tasks: 22 (limit: 38340)
     Memory: 93.1M
     CGroup: /system.slice/snapd.service
             └─323 /usr/lib/snapd/snapd

Feb 25 06:49:49 mlwphpenvy360 systemd[1]: Starting Snap Daemon...
Feb 25 06:49:51 mlwphpenvy360 snapd[323]: overlord.go:268: Acquiring state lock file
Feb 25 06:49:51 mlwphpenvy360 snapd[323]: overlord.go:273: Acquired state lock file
Feb 25 06:49:52 mlwphpenvy360 snapd[323]: daemon.go:247: started snapd/2.58.2 (series 16; classic; devmode; wsl) ubuntu/22.10 (amd>
Feb 25 06:49:52 mlwphpenvy360 snapd[323]: daemon.go:340: adjusting startup timeout by 1m5s (pessimistic estimate of 30s plus 5s pe>
Feb 25 06:49:52 mlwphpenvy360 snapd[323]: backends.go:58: AppArmor status: apparmor not enabled
Feb 25 06:49:52 mlwphpenvy360 systemd[1]: Started Snap Daemon.
Feb 25 07:20:30 mlwphpenvy360 snapd[323]: api_snaps.go:366: Installing snap "nvim" revision unset
Feb 25 07:22:26 mlwphpenvy360 snapd[323]: api_snaps.go:366: Installing snap "firefox" revision unset
Feb 25 07:23:06 mlwphpenvy360 snapd[323]: api_snaps.go:366: Installing snap "firefox" revision unset

However, I still see snap version reporting snapd is unavailable:

sudo snap version
snap                         2.58.2
snapd                        unavailable
series                       16
Windows Subsystem for Linux  -
kernel                       5.15.90.1-microsoft-standard-WSL2 (amd64)

My WSL version command reports:

wsl.exe --version
WSL version: 1.1.3.0
Kernel version: 5.15.90.1
WSLg version: 1.0.49
MSRDC version: 1.2.3770
Direct3D version: 1.608.2-61064218
DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp
Windows version: 10.0.22623.1325

When I try to create a snap I get the following error. Since I would really like to be able to create and use snaps on WSL-2 I would really like to understand what functionality is missing in WSL-2 to fix these issues

Support for ‘multipass’ needs to be set up. Would you like to do it now? [y/N]: y snapd is not logged in, snap install commands will use sudo multipass 1.11.0 from Canonical✓ installed Waiting for multipass… Launching a VM. warning: “–mem” long option will be deprecated in favour of “–memory” in a future release.Please update any scripts, etc. launch failed: multipass socket access denied Please check that you have read/write permissions to ‘/var/snap/multipass/common/multipass_socket’ An error occurred with the instance when trying to launch with ‘multipass’: returned exit code 2. Ensure that ‘multipass’ is setup correctly and try again. mwoodpatrick@westie-k0s:~/projects/git/westie-dev-pnpm/snaps/hello (13-nx-kubernetes)$ sudo snapcraft Running with ‘sudo’ may cause permission errors and is discouraged. Use ‘sudo’ when cleaning. Launching a VM. warning: “–mem” long option will be deprecated in favour of “–memory” in a future release.Please update any scripts, etc. [2023-02-25T08:21:28.988] [error] [dnsmasq] dnsmasq: failed to create inotify: Too many open files

[2023-02-25T08:21:28.990] [error] [dnsmasq] dnsmasq died: Process returned exit code: 5 [2023-02-25T08:21:28.990] [error] [dnsmasq] dnsmasq died: Process returned exit code: 5 [2023-02-25T08:21:28.990] [error] [dnsmasq] dnsmasq died: Process returned exit code: 5 launch failed: dnsmasq died: Process returned exit code: 5 An error occurred with the instance when trying to launch with ‘multipass’: returned exit code 2. Ensure that ‘multipass’ is setup correctly and try again.

How have you setup systemd to run?

The recommended way is to write

[boot]
systemd=true

into /etc/wsl.conf

But historically there’s been other ways such as Genie, or using unshare & etc. They probably shouldn’t be peoples go to, now that WSL2 has official systemd support.

Ensure you run wsl --update in the Windows shell too, to grab the latest release.

systemd is running I use it on a regular basis without problem and the distro is upto date.

When I run the same command on my multipass distro I get:

snapcraft Launching a VM. Build environment is in unknown state, cleaning first. info failed: The following errors occurred: instance “snapcraft-hello” does not exist warning: “–mem” long option will be deprecated in favour of “–memory” in a future release.Please update any scripts, etc. launch failed: KVM support is not enabled on this machine. Please ensure the following: 1. The system’s CPU supports virtualization. 2. Virtualization is enabled in the system BIOS. 3. The KVM kernel modules are loaded. An error occurred with the instance when trying to launch with ‘multipass’: returned exit code 2. Ensure that ‘multipass’ is setup correctly and try again.

Ah my apoligies, I can see you’re actually on the pre-release version of WSL which might itself cause problems. The latest stable WSL version is 1.0.3, which in my testing on Win 11 works fine if using the built in systemd support. The 1.1 pre-releases had a lot of problems from what I’d seen so far, so it might be worth rolling back to 1.0.3 for testing purposes.

Regarding the Multipass aspect: KVM support is not enabled on this machine.

Are you using an AMD CPU? Nested virtualisation isn’t available on Windows 10 for AMD CPU’s, which would be an outright blocker for Multipass in WSL2. You’d still be able to make use of LXD though. AMD nested virtualisation in Hyper V was added in Windows 11, so you’d be able to make use of Multipass in WSL2 in Win 11, assuming CPU support is the issue. Edit: Strangely build 22623 is actually Windows 11, so nested virtualisation support likely isn’t actually the issue with Multipass, but on build 22621, there’s no problem for me unfortunately, Multipass “just works” with no extra setup.

sudo snap install lxd
sudo lxd init --auto
snapcraft --use-lxd

(or snapcraft for Core22 snaps, where LXD is default).

When running in a multipass VM on windows 11 (build 10.0.22623.1325) and WSL-2 (version 1.1.3.0) when I run

multipass start snapcraft-hello

The error I get is:

start failed: The following errors occurred: qemu-system-x86_64: cannot set up guest memory ‘pc.ram’: Cannot allocate memory

I would like to be able to debug this issue rather than revert my WSL-2 version. Any pointers would be appreciated

Increasing the memory available in the multipass host let it get further but then it failed and when running it failed with

multipass start snapcraft-hello start failed: The following errors occurred: Instance ‘snapcraft-hello’ is already running, but in an unknown state snapcraft-hello: timed out waiting for response

Are there any logs generated by snapcraft?

It appears that both multipass and snapcraft are symbolic links to snap

ubuntu@westie-multipass:~/projects/git/westie-dev-pnpm/snaps/hello$ ls -l /snap/bin/snapcraft

lrwxrwxrwx 1 root root 13 Feb 26 12:07 /snap/bin/snapcraft -> /usr/bin/snap ubuntu@westie-multipass:~/projects/git/westie-dev-pnpm/snaps/hello

$ which multipass

/snap/bin/multipass

ubuntu@westie-multipass: ~/projects/git/westie-dev-pnpm/snaps/hello$ ls -l /snap/bin/multipass

lrwxrwxrwx 1 root root 13 Feb 26 12:08 /snap/bin/multipass -> /usr/bin/snap