Skip to content

Instantly share code, notes, and snippets.

@kmatt
Last active Dec 5, 2022
Embed
What would you like to do?
Install Void Linux on WSL2
# Based on https://gist.github.com/kmatt/71603170556ef8ffd14984af77ff10c5
# prompt ">" indicates Powershell 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://alpha.de.repo.voidlinux.org/live/current/void-x86_64-ROOTFS-20210930.tar.xz
# uncompress but do not unzip tar file
> 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
$ su - $USERNAME
$ echo "[user]\ndefault=$USERNAME" > /etc/wsl.conf
# IMPORTANT - Use visudo to grant wheel group sudo (/etc/sudoers)
> wsl --terminate $DISTRONAME
> wsl -d $DISTRONAME
@jsumners
Copy link

jsumners commented Nov 11, 2022

This is fantastic stuff. Thank you for creating this document.

As of at least 2022-11-11, we don't need to use the final Powershell command to set the default user. Instead, we can:

$ echo -e "[user]\ndefault=$USERNAME" > /etc/wsl.conf
$ exit
> wsl --terminate $DISTRONAME
> wsl -d $DISTRONAME

See https://learn.microsoft.com/en-us/windows/wsl/use-custom-distro (https://web.archive.org/web/20221014081630/https://learn.microsoft.com/en-us/windows/wsl/use-custom-distro).

Also, for anyone else reading this, you may want to edit /etc/sudoers prior to exiting the initial root shell. Adjust it so that your newly added user can perform sudo actions.

One other tip: set your default distribution by wsl --setdefault $DISTRONAME.

@kmatt
Copy link
Author

kmatt commented Nov 15, 2022

Simplified with suggestions from @jsumners

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment