WSL: snapd does not work inside WSL

Version

10.0.22621.674

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

5.15.68.1

Distro Version

Ubuntu 22.10

Other Software

No response

Repro Steps

Run systemctl --failed

Expected Behavior

Functional snapd service

Actual Behavior

toor@XPS:~$ systemctl status snapd
● snapd.service - Snap Daemon
     Loaded: loaded (/lib/systemd/system/snapd.service; enabled; preset: enabled)
     Active: active (running) since Sun 2022-10-16 17:42:14 PDT; 3min 9s ago
TriggeredBy: ● snapd.socket
   Main PID: 181 (snapd)
      Tasks: 11 (limit: 4697)
     Memory: 44.6M
     CGroup: /system.slice/snapd.service
             └─181 /usr/lib/snapd/snapd

Oct 16 17:42:14 XPS systemd[1]: Starting Snap Daemon...
Oct 16 17:42:14 XPS snapd[181]: AppArmor status: apparmor not enabled
Oct 16 17:42:14 XPS snapd[181]: overlord.go:263: Acquiring state lock file
Oct 16 17:42:14 XPS snapd[181]: overlord.go:268: Acquired state lock file
Oct 16 17:42:14 XPS snapd[181]: daemon.go:247: started snapd/2.57.4+22.10ubuntu1 (series 16; classic; devmode; wsl) ubuntu/22.10 (amd64) linux/5.15.68.1-microsoft-stand.
Oct 16 17:42:14 XPS snapd[181]: main.go:129: system does not fully support snapd: snapd does not work inside WSL
Oct 16 17:42:14 XPS snapd[181]: daemon.go:340: adjusting startup timeout by 55s (pessimistic estimate of 30s plus 5s per snap)
Oct 16 17:42:14 XPS systemd[1]: Started Snap Daemon.
toor@XPS:~$ snap list
Interacting with snapd is not yet supported on Windows Subsystem for Linux.
This command has been left available for documentation purposes only.

Diagnostic Logs

No response

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 8
  • Comments: 24 (1 by maintainers)

Commits related to this issue

Most upvoted comments

There is a fix for this in the beta channel of snapd. Problem being that you cannot update to beta because snap won’t let you.

If you manage to make snap work temporarily (e.g. disabling interop or reverting to an older version via apt), you can use either command (try the first one, if it fails try the second one):

sudo snap install snapd --beta 
sudo snap refresh snapd --beta

Then you can undo your temporary fix (e.g. enabling interop again or doing apt upgrade).

For a more step-by-step explanation (following @cerebrate 's trick of disabling interop): https://github.com/ubuntu/WSL/issues/299#issuecomment-1285083475

I think this issue can be closed.

The issue still affects users in WSL2 that use Ubuntu 22.10. (See here to check out the status of the fix). I believe the issue should stay open until snapd 2.57.5+22.10 is released.

Workaround that keeps WSL Interop active:

Ensure you have systemd-binfmt.service installed in your distro (in Ubuntu that means having the binfmt-support package installed via apt), then execute the following:

echo ":windowsexe:M::\x4d\x5a::/init:PF" | sudo tee -a /etc/binfmt.d/windowsexe.conf

This will replace the WSLInterop binfmt support with an identical configuration under a different name. To activate this, leave WSL and run wsl --shutdown in a PowerShell or CMD window. Next time you restart your distro it should replace the WSLInterop binfmt configuration with this renamed copy so that snapd can’t tell that it’s on WSL.

Yeah, it’s kind of a long story. Way back when, snapd implemented a test to see if it was running under WSL, but that test, it turned out, had a bug which meant that it only detected WSL 1, so for a very long time, you were able to get snapd working under WSL 2 if you fixed the prerequisites that stopped it from doing so.

(I don’t think any of us who got snapd working even noticed the test was there.)

Then along came snapcore/snapd#12135, which fixed the WSL detection bug so the test actually worked, and snapd stopped working.

The good news is that WSL detection post that PR works by looking for /proc/sys/fs/binfmt_misc/WSLInterop, so you can enable snapd at the cost of disabling Windows interop. (Note: not using the /etc/wsl.conf method, because that leaves the binfmt in place; rather, as root, run echo -1 >> /proc/sys/fs/binfmt_misc/WSLInterop, which removes the binfmt handler. Then restart all snapd services.)

The better news is that there’s a PR which acknowledges this stuff over at snapcore/snapd#12179, which has been merged, so we should be good once snapd 2.57.5 hits.

This issue now considered solved from the Ubuntu team’s point of view. snapd 2.57.5+22.10 has been released on kinetic, you can fix it with:

sudo apt-get -y update
sudo apt-get -y upgrade snapd

The permanent fix has been released for Ubuntu 18.04, 20.04 and 22.04. It’ll soon reach 22.10 as well. Here is the fix:

https://github.com/ubuntu/WSL/issues/299#issuecomment-1291650396

will users who install via --beta need to revert anything to return to the “release” version, or will a basic sudo apt update && sudo apt upgrade take care of it?

Yes, they’ll need to return to the stable channel. I added it to the linked comment.

I also suddenly couldn’t use the snap command as well, it worked for a while after updating WSL2 to 0.7.0, but today it was not working anymore.

Does it mean snapd with version 2.57.5+22.10ubuntu1 should be available in kinetic channel directly? What’s the difference between 2 channels?

No, it’ll be on kinetic-updates. Form the /etc/apt/sources.list file:

## Major bug fix updates produced after the final release of the
## distribution.
deb http://archive.ubuntu.com/ubuntu/ kinetic-updates main restricted

kinetic-updates contains bug fixes (such as this one). Both ppa are enabled on your distro by default so simply do apt update && apt upgrade and this problem will be solved.

@circleupx

I decide to take another route, I upgraded to Windows 11

Ahh, then your original problem was simply because Systemd is not supported under Windows 10 anyway. As the announcement mentioned, Systemd support requires WSL 0.67.6 or later, which is only available for Windows 11! 😀

error: cannot communicate with server: Post http://localhost/v2/snaps/microk8s: dial unix /run/snapd.socket: connect: no such file or directory

This looks like the message you get when systemd is not enabled. Did you re-enable systemd after installing the distro anew?

Also, what command prompted this message? Does snap list work fine?

I had the systemd=true in the WSL, though snap list never yielded any results. I decide to take another route, I upgraded to Windows 11. Reinstalled everything following the guidelines listed here and on various posts by Microsoft and I am happy to say.

It is working!!!

Thank you.

I’ve tried the permanent fix mentioned WSL#299 but I still can’t get it to work. At first, I was getting the message posted in this issue.

Interacting with snapd is not yet supported on Windows Subsystem for Linux. This command has been left available for documentation purposes only.

I decided to nuke the distro and start over, then it turned into this message.

error: cannot communicate with server: Post http://localhost/v2/snaps/microk8s: dial unix /run/snapd.socket: connect: no such file or directory

Snapd version

snap version snap 2.57.5+20.04 snapd unavailable series 16 Windows Subsystem for Linux - kernel 5.10.102.1-microsoft-standard-WSL2 (amd64)

Distro version

Distributor ID: Ubuntu Description: Ubuntu 20.04.5 LTS Release: 20.04 Codename: focal

Windows Build Version 10.0.19045 Build 19045

Does anyone have any suggestions?