This repository provides a complete configuration framework for deploying an optimized Gentoo Linux environment on Windows Subsystem for Linux 2 (WSL2). It includes production-grade compiler optimizations, automated provisioning via Ansible, and documented solutions to common deployment challenges.
- Hardware-Optimized Compilation: Portage configuration utilizing
march=nativeand processor-specificCPU_FLAGS_X86for optimal binary performance - Automated Provisioning: Complete system deployment through Ansible playbooks
- Resource Management: WSL configuration tuned for efficient host resource allocation
- Production Documentation: Comprehensive troubleshooting reference based on real deployment scenarios
.
├── ansible/
│ └── playbook.yml # System provisioning automation
├── configs/
│ ├── make.conf # Portage compiler configuration
│ └── .wslconfig # WSL resource allocation limits
├── screenshots/
└── README.md
Before using this configuration, ensure you have:
- WSL2 enabled on Windows 10/11
- A Gentoo stage3 tarball imported into WSL
- Basic familiarity with Gentoo's package management (Portage)
Copy the provided WSL configuration to your Windows user directory:
- Source:
configs/.wslconfig - Destination:
C:\Users\<YourUsername>\.wslconfig
The provided configuration allocates:
- 5 CPU cores
- 3 GB RAM
- 20 GB virtual hard disk size
Adjust these values based on your hardware specifications and requirements.
After copying the file, restart WSL:
wsl --shutdownCopy configs/make.conf to /etc/portage/make.conf in your Gentoo WSL instance.
⚠️ CRITICAL: Hardware-Specific ConfigurationThe
CPU_FLAGS_X86line in the providedmake.confis generated for specific hardware and must not be used directly on different systems. This configuration is hardware-dependent and using incorrect flags can cause package compilation failures or runtime errors.Required steps for your system:
Install the CPU flags detection tool:
emerge app-portage/cpuid2cpuflagsGenerate your hardware-specific flags:
cpuid2cpuflagsReplace the
CPU_FLAGS_X86line in/etc/portage/make.confwith the generated output.
Configuration Highlights:
- MAKEOPTS="-j5": Parallel compilation using 5 jobs (adjust based on your CPU core count)
- USE flags: Minimal headless configuration with desktop environments and unnecessary services disabled
- ACCEPT_LICENSE="*": Accepts all software licenses (review based on your requirements)
First, install Ansible in your Gentoo WSL environment:
emerge --ask app-admin/ansibleThe Ansible playbook automates:
- Portage tree synchronization
- Essential package installation (sudo, vim, git, strace, tcpdump)
- Sudo configuration for the wheel group
- Dependency cleanup
Execute the playbook:
cd ansible
ansible-playbook playbook.ymlNote: The playbook requires root privileges and will prompt for confirmation during package installation.
If you prefer manual installation without Ansible:
# Sync portage tree
emerge --sync
# Install packages
emerge --ask app-admin/sudo app-editors/vim dev-vcs/git dev-debug/strace net-analyzer/tcpdump
# Configure sudo
visudo
# Uncomment: %wheel ALL=(ALL:ALL) ALL
# Clean dependencies
emerge --ask --depcleanError: Invoke-WebRequest : A parameter cannot be found that matches parameter name 'L'.
Solution: PowerShell aliases curl to Invoke-WebRequest. Use the full cmdlet or the native curl executable:
Invoke-WebRequest -Uri "https://distfiles.gentoo.org/releases/amd64/autobuilds/current-stage3-amd64-openrc/stage3-amd64-openrc-20251012T210603Z.tar.xz" -OutFile C:\wsl\gentoo\stage3.tar.xzCorrect package atoms for commonly used utilities:
- Git:
dev-vcs/git(notsys-devel/git) - Strace:
dev-debug/strace(notdev-util/strace) - Sudo:
app-admin/sudo
If the Ansible playbook fails to configure sudo, manually enable wheel group access:
visudoUncomment the following line:
%wheel ALL=(ALL:ALL) ALL
If packages fail to compile after applying make.conf:
- Verify your
CPU_FLAGS_X86is correctly generated for your hardware - Test with safer flags temporarily:
COMMON_FLAGS="-O2 -pipe -march=x86-64" - Check
/var/log/portage/for specific error messages
Remove unnecessary dependencies and cached distribution files:
emerge --ask --depclean
eclean-distKeep your system updated:
emerge --sync
emerge --ask --update --deep --newuse @worldWSL distributions import as root by default. Configure your standard user account as the default login:
Get-Item "HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss\*\DistributionName" | Where-Object { $_.GetValue("") -eq "Gentoo" } | Set-ItemProperty -Name "DefaultUid" -Value 1000Replace 1000 with your user's UID if different (check with id -u username in WSL).
On WSL2 systems, the following error may appear during Portage tree synchronization:
!!! Manifest verification failed:
Manifest mismatch for metadata/Manifest.gzThis is not a local system or configuration error. The failure is typically caused by a temporary inconsistency on the selected Gentoo mirror (e.g. partial mirror sync or stale metadata). Portage correctly aborts the operation for security reasons.
In most cases, no manual intervention is required. Retry the synchronization after a short delay:
emerge --syncOnce the mirror state has stabilized, synchronization will complete successfully with a valid OpenPGP signature.
After syncing or updating Portage, the following warning may be displayed:
IMPORTANT: config file '/etc/hosts' needs updating.
WSL automatically generates /etc/hosts at startup. This behavior can conflict with Gentoo’s default /etc/hosts template during etc-update or dispatch-conf.
Do not replace /etc/hosts with Gentoo’s full template.
Instead, ensure that the IPv6 localhost entry exists while keeping all WSL-managed entries intact.
Required line:
::1 localhostTypical safe /etc/hosts content on WSL:
127.0.0.1 localhost
127.0.1.1 <hostname>.localdomain <hostname>
::1 localhost- The configuration warning will no longer appear
emerge --syncand world updates proceed normally- WSL host integration remains intact
Do not fully overwrite /etc/hosts on WSL systems unless automatic host generation is explicitly disabled via /etc/wsl.conf.
This project is licensed under the MIT License.
