Gentoo Linux on WSL2 (Windows 10 1903 or later) based on wsldl
- Windows 10 1903 x64 (KB4566116 update required on 1903/09) or later.
- Windows Subsystem for Linux feature is enabled.
The main reason for choosing WSL2 is because of it's improved file system performance. For the best overall experience it is recommended to use WSL2 with it's local EXT4 filesystem. Portage and it's related operations work perfectly on WSL2 for the fact that WSL2 uses a real linux kernel. However it is possible to set up Gentoo on WSL1, but there are certain caveats of doing so.
1. Download installer zip
Exe filename is used as the instance name to register. If you rename it, you can register with a different name and have multiple installs.
Make changes to the portage environment accordingly (/etc/portage/make.conf file):
- Adjust CPU configuration and COMMON_FLAGS to match your PC architecture.
- Adjust MAKEOPTS to the number of CPU cores (+1) to make the compilation faster
To finish the Gentoo installation a new snapshot of the ebuild repository should be downloaded. A recompilation of the compiler ensures that GCC is on the most recent stable version. After updating GCC a recompilation of all programs / libraries ensures that the set optimizations take effect.
#!/bin/bash
set -e -x
# Download a snapshot of all official ebuilds
emerge-webrsync
# Upgrade the compiler and the required libtool library
emerge --oneshot --deep sys-devel/gcc
emerge --ask --oneshot --usepkg=n dev-build/libtool
# Update all packages with the newly built compiler
# This will take a long time, ~1-5 hours
emerge --oneshot --emptytree --deep @world
emerge --oneshot --deep @preserved-rebuild
emerge --ask --depclean
Portage overlays provide a method to add additional package sources to portage. Eselect provides an easy integration of overlays into portage. To install Eselect:
emerge --ask app-eselect/eselect-repository
Finally, synchronize emerge:
emerge --sync
Sync via git which is fast, secure and up-to-date
emerge --ask dev-vcs/git
First disable the gentoo repository:
eselect repository disable gentoo
Then enable the gentoo repository, using git as the sync type:
eselect repository enable gentoo git
Finally,
mv /var/db/repos/gentoo /var/db/repos/gentoo.old-rsync
emaint sync -r gentoo
rm -r /var/db/repos/gentoo.old-rsync
Subsequent syncs should be now faster.
- Open
/etc/locale.gen
file and add the locales you need. For example
en_US.UTF-8 UTF-8
en_US ISO-8859-1
- Run
locale-gen
to generate the locales. - Run
eselect locale list
to view the locales - Run
eselect locale set 1
to set the locale - Run
env-update
- Create a new user with the following command: (replace
username
with your desired username)
useradd -m -G wheel,audio,video,portage,usb,cdrom -s /bin/bash username
- Set the password for the user
passwd username
- Set the password for the root user
passwd root
- Set the default user to the new user in WSL2
# /etc/wsl.conf
[user]
default=username
emerge --ask app-admin/sudo
Uncomment # %wheel ALL=(ALL) ALL
line in /etc/sudoers
using visudo
to allow users added to wheel group to have priviliges.
Create a global configuration for all installed WSL2 Linux disributions, named .wslconfig in your user profile folder. This is necessary to set a maximum size limit of the RAM WSL will use. Sometimes, Linux Kernel may use free memory as cache and will eat away RAM of host.
[wsl2]
#kernel=
memory=4GB # Limit VM memory
#processors=
#swap=
#swapFile=
localhostForwarding=true
EOF
Restart WSL from Powershell with admin rights
Restart-Service LxssManager
Usage :
<no args>
- Open a new shell with your default settings.
run <command line>
- Run the given command line in that distro. Inherit current directory.
runp <command line (includes windows path)>
- Run the path translated command line in that distro.
config [setting [value]]
- `--default-user <user>`: Set the default user for this distro to <user>
- `--default-uid <uid>`: Set the default user uid for this distro to <uid>
- `--append-path <on|off>`: Switch of Append Windows PATH to $PATH
- `--mount-drive <on|off>`: Switch of Mount drives
- `--default-term <default|wt|flute>`: Set default terminal window
get [setting]
- `--default-uid`: Get the default user uid in this distro
- `--append-path`: Get on/off status of Append Windows PATH to $PATH
- `--mount-drive`: Get on/off status of Mount drives
- `--wsl-version`: Get WSL Version 1/2 for this distro
- `--default-term`: Get Default Terminal for this distro launcher
- `--lxguid`: Get WSL GUID key for this distro
backup [contents]
- `--tgz`: Output backup.tar.gz to the current directory using tar command
- `--reg`: Output settings registry file to the current directory
clean
- Uninstall the distro.
help
- Print this usage message.
>Gentoo.exe clean