Skip to content

VPraharsha03/GentooWSL2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GentooWSL2

GentooWSL2

Gentoo Linux on WSL2 (Windows 10 1903 or later) based on wsldl

License

Requirements

  • Windows 10 1903 x64 (KB4566116 update required on 1903/09) or later.
  • Windows Subsystem for Linux feature is enabled.

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):

  • 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 --oneshot --usepkg=n sys-devel/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

Make changes in portage config file under /etc/portage/repos.conf/gentoo.conf that holds the configuration for the main gentoo repository:

Replace,

sync-type = rsync
sync-uri = rsync://rsync.de.gentoo.org/gentoo-portage/

with

sync-type = git
sync-uri = https://github.com/gentoo-mirror/gentoo.git

Finally,

rm -r /var/db/repos/gentoo # delete the old rsync-managed repository
emerge --sync

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:

About

Install Gentoo as a WSL2 instance (for Windows 10 1903 64bit or later). Minimal setup and configuration. Releases are automated with CircleCI

Topics

Resources

License

Stars

Watchers

Forks

Languages