├── .circleci └── config.yml ├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── build.sh ├── env.sh └── img └── screenshot.jpg /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | jobs: 2 | build: 3 | machine: true 4 | steps: 5 | - checkout 6 | # build 7 | - run: 8 | command: | 9 | sudo bash build.sh; 10 | - run: 11 | name: "get ghr" 12 | command: | 13 | GHR_VERSION=0.13.0 14 | GHR_URL=https://github.com/tcnksm/ghr/releases/download/v${GHR_VERSION}/ghr_v${GHR_VERSION}_linux_amd64.tar.gz 15 | wget "$GHR_URL" && \ 16 | tar xzf ghr_v${GHR_VERSION}_linux_amd64.tar.gz && \ 17 | sudo mv ghr_v${GHR_VERSION}_linux_amd64/ghr /usr/bin/ghr && \ 18 | sudo rm -r ghr_v${GHR_VERSION}_linux_amd64.tar.gz ghr_v${GHR_VERSION}_linux_amd64/ 19 | - run: 20 | name: "Publish Release on GitHub" 21 | command: | 22 | source ./env.sh 23 | VERSION=$(date +'%Y%m%d') 24 | body='![Downloads](https://img.shields.io/github/downloads/CIRCLE_PROJECT_USERNAME/CIRCLE_PROJECT_REPONAME/VERSION/total)
Rootfs ver. ROOTFS
Launcher ver. LNCR_BLD
' 25 | body="${body/ROOTFS/${ROOTFS_VER}}" 26 | body="${body/LNCR_BLD/${LNCR_BLD}}" 27 | body="${body/VERSION/${VERSION}}" 28 | body="${body/CIRCLE_PROJECT_USERNAME/${CIRCLE_PROJECT_USERNAME}}" 29 | body="${body/CIRCLE_PROJECT_REPONAME/${CIRCLE_PROJECT_REPONAME}}" 30 | ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -b "${body}" ${VERSION} ~/project/dist/Gentoo.zip 31 | 32 | workflows: 33 | version: 2 34 | main: 35 | jobs: 36 | - build: 37 | filters: 38 | tags: 39 | ignore: /.*/ 40 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.bash text eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.md 2 | LICENSE 3 | res/ 4 | img/ 5 | .circleci/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 VPraharsha03 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GentooWSL2 2 |

GentooWSL2

3 | 4 | 5 |

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

6 | 7 | 8 |

9 | 10 |

11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | License 21 |

22 | 23 | ### 📦[Download](https://github.com/VPraharsha03/GentooWSL2/releases) 24 | 25 | 26 | ## Requirements 27 | * Windows 10 1903 x64 ([KB4566116 update](https://www.catalog.update.microsoft.com/Search.aspx?q=KB4566116) required on 1903/09) or later. 28 | * Windows Subsystem for Linux feature is enabled. 29 | 30 | ## Why WSL2? 31 | The main reason for choosing WSL2 is because of it's [improved file system performance](https://vxlabs.com/2019/12/06/wsl2-io-measurements/). 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](https://leo3418.github.io/2022/02/28/gentoo-wsl-perfection.html) of doing so. 32 | 33 | ## Initial Setup (Installing Gentoo userspace) 34 | #### 1. [Download](https://github.com/VPraharsha03/GentooWSL2/releases) installer zip 35 | 36 | #### 2. Extract all files in zip file to same directory 37 | 38 | #### 3. Run Gentoo.exe to Extract rootfs and Register to WSL 39 | Exe filename is used as the instance name to register. 40 | If you rename it, you can register with a different name and have multiple installs. 41 | 42 | ## Setting up Gentoo in WSL: 43 | Make changes to the portage environment accordingly (**/etc/portage/make.conf** file): 44 | * Adjust CPU configuration and COMMON_FLAGS to match your PC architecture. 45 | * Adjust MAKEOPTS to the number of CPU cores (+1) to make the compilation faster 46 | 47 | 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. 48 | 49 | ```shell 50 | #!/bin/bash 51 | set -e -x 52 | 53 | # Download a snapshot of all official ebuilds 54 | emerge-webrsync 55 | 56 | # Upgrade the compiler and the required libtool library 57 | emerge --oneshot --deep sys-devel/gcc 58 | emerge --ask --oneshot --usepkg=n dev-build/libtool 59 | 60 | # Update all packages with the newly built compiler 61 | # This will take a long time, ~1-5 hours 62 | emerge --oneshot --emptytree --deep @world 63 | emerge --oneshot --deep @preserved-rebuild 64 | emerge --ask --depclean 65 | ``` 66 | 67 | ## Finalizing: 68 | 69 | ### Enabling overlays for portage: 70 | Portage overlays provide a method to add additional package sources to portage. Eselect provides an easy integration of overlays into portage. 71 | To install Eselect: 72 | 73 | ```shell 74 | emerge --ask app-eselect/eselect-repository 75 | ``` 76 | 77 | Finally, synchronize emerge: 78 | 79 | ```shell 80 | emerge --sync 81 | ``` 82 | 83 | ### Using Git for portage sync: 84 | Sync via git which is fast, secure and up-to-date 85 | ```shell 86 | emerge --ask dev-vcs/git 87 | ``` 88 | First disable the gentoo repository: 89 | ```shell 90 | eselect repository disable gentoo 91 | ``` 92 | Then enable the gentoo repository, using git as the sync type: 93 | ```shell 94 | eselect repository enable gentoo git 95 | ``` 96 | Finally, 97 | ```shell 98 | mv /var/db/repos/gentoo /var/db/repos/gentoo.old-rsync 99 | emaint sync -r gentoo 100 | rm -r /var/db/repos/gentoo.old-rsync 101 | ``` 102 | 103 | Subsequent syncs should be now faster. 104 | 105 | ### Setting up Locales 106 | 1. Open `/etc/locale.gen` file and add the locales you need. For example 107 | ```shell 108 | en_US.UTF-8 UTF-8 109 | en_US ISO-8859-1 110 | ``` 111 | 2. Run `locale-gen` to generate the locales. 112 | 3. Run `eselect locale list` to view the locales 113 | 4. Run `eselect locale set 1` to set the locale 114 | 5. Run `env-update` 115 | 116 | ### Setting up users 117 | 1. Create a new user with the following command: (replace `username` with your desired username) 118 | ```shell 119 | useradd -m -G wheel,audio,video,portage,usb,cdrom -s /bin/bash username 120 | ``` 121 | 2. Set the password for the user 122 | ```shell 123 | passwd username 124 | ``` 125 | 3. Set the password for the root user 126 | ``` 127 | passwd root 128 | ``` 129 | 4. Set the default user to the new user in WSL2 130 | ```shell 131 | # /etc/wsl.conf 132 | [user] 133 | default=username 134 | ``` 135 | 136 | ### Setting up sudo 137 | ```shell 138 | emerge --ask app-admin/sudo 139 | ``` 140 | 141 | Uncomment `# %wheel ALL=(ALL) ALL` line in `/etc/sudoers` using `visudo` to allow users added to wheel group to have priviliges. 142 | 143 | ### Limit WSL2 resource usage: 144 | 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. 145 | 146 | ```dos 147 | [wsl2] 148 | #kernel= 149 | memory=4GB # Limit VM memory 150 | #processors= 151 | #swap= 152 | #swapFile= 153 | localhostForwarding=true 154 | EOF 155 | ``` 156 | Restart WSL from Powershell with admin rights 157 | ```powershell 158 | Restart-Service LxssManager 159 | ``` 160 | 161 | 162 | ## How-to-Use(for Installed Instance) 163 | #### exe Usage 164 | ```dos 165 | Usage : 166 | 167 | - Open a new shell with your default settings. 168 | 169 | run 170 | - Run the given command line in that distro. Inherit current directory. 171 | 172 | runp 173 | - Run the path translated command line in that distro. 174 | 175 | config [setting [value]] 176 | - `--default-user `: Set the default user for this distro to 177 | - `--default-uid `: Set the default user uid for this distro to 178 | - `--append-path `: Switch of Append Windows PATH to $PATH 179 | - `--mount-drive `: Switch of Mount drives 180 | - `--default-term `: Set default terminal window 181 | 182 | get [setting] 183 | - `--default-uid`: Get the default user uid in this distro 184 | - `--append-path`: Get on/off status of Append Windows PATH to $PATH 185 | - `--mount-drive`: Get on/off status of Mount drives 186 | - `--wsl-version`: Get WSL Version 1/2 for this distro 187 | - `--default-term`: Get Default Terminal for this distro launcher 188 | - `--lxguid`: Get WSL GUID key for this distro 189 | 190 | backup [contents] 191 | - `--tgz`: Output backup.tar.gz to the current directory using tar command 192 | - `--reg`: Output settings registry file to the current directory 193 | 194 | clean 195 | - Uninstall the distro. 196 | 197 | help 198 | - Print this usage message. 199 | ``` 200 | 201 | 202 | #### How to uninstall instance 203 | ```dos 204 | >Gentoo.exe clean 205 | 206 | ``` 207 | 208 | ### Useful Links: 209 | - [Official article on Gentoo Wiki](https://wiki.gentoo.org/wiki/Gentoo_in_WSL) 210 | - [Comparing WSL1 and WSL2 filesystem I/O performance on local and host files.](https://vxlabs.com/2019/12/06/wsl2-io-measurements/) 211 | - [Refine Gentoo on Windows Subsystem for Linux](https://leo3418.github.io/2022/02/28/gentoo-wsl-perfection.html) 212 | - [WSL2 init: emerging OpenRC](https://wsl.dev/wsl2init/) 213 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e -x 3 | export PATH=/usr/.bin:$PATH 4 | 5 | # Load necessary environment variables 6 | source ./env.sh 7 | 8 | # Create a work dir 9 | mkdir rootfs 10 | 11 | # Download the Gentoo Rootfs and Yuk7's WSLDL 12 | curl -L ${ROOTFS_URL} --output base.tar.xz 13 | curl -L ${LNCR_URL} --output ${LNCR_ZIP} 14 | 15 | # Extract the Gentoo WSL launcher 16 | unzip ${LNCR_ZIP} ${LNCR_FN} 17 | 18 | # Clean up 19 | rm ${LNCR_ZIP} 20 | 21 | # Extract rootfs 22 | sudo tar -xpf base.tar.xz -C rootfs 23 | sudo chmod +x rootfs 24 | 25 | # Delete auto-generated files 26 | # rm rootfs/etc/resolv.conf || true 27 | # rm rootfs/etc/wsl.conf || true 28 | 29 | # Enable changing /etc/resolv.conf 30 | # Enable extended attributes on Windows drives 31 | cat < rootfs/etc/wsl.conf 32 | [network] 33 | generateResolvConf = false 34 | 35 | [automount] 36 | enabled = true 37 | options = "metadata" 38 | mountFsTab = false 39 | EOF 40 | 41 | # Use google nameservers for DNS resolution 42 | cat < rootfs/etc/resolv.conf 43 | nameserver 8.8.8.8 44 | nameserver 8.8.4.4 45 | EOF 46 | 47 | # Make changes to /etc/portage/make.conf 48 | cat < rootfs/etc/portage/make.conf 49 | # No GUI (-X -gtk), only english error messages (-nls) 50 | USE="-X -gtk -nls" 51 | 52 | # Enable python 3.12 and set it as default 53 | PYTHON_TARGETS="python3_12" 54 | PYTHON_SINGLE_TARGET="python3_12" 55 | 56 | # Define targets for QEMU 57 | QEMU_SOFTMMU_TARGETS="aarch64 arm i386 riscv32 riscv64 x86_64" 58 | QEMU_USER_TARGETS="aarch64 arm i386 riscv32 riscv64 x86_64" 59 | 60 | # No hardware videocard support 61 | VIDEO_CARDS="dummy" 62 | 63 | # Disable non-functional sandboxing features 64 | FEATURES="-ipc-sandbox -pid-sandbox -mount-sandbox -network-sandbox" 65 | 66 | # Always ask when managing packages, always consider deep dependencies (slow) 67 | EMERGE_DEFAULT_OPTS="--ask --complete-graph" 68 | 69 | # Enable optimizations for the used CPU 70 | #COMMON_FLAGS="-march=native -O2 -pipe" 71 | #CHOST="x86_64-pc-linux-gnu" 72 | #CFLAGS="\${COMMON_FLAGS}" 73 | #CXXFLAGS="\${COMMON_FLAGS}" 74 | #FCFLAGS="\${COMMON_FLAGS}" 75 | #FFLAGS="\${COMMON_FLAGS}" 76 | #MAKEOPTS="-j5" 77 | 78 | # NOTE: This stage was built with the bindist Use flag enabled 79 | PORTDIR="/var/db/repos/gentoo" 80 | DISTDIR="/var/cache/distfiles" 81 | PKGDIR="/var/cache/binpkgs" 82 | 83 | # This sets the language of build output to English. 84 | # Please keep this setting intact when reporting bugs. 85 | LC_MESSAGES=C 86 | EOF 87 | 88 | # Clean up (delete base.tar.gz) 89 | rm base.tar.xz 90 | 91 | # Create a tar.gz of the rootfs 92 | sudo tar -zcpf rootfs.tar.gz -C ./rootfs . 93 | sudo chown "$(id -un)" rootfs.tar.gz 94 | 95 | # Clean up 96 | sudo rm -rf rootfs 97 | 98 | # Create the distribution zip of Gentoo WSL 99 | mkdir out 100 | mkdir dist 101 | mv -f ${LNCR_FN} ./out/${LNCR_ZIPFN} 102 | mv -f rootfs.tar.gz ./out/ 103 | pushd out 104 | zip ../dist/Gentoo.zip ./* 105 | popd 106 | 107 | # Clean up 108 | rm -rf out 109 | -------------------------------------------------------------------------------- /env.sh: -------------------------------------------------------------------------------- 1 | # Env variables for the Gentoo image 2 | OS_VER="stable" 3 | ROOTFS_VER="20241201T164824Z" 4 | ROOTFS_URL="https://gentoo.osuosl.org/releases/amd64/autobuilds/current-stage3-amd64-nomultilib-openrc/stage3-amd64-nomultilib-openrc-${ROOTFS_VER}.tar.xz" 5 | 6 | # Environment variables for Yuk7's wsldl 7 | LNCR_BLD="24102000" 8 | LNCR_ZIP="icons.zip" 9 | LNCR_NAME="Gentoo" 10 | LNCR_FN=${LNCR_NAME}.exe 11 | LNCR_ZIPFN=${LNCR_NAME}.exe 12 | LNCR_URL="https://github.com/yuk7/wsldl/releases/download/${LNCR_BLD}/${LNCR_ZIP}" -------------------------------------------------------------------------------- /img/screenshot.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/VPraharsha03/GentooWSL2/ad1a0fe74af7bd1dea489b31d1d0833c34d1f942/img/screenshot.jpg --------------------------------------------------------------------------------