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.

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.

For example:

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:

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:

Configure the system as how you normally would using the Gentoo handbook. However, there are some handbook parts that can be skipped on WSL:
 * Chapters in "Choosing the media" through "Preparing the disks". An installation media is not necessary on WSL. Networking and partitioning are handled automatically.
 * "Installing stage3" chapter, "Installing a stage tarball" section. WSL automatically sets the date, and the stage tarball has already been downloaded on Windows and imported into WSL.
 * "Installing base system" chapter, "Chrooting" and "Timezone" sections. Chrooting is not applicable to WSL. WSL handles the time zone files and  automatically, so no user intervention is needed.
 * Chapters in "Configuring the kernel" through "Configuring the bootloader". By default, WSL provides a kernel, handles partitions and networking, and does not require a bootloader.

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.

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: