-
-
Save kmatt/aad3970a05f72fbbd5f1b9ef7ee1e330 to your computer and use it in GitHub Desktop.
# Based on https://gist.github.com/kmatt/71603170556ef8ffd14984af77ff10c5 | |
# prompt ">" indicates Powershell commands | |
# prompt "$" are Linux shell commands | |
# https://docs.microsoft.com/en-us/windows/wsl/install-win10 | |
> dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart | |
> dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart | |
# install https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi | |
> wsl --set-default-version 2 | |
# use rootfs tarball from https://voidlinux.org/download | |
# ex: https://repo-default.voidlinux.org/live/current/void-x86_64-ROOTFS-20230628.tar.xz | |
# uncompress but do not extract tar file (don't tar -x) | |
> wsl.exe --import $DISTRONAME $STORAGEPATH void-$VERSION.tar | |
> wsl -d $DISTRONAME | |
# optional - update xbps mirrors | |
$ cp /usr/share/xbps.d/*-repository-*.conf /etc/xbps.d/ | |
# if in US https://voidlinux.org/news/2021/10/mirror-retirement.html | |
$ xbps-install -Su xbps | |
$ xbps-install -u | |
$ xbps-install base-system | |
$ xbps-remove base-voidstrap | |
$ xbps-reconfigure -fa | |
$ useradd -m -G wheel -s /bin/bash $USERNAME | |
$ passwd $USERNAME | |
# Default user | |
$ echo -e "[user]\ndefault=$USERNAME" > /etc/wsl.conf | |
# Grant sudo | |
$ sed -i 's/# %wheel ALL=(ALL:ALL) ALL/%wheel ALL=(ALL:ALL) ALL/' /etc/sudoers | |
> wsl --terminate $DISTRONAME | |
> wsl -d $DISTRONAME |
@kmatt @jsumners @Nequo just fyi the official way of setting the default user for a WSL instance is the following:
Assuming your UID is 1000, then open up the registry editor (regedit
), go to HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss
, click through the UUIDs until you find the one with the key DistributionName
set to your WSL distro name. Upon finding it, create a new DWORD32 key called DefaultUid
and set its value to decimal 1000 which will result in 3e8 hexadecimal.
Afterwards the default user is set and you don't need to configure that within /etc/wsl.conf
. It probably doesn't matter which method you choose, but I personally prefer the registry. Microsoft should really allow DefaultUid
to be set on the parent (Lxss
), so all distros can use that value if it's not explicitly set for a distro. But I guess that's an oversight they won't fix... Gonna create an issue anyway lol.
Edit: done. microsoft/WSL#10631
I highly doubt editing the registry is "the official way" when WSL reads the configuration file I noted in order to get the information.
@jsumners it reads the registry first, then the config file.
https://learn.microsoft.com/en-us/windows/wsl/wsl-config#automount-options
I prefer not to edit the Windows registry if at all possible.
Well the registry is just another place to configure the distro, and these are per-user settings anyway. It's basically the same in the end. Besides, those automount options are not the same setting as setting the default WSL user in general, they're used to give that user the respective permissions.
I don't get what "uncompress but do not unzip tar file" should mean
I don't get what "uncompress but do not unzip tar file" should mean
gunzip rootfs.tar.gz
but do not tar xf rootfs.tar
curl.exe
seems to be bundled with Windows:
C:\Users\roman>where curl.exe
C:\Windows\System32\curl.exe
and since you'll need something to decompress the rootfs anyway...
> scoop install xz
> rootfs=void-x86_64-ROOTFS-20240314.tar.xz
# the `.exe` is neccessary to disambiguate from the incompatible, half-assed PowerShell cmdlet
> curl.exe -LSfs --remote-name --no-clobber --remove-on-error \
https://repo-default.voidlinux.org/live/current/$rootfs
> xz -d $rootfs
stripping the .xz
tail from $rootfs
so this dovetails with the following wsl.exe --import
command is left as an excercise for the reader, i've had enough PowerShell. alternatively, you could
> rootfs=void-...tar
> curl.exe ... https://.../$rootfs.xz
> xz -d $rootfs.xz
> wsl --import ... $rootfs
@SkyNetMkII your suggestion worked, thanks!
I configured my
/etc/wsl.conf
as follows:To still have Windows tools available under WSL2, I did the following:
To get Docker working, first install it:
Then the service's
run
file (/etc/sv/docker/run
) needs to be changed, because/lib/modules
is not available under WSL2:My version of the file is the following (played around a bit):
I created a PR for that: void-linux/void-packages#46667. Fingers crossed that it gets accepted.