VSWSL/Arch-WSL

Thanks for your packaging, there are few suggestions by packaging to implement later :)

llorephie opened this issue · 1 comments

Prior following text wall - thanks for packaging for MS Store :) Almost zero fixups required after installation, but I have bad feeling on usage upstream distro name for publication due to trademark policy and CoC... Anyway, not my business, but Antergos used own branding, and used mainline repos with few own decorative packages (and graphical installer) optional repo, built from AUR.

For those, who look for ready recipes without 3hrs waste of MSDN weird documentation reading (can be safely ignored otherwise, as this setup way is somewhat dumb and beer-inspired...):

Prepare Windows host for WSL2

  • PS > DISM.exe /Online /Enable-Feature /FeatureName:VirtualMachinePlatform /All
  • PS > wsl.exe --shutdown
  • PS > wsl.exe --update
  • PS > wsl.exe --set-version Arch 2

Setting up Arch

  • # cat /etc/wsl.conf
[automount]
enabled = true
# For sharing storage with other WSL instances.
crossDistro = true
root = /mnt/
# dirs = 755, files = 644, disable char case check.
options = "metadata,uid=1000,gid=1000,umask=0000,fmask=0033,dmask=0022,case=off"
# UID/GID 1000 is default, can be omitted.
# options = "metadata,umask=0000,fmask=0033,dmask=0022,case=off"
# mountFsTab = true

[network]
hostname = archlinux.wsl
generateHosts = true
## LATE EDIT - there are few more undocumented (on MSDN at least) options for this section, like bridged mode setup:
## https://github.com/microsoft/WSL/issues/4150#issuecomment-1310028257
## By default Hyper-V network stack doesn't support IPv6 for WSL2 instances, if you have IPv6-primary ISP connection - worth to try.
generateResolvConf = true

# Set both keys to false to disable ability to call windows binaries from WSL envinroment
[interop]
enabled = true
appendWindowsPath = true

[user]
default = defaultuser

[boot]
systemd = true
  • PS > cat %USERPROFILE%/.wslconfig (on windows host)
[wsl2]
memory = 6GB
processors = 8
kernelCommandLine = mmio_stale_data=off
swap = 4GB
pageReporting = true
# Well, guess this key should break things if more than one WSL running... Enable direct access to WSL resources, listening on localhost/0.0.0.0 from host side using localhost as address.
localhostForwarding = true
nestedVirtualization = true
debugConsole = false
# flatpak applications looks like started without any issues (Wayland).
guiApplications = true
vmIdleTimeout = 60000
idleThreshold = 10000

Some fixup of default systemd unit configurations, due to somewhat messed implementation from WSL init side

  • # cat /etc/systemd/system/fixshm.service
[Unit]
Description=Fix the /dev/shm symlink to be a mount
DefaultDependencies=no
Before=sysinit.target
ConditionPathExists=/dev/shm
ConditionPathIsSymbolicLink=/dev/shm
ConditionPathIsMountPoint=/run/shm

[Service]
Type=oneshot
ExecStart=/usr/bin/rm /dev/shm
ExecStart=/usr/bin/mkdir /dev/shm
ExecStart=/bin/umount /run/shm
ExecStart=/usr/bin/rmdir /run/shm
ExecStart=/bin/mount -t tmpfs -o mode=1777,nosuid,nodev,strictatime tmpfs /dev/shm
ExecStart=/usr/bin/ln -s /dev/shm /run/shm

[Install]
WantedBy=sysinit.target
Another fix...
  • # cat /etc/systemd/system/systemd-sysctl.service.d/override.conf
  • # cat /etc/systemd/system/systemd-sysusers.service.d/override.conf
    • Or use # systemctl edit systemd-sysusers.service; systemctl edit systemd-sysctl.service
[Service]
LoadCredential=

After this modifications -

  • PS > wsl.exe --shutdown

Next boot should be systemd-backed.

  • # systemctl list-units --type=service - to check if systemd is working. At least podman works fine :)

Solution source links to be added later via UPD.

Known sound journald entries

  • WSL (2) ERROR: InitCreateSessionLeader:1088: /sbin/init failed to start within 10000ms - can be safely ignored, no impact observed in 2 hours.
  • 9pnet_virtio: no channels available for device drvfs - guess can be ignored too, everything seems working.

Suggestions:

I don't see any reason to additionaly modify/update upstream docker image during package preparation, to be honest, as it rebuilds daily on GitLab, and weekly - pushed on DockerHub. Maybe it is more suitable to use full pipeline to prepare image from scratch, and replace sudo (someone using other privilege escalation options, worth to mention - su is provided from base group) configuration with systemd-firstboot :) Well, it needs to be configured - but Arch, for painless usage, anyway requires recently added WSL2 features, as I remember - there are no packages in "main" repositories with other init options, but systemd... Yes, they are all in AUR, and WSL anyway will configure system each run.
So, I guess, less "vanilla" image packaging suitable in this case - polishing required anyway just to run Arch not in single-user mode under WSL.

Hey, thanks for your suggestions, regarding the trademark i think I read somewhere in the arch wiki that if you are making minimal/no changes to the base you can use arch name but i am not exactly sure but i will look into it again. I included sudo so it would be a coherent experience with other wsl distributions and help people not get stuck from the get go if they are following some tutorial for wsl. The same goes for systemd boot wsl is not designed to use systemd boot by default but they can do it if they want to, i have seen in newer versions of wsl it is relatively easy to use systemd anyway so probably should let the user decide what they want.