Gentoo in WSL

From Gentoo Wiki
Jump to:navigation Jump to:search
This page contains changes which are not marked for translation.
This article is a stub. You can help by expanding it.

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.

user $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.

For example:

user $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:

user $wsl -d gentoo

Next we need to sync the portage tree:

root #emerge-webrsync

If you want a more recent portage snapshot.

root #emerge --sync

On slower command prompts or terminals it is recommended to use the --quiet option:

root #emerge --sync --quiet

Configure portage how you normally would using the Gentoo handbook.

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.

root #useradd -m -G wheel alice
root #passwd alice

Set a root password.

root #passwd

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.

FILE /etc/wsl.conf

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:

FILE /etc/wsl.conf
memory=8GB # Allocates 8GB RAM to WSL 2
processors=4 # Allocates 4cores to WSL 2