Home

Awesome

GentooWSL2

<p align="center"><img src="https://socialify.git.ci/VPraharsha03/GentooWSL2/image?description=1&descriptionEditable=Gentoo%20on%20Windows%20Subsystem%20for%20Linux.&font=Bitter&forks=1&issues=1&logo=https%3A%2F%2Fwww.gentoo.org%2Fassets%2Fimg%2Flogo%2Fgentoo-signet.svg&name=1&pattern=Signal&pulls=1&stargazers=1&theme=Auto" alt="GentooWSL2" width="800" height="400" /></p> <!--Gentoo Linux on WSL2 (Windows 10 1903 or later) based on [wsldl](https://github.com/yuk7/wsldl)--> <p align="center">Gentoo Linux on WSL2 (Windows 10 1903 or later) based on <a href="https://github.com/yuk7/wsldl">wsldl</a></p> <!--![screenshot](https://github.com/VPraharsha03/GentooWSL2/blob/main/img/screenshot.jpg?raw=true)--> <p align="center"><img src="https://github.com/VPraharsha03/GentooWSL2/blob/main/img/screenshot.jpg?raw=true"/></p> <p align="center"> <a href="" alt="AutomatedReleases"> <img src="https://img.shields.io/badge/-Automated%20Releases-success?logo=circleci&style=svg" /></a> <a href="https://app.circleci.com/pipelines/github/VPraharsha03/GentooWSL2?status=failing&status=on_hold&status=queued&status=running&status=success" alt="CircleCI"> <img src="https://circleci.com/gh/VPraharsha03/GentooWSL2.svg?style=svg" /></a> <a href="https://github.com/VPraharsha03/GentooWSL2/releases/latest" alt="Github All Releases"> <img src="http://img.shields.io/github/downloads/VPraharsha03/GentooWSL2/total.svg?style=flat-square" /></a> <a href="http://makeapullrequest.com" alt="PRs Welcome"> <img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square" /></a> <a href=""> <img src="https://img.shields.io/github/license/yuk7/AlpineWSL.svg?style=flat-square" alt="License"></a> </p>

📦Download

Requirements

Why WSL2?

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.

Initial Setup (Installing Gentoo userspace)

1. Download installer zip

2. Extract all files in zip file to same directory

3. Run Gentoo.exe to Extract rootfs and Register to WSL

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.

Setting up Gentoo in WSL:

Make changes to the portage environment accordingly (/etc/portage/make.conf file):

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

Finalizing:

Enabling overlays for portage:

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

Using Git for portage 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.

Setting up Locales

  1. Open /etc/locale.gen file and add the locales you need. For example
en_US.UTF-8 UTF-8
en_US ISO-8859-1
  1. Run locale-gen to generate the locales.
  2. Run eselect locale list to view the locales
  3. Run eselect locale set 1 to set the locale
  4. Run env-update

Setting up users

  1. 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
  1. Set the password for the user
passwd username
  1. Set the password for the root user
passwd root
  1. Set the default user to the new user in WSL2
# /etc/wsl.conf
[user]
default=username

Setting up sudo

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.

Limit WSL2 resource usage:

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

How-to-Use(for Installed Instance)

exe Usage

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.

How to uninstall instance

>Gentoo.exe clean

Useful Links: