Gentoo in WSL
WSL stands for Windows Subsystem for Linux. It is a subsystem for running Linux on Windows. Since WSL uses a real Linux kernel running on top of a hypervisor you are effectively running Linux within Windows.
Gentoo can run on top of WSL too.
Installing Gentoo on WSL
A stage 3 tarball is required, and WSL needs to be installed. Version 2 is assumed here but these instructions might apply to version 1.
Use the following command to import Gentoo into WSL.
wsl --import Gentoo (path) .\stage3-amd64-openrc-20211121T170545Z.tar.xz --version 2
Gentoo = the name of the Linux distribution we are importing. (path) = the path we want Gentoo to go. Then we select our stage 3. We are using WSL version 2.
wsl --import Gentoo C:\Users\Alice\AppData\Local\WSL\Gentoo\ .\stage3-amd64-openrc-20211121T170545Z.tar.xz --version 2
Entering and setting up the Gentoo distribution
This is not gonna be a rewrite of the Gentoo handbook, just covering some of the basics to get started. Enter the Gentoo distribution on WSL by using the command:
wsl -d gentoo
Next we need to sync the portage tree:
If you want a more recent portage snapshot.
On slower command prompts or terminals it is recommended to use the --quiet option:
emerge --sync --quiet
Create and configure a user, this is what WSL prompts you to do when you use one of the prepackaged distros. Replace alice with a username of your choice.
useradd -m -G wheel alice
Set a root password.
Now we have a basic Gentoo system setup in WSL. You can install programs and use it the way you'd normally use Gentoo!
Setting your user to be default
When starting Gentoo in WSL by default it will use the root user. This isn't secure, or preferable. It would be better if WSL would use the user we created as default.
Create a file called /etc/wsl.conf with the following contents.
Replace alice with your own username.
Configuring WSL 2
WSL can be configured in ways such as adjusting the memory allocation, since WSL 2 is a virtual machine. Here's an example of configuring WSL 2:
[wsl2] memory=8GB # Allocates 8GB RAM to WSL 2 processors=4 # Allocates 4cores to WSL 2