~lovelymono/site

ceaa89f6c8ed976258567f462fc256a794ef4c8a — Lena Milizé 4 months ago 83d2107
feat: add new post, remove jp

Signed-off-by: Lena Milizé <me@lvmn.org>
3 files changed, 228 insertions(+), 5 deletions(-)

M public/index.html
A public/posts/musl-gentoo-wsl.txt
M public/styles.css
M public/index.html => public/index.html +4 -1
@@ 5,10 5,12 @@
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>index · lovelymono</title>
	<link rel="stylesheet" type="text/css" href="styles.css">
	<!-- <link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🪷</text></svg>"> -->
	<link rel="icon" href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48dGV4dCB5PSIuOWVtIiBmb250LXNpemU9IjkwIj7wn6q3PC90ZXh0Pjwvc3ZnPg==">
</head>
<body>
	<div id="header">
		<h1>lovelymono <span class="jp">「レーナ・ミリーゼ」</span></h1>
		<h1>lovelymono</h1>
	</div>

	<div id="content">


@@ 27,6 29,7 @@

		<h3>blog</h3>
		<ul class="posts">
			<li><date>14 May, 2022</date> <a href="posts/musl-gentoo-wsl.txt">musl gentoo on wsl</a></li>
			<li><date>8 May, 2022</date> <a href="posts/ssh-with-yubikey.txt">ssh with yubikey</a></li>
		</ul>


A public/posts/musl-gentoo-wsl.txt => public/posts/musl-gentoo-wsl.txt +220 -0
@@ 0,0 1,220 @@
GENTOO WITH MUSL ON WSL
Setting up Gentoo installation with musl libc on top of WSL2.
14/05/2022

1. INSTALLING WSL

You can use either the "Turn Windows features on or off" window, or PowerShell
for that.

In the window, select "Windows Subsystem for Linux" and restart the computer.

Otherwise, if using PowerShell, run

  PS> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

and restart the computer.

Next, you need to enable WSL 2. There's no GUI option for that, so you have to
use PowerShell.

Run

  PS> Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform

and, of course, restart the computer.

2. INSTALLING GENTOO

First, we need to download Gentoo stage3. We can do that by going to the Gentoo
downloads[1] page and scrolling down to "Musl stage archives". Select the non-
hardened version (without SELinux etc.) and wait for it to finish.

Stage3 archive is in .tar.xz format, but WSL needs a .tar format to import. We
can use 7-Zip[2] to extract it.

We're also going to need a location to install Gentoo to. We're going to use
C:\Users\Luna\AppData\Local\WSL\Gentoo (replace Luna with your profile name),
but you can also use any other location.

Now we need to import stage3 tar file into WSL, running in PowerShell

  PS> wsl --import Gentoo C:\Users\Luna\AppData\Local\WSL\Gentoo .\stage3-amd64-musl-20220508T170538Z.tar --version 2

Remember to add "--version 2", otherwise it probably won't run at all. This is
going to take a while, so make yourself something nice to drink. ^w^

If you get "Unspecified error" when running this command, you probably forgot
to unpack the stage3 tar file. If that's not the case, good luck?

[1]: https://www.gentoo.org/downloads/
[2]: https://www.7-zip.org/

3. CONFIGURING GENTOO

Now you can boot into Gentoo by running

  PS> wsl -d Gentoo

in PowerShell. However, we still need to configure it plenty.

3.1. Compile options.

We can optimize the compilation process by specifing some GCC and Make flags
for Portage to use. By default it comes set with "-O2" (medium optimization
level) and "-pipe" (use pipes instead of creating files), which are sensible
defaults for most systems.

However, "-pipe" uses more memory, so you can to remove it if your system is
low on memory.

Additionally, we can set "-march=native", which will tell GCC to target the
architecture we're running on. This can provide small amount of performance
improvement.

We also want to parallelize compilation when using Make. We can set MAKEOPTS to
provide options to Make when running, such as "-j4", which will tell it to run
4 processes at the same time (if possible).

  # nano -w /etc/portage/make.conf

  COMMON_FLAGS="-O2 -pipe -march=native"
  MAKEOPTS="-j4"

3.2. Tuning performance.

  # nano -e /etc/wsl.conf

  [wsl2]
  memory=8GB
  processors=4

3.3. Configuring Portage.

First, we need to synchronize Portage build repository to the latest version.
This will make sure we can install the latest version of packages.

  # emerge --sync

Next, we need to select a correct "profile".

> A profile is a building block for any Gentoo system. Not only does it specify
> default values for USE, CFLAGS, and other important variables, it also locks
> the system to a certain range of package versions

You can see the list of all available profiles using

  # eselect profile list

  Available profile symlink targets:
  [1]   default/linux/amd64/17.1 (stable)
  [2]   default/linux/amd64/17.1/selinux (stable)
  [3]   default/linux/amd64/17.1/hardened (stable)
  [4]   default/linux/amd64/17.1/hardened/selinux (stable)
  [5]   default/linux/amd64/17.1/desktop (stable)
  [6]   default/linux/amd64/17.1/desktop/gnome (stable)
  [7]   default/linux/amd64/17.1/desktop/gnome/systemd (stable)
  [8]   default/linux/amd64/17.1/desktop/plasma (stable)
  [9]   default/linux/amd64/17.1/desktop/plasma/systemd (stable)
  [10]  default/linux/amd64/17.1/desktop/systemd (stable)
  [11]  default/linux/amd64/17.1/developer (exp)
  [12]  default/linux/amd64/17.1/no-multilib (stable)
  [13]  default/linux/amd64/17.1/no-multilib/hardened (stable)
  [14]  default/linux/amd64/17.1/no-multilib/hardened/selinux (stable)
  [15]  default/linux/amd64/17.1/no-multilib/systemd (dev)
  [16]  default/linux/amd64/17.1/no-multilib/systemd/selinux (exp)
  [17]  default/linux/amd64/17.1/systemd (stable)
  [18]  default/linux/amd64/17.1/systemd/selinux (exp)
  [19]  default/linux/amd64/17.1/clang (exp)
  [20]  default/linux/amd64/17.0 (dev)
  [21]  default/linux/amd64/17.0/selinux (exp)
  [22]  default/linux/amd64/17.0/hardened (exp)
  [23]  default/linux/amd64/17.0/hardened/selinux (exp)
  [24]  default/linux/amd64/17.0/desktop (exp)
  [25]  default/linux/amd64/17.0/desktop/gnome (dev)
  [26]  default/linux/amd64/17.0/desktop/gnome/systemd (exp)
  [27]  default/linux/amd64/17.0/desktop/plasma (dev)
  [28]  default/linux/amd64/17.0/desktop/plasma/systemd (exp)
  [29]  default/linux/amd64/17.0/developer (exp)
  [30]  default/linux/amd64/17.0/no-multilib (exp)
  [31]  default/linux/amd64/17.0/no-multilib/hardened (exp)
  [32]  default/linux/amd64/17.0/no-multilib/hardened/selinux (exp)
  [33]  default/linux/amd64/17.0/systemd (dev)
  [34]  default/linux/amd64/17.0/x32 (dev)
  [35]  default/linux/amd64/17.0/musl (exp) *
  [36]  default/linux/amd64/17.0/musl/clang (exp)
  [37]  default/linux/amd64/17.0/musl/hardened (exp)
  [38]  default/linux/amd64/17.0/musl/hardened/selinux (exp)

In our case, the correct profile (35) was already selected, but you might need
to use

  # eselect profile set 35

if it's not. Make sure to replace 35 with whatever value your system outputs!

Now, we need to update @world set. @world is the set of packages which contains
both packages needed for Gentoo to run, and explicitly installed packages. But,
before we can do that, we need to configure USE flags.

We're going to set some USE flags globally in /etc/portage/make.conf. These
will be set for every package we install on this system.

  # nano -w /etc/portage/make.conf

  USE="-X -gtk"

Setting "-X -gtk" will disable GUI parts of applications, since we don't need
them (if you want, you can enable them, but that will require more setup on the
Windows side to handle Wayland/X11).

You can see the full list of known USE flags here[3]. Note that this list might
be incomplete, since every package is free to use whatever USE flags it wants
to.

We don't need any video card support, so we can set VIDEO_CARDS to "dummy"

  VIDEO_CARDS="dummy"

Then, update @world by running

  # emerge --ask --verbose --update --deep --newuse @world

and wait for it to finish. It can take a while though. ;^w^

[3]: https://www.gentoo.org/support/use-flags/

3.4. Adding musl overlay.

Since we're using musl, some packages are going to need patching to work with
it. Applying them by hand would be very tiresome, so instead Gentoo developers
made an overlay (set of patches and packages) that should fix them.

To enable it, we first need to add eselect-repository (to select the overlay)
and git (to download it)

  # emerge --ask --verbose eselect-repository dev-vcs/git

Now we need to enable it with

  # eselect repository enable musl

and update Portage with

  # emerge --sync

And now, we need to update all @world again, using

  # emerge --ask --verbose --update --deep --newuse @world

It might turn out that you don't need to update anything!

4. SEE ALSO

Gentoo in WSL[4]
Gentoo on Windows 10 WSL 2[5]
Project:Musl - Gentoo Wiki[6]

[4]: https://wiki.gentoo.org/wiki/Gentoo_in_WSL
[5]: https://developer.moe/gentoo-on-wsl-2
[6]: https://wiki.gentoo.org/wiki/Project:Musl

M public/styles.css => public/styles.css +4 -4
@@ 16,10 16,6 @@ h1 {
	font-family: monospace;
}

h1 .jp {
	font-weight: normal;
}

h3 {
	font-size: 1rem;
}


@@ 38,6 34,10 @@ ul.posts date {
	font-style: italic;
}

ul.posts li {
	margin-bottom: .5rem;
}

ul.quotes li {
	font-style: italic;
	/* margin-bottom: 1rem; */