#16 Add a WSL definition and config snippets
Merged 2 months ago by ngompa. Opened a year ago by jcline.
jcline/fedora-kiwi-descriptions wsl  into  rawhide

file modified
+1
@@ -38,6 +38,7 @@ 

  	<include from="this://./teams/cloud/cloud.xml"/>

  	<include from="this://./teams/cloud/container.xml"/>

  	<include from="this://./teams/cloud/vagrant.xml"/>

+ 	<include from="this://./teams/cloud/wsl.xml"/>

  	<include from="this://./teams/server.xml"/>

  	<include from="this://./teams/workstation.xml"/>

  	<include from="this://./teams/kde.xml"/>

file modified
+2 -2
@@ -33,7 +33,7 @@ 

  #======================================

  # Configure grub correctly

  #--------------------------------------

- if [[ "$kiwi_profiles" != *"Container"* ]] && [[ "$kiwi_profiles" != *"FEX"* ]]; then

+ if [[ "$kiwi_profiles" != *"Container"* ]] && [[ "$kiwi_profiles" != *"FEX"* ]] && [[ "$kiwi_profiles" != *"WSL"* ]]; then

  	## Works around issues with grub-bls

  	## See: https://github.com/OSInside/kiwi/issues/2198

  	echo "GRUB_DEFAULT=saved" >> /etc/default/grub
@@ -58,7 +58,7 @@ 

  #======================================

  # Delete & lock the root user password

  #--------------------------------------

- if [[ "$kiwi_profiles" == *"Cloud"* ]] || [[ "$kiwi_profiles" == *"Disk"* ]] || [[ "$kiwi_profiles" == *"Live"* ]]; then

+ if [[ "$kiwi_profiles" == *"Cloud"* ]] || [[ "$kiwi_profiles" == *"Disk"* ]] || [[ "$kiwi_profiles" == *"Live"* ]] || [[ "$kiwi_profiles" == *"WSL"* ]]; then

  	passwd -d root

  	passwd -l root

  fi

file added
+68
@@ -0,0 +1,68 @@ 

+ <image>

+ 	<profiles>

+ 		<profile name="WSL-Base" description="Windows Subsystem for Linux Base"/>

+ 	</profiles>

+ 	<preferences profiles="WSL-Base">

+ 		<type image="tbz"/>

+ 		<timezone>Etc/UTC</timezone>

+ 		<locale>en_US</locale>

+ 		<rpm-locale-filtering>false</rpm-locale-filtering>

+ 		<rpm-excludedocs>false</rpm-excludedocs>

+ 	</preferences>

+ 	<packages type="bootstrap" profiles="WSL-Base">

+ 		<package name="bash"/>

+ 		<package name="coreutils"/>

+ 		<package name="dnf5"/>

+ 		<package name="dnf5-plugins"/>

+ 		<package name="fedora-release-wsl"/>

+ 		<package name="policycoreutils"/>

+ 		<package name="rpm"/>

+ 		<package name="selinux-policy-targeted"/>

+ 	</packages>

+ 	<packages type="image" patternType="plusRecommended" profiles="WSL-Base">

+ 		<package name="attr"/>

+ 		<package name="acl"/>

+ 		<package name="bash-color-prompt"/>

+ 		<package name="bash-completion"/>

+ 		<package name="bind-utils"/>

+ 		<package name="bzip2"/>

+ 		<package name="curl"/>

+ 		<package name="dbus"/>

+ 		<package name="default-editor"/>

+ 		<package name="file"/>

+ 		<package name="glibc-langpack-en"/>

+ 		<package name="gnupg2"/>

+ 		<package name="iproute"/>

+ 		<package name="iputils"/>

+ 		<package name="less"/>

+ 		<package name="lsof"/>

+ 		<package name="man-db"/>

+ 		<package name="man-pages"/>

+ 		<package name="NetworkManager"/>

+ 		<package name="nmap-ncat"/>

+ 		<package name="openssh-clients"/>

+ 		<package name="passwd"/>

+ 		<package name="pciutils"/>

+ 		<package name="procps-ng"/>

+ 		<package name="rsync"/>

+ 		<package name="shadow-utils"/>

+ 		<package name="sudo"/>

+ 		<package name="symlinks"/>

+ 		<package name="systemd-udev"/>

+ 		<package name="systemd-resolved"/>

+ 		<package name="tar"/>

+ 		<package name="tcpdump"/>

+ 		<package name="time"/>

+ 		<package name="traceroute"/>

+ 		<package name="tree"/>

+ 		<package name="unzip"/>

+ 		<package name="usbutils"/>

+ 		<package name="util-linux"/>

+ 		<package name="vim-minimal"/>

+ 		<package name="which"/>

+ 		<package name="whois"/>

+ 		<package name="wsl-setup"/>

+ 		<package name="zip"/>

+ 		<package name="zram-generator-defaults"/>

+ 	</packages>

+ </image>

@@ -0,0 +1,9 @@ 

+ summary: Build the Windows Subsystem for Linux image

+ discover:

+     how: fmf

+ environment:

+     image_type: tbz

+     image_profile: WSL-Base

+     kiwi_file: Fedora.kiwi

+ execute:

+     how: tmt

This introduces the beginnings of an image definition for Windows
Subsystem for Linux (WSL).

The package list is based on the core and standard grouplists. Some
packages, like the kernel, dracut, and so on, are omitted as they are
unnecessary. Others, like audit, don't work in the environment. Finally,
many packages are omitted since I thought "people probably won't want
that", so the package list is completely up for debate. This is just a
reasonable starting point that works.

I'm not sure my Kiwi definitions are reasonable, I mostly cherry-picked
things from other definitions.

Build/test instructions:

To build the tarball:

$ ./kiwi-build --image-profile=WSL-Base --image-type=tbz --output-dir=./build/

Get it to a Windows host with WSL installed. To boot it with cgroupsv2,
add the following to .wslconfig in the Windows host home folder:

[wsl2]
kernelCommandLine=systemd.unified_cgroup_hierarchhy=1 cgroup_no_v1=all

This assumes the latest WSL release is installed, at least version 2.4.4:

$ wsl --install --from-file .\path\to\the\fedora.tar.xz

Alternatively, if you're using something prior to version 2.4.4:

$ wsl --import --version=2 Fedora C:\path\to\storage\Fedora\ .\path\to\the\fedora.tar.xz

Finally, run it with:

$ wsl -d Fedora

If you are using 2.4.4+, you will be prompted for a username and then
dropped into an interactive shell with that user and passwordless sudo
access.

If you're using an older version, you need to do:

$ wsl -d Fedora -u root
# useradd ...

wsl.xml goes into the teams/cloud folder, since it'll be owned by Fedora Cloud.

rebased onto 36f8936274931a07301f536cf65a8450cfdb4340

a year ago

What is this profile for?

What is this profile for?

Ah, I had been playing with inheritance to see how that worked and missed cleaning it up in the sea of XML. Tidied it up, along with some space indentation that slipped in there.

rebased onto 0c04a5a5c3747870be7c88d1604c39a5c658ecea

a year ago

rebased onto f598200defe3ce3a0bab069b347fea978effc526

a year ago

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci
https://fedora.softwarefactory-project.io/zuul/buildset/a72f4a208bdb4aed9636d09774b2bbad

I or'd when I should have and'd

rebased onto e1dc5359f642d59beb3e77b893b765165628c40d

a year ago

Can you rebase this and switch things to pull in dnf5 instead of dnf4?

rebased onto 6c69287

8 months ago

I've rebased it and done what I think is required to use dnf5, although testing locally to build it (or a container also using dnf5) fail with KiwiCommandError: dnf5: stderr: Cannot load plugins: priorities.conf and I've not got time at the moment to debug things. I'll get back to it soon, hopefully.

Well, zuul seems happy with it, at least.

I've sketched up a change proposal for this, as well: https://fedoraproject.org/wiki/Changes/FedoraWSL

Note to my future self when I come rebase this: they've made it much easier to have a nice experience without dealing with all the appx stuff: https://learn.microsoft.com/en-us/windows/wsl/build-custom-distro. Configure a script to run to create the user, Windows now has a ".wsl" file extension to let users click to install, etc. Probably want to collect the config and script into a package we install.

rebased onto f4fe89a

4 months ago

Okay, I've rebased this. It's not merge-able at this point since I've stuffed all the wsl.conf files in the config.sh and we should move it to a package (perhaps the WSL fedora-release variant). You can build it and use the new double-click-to-install on WSL 2.4.4, though.

Okay, I've rebased this. It's not merge-able at this point since I've stuffed all the wsl.conf files in the config.sh and we should move it to a package (perhaps the WSL fedora-release variant). You can build it and use the new double-click-to-install on WSL 2.4.4, though.

Yes, this makes sense, it is a distribution property, so it should be in fedora-release-wsl.

Hyperv-daemons maybe help too. I'll check when I test to see if it's helpful or not. I usually want it for time sync but that may be handled in the wsl base itself outside the distro

The automatic build from zuul above did not include the new tarball, so I built manually from 684cadd . I was able to install it manually since I'm on an older WSL version at the moment.

 wsl --version
WSL version: 2.3.26.0
Kernel version: 5.15.167.4-1
WSLg version: 1.0.65
MSRDC version: 1.2.5620
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26100.1-240331-1435.ge-release
Windows version: 10.0.22631.4460

Issues/Observations:

  • This produced a .tar.xz, which is different from what is in the proposal mentioning .tar.gz. That is also contrary to the preference set in the source <type image="tbz"/> . wsl --import can accept .tar.xz so this is just something we should figure out for consistency between source & docs
  • The steps for manual install are missing a few things (how to run oobe.sh, how to set default user in WSL) - I will correct in the wiki

The wiki is giving me a 504 :/ here's the edits I was going to make so we have it in the thread here:

For WSL versions prior to 2.4.4:

# Have access to a Windows 10 or 11 installation (VMs should work)
# On the Windows host, download the WSL tarball from <somewhere>
# Open up a Windows terminal and install WSL itself with "wsl --install"
# Import the WSL tarball with "wsl --import Fedora $ENV:LOCALAPPDATA\WSL\Fedora .\Path\To\Fedora.x86_64-Rawhide.tar.xz"
# Enter the environment with "wsl -d Fedora -u root"
# manually execute the interactive out-of-the-box experience script to set up a new user with "/usr/libexec/wsl/oobe.sh"
# exit the environment logged in as root
# Enter the environment as the newly created user with "wsl -D Fedora -u <username>"
# Install some applications, start some services, see if things fall over.

The automatic build from zuul above did not include the new tarball, so I built manually from 684cadd . I was able to install it manually since I'm on an older WSL version at the moment.

wsl --version WSL version: 2.3.26.0 Kernel version: 5.15.167.4-1 WSLg version: 1.0.65 MSRDC version: 1.2.5620 Direct3D version: 1.611.1-81528511 DXCore version: 10.0.26100.1-240331-1435.ge-release Windows version: 10.0.22631.4460

Issues/Observations:

  • This produced a .tar.xz, which is different from what is in the proposal mentioning .tar.gz. That is also contrary to the preference set in the source <type image="tbz"/> . wsl --import can accept .tar.xz so this is just something we should figure out for consistency between source & docs
  • The steps for manual install are missing a few things (how to run oobe.sh, how to set default user in WSL) - I will correct in the wiki

Yeah, I haven't decided quite what we should do here. At some point Windows got support for XZ, so for newer versions it'll happily handle a tar.xz. There's probably some knob on kiwi to have it spit out a tar.gz if we want since IIRC the Google images are tar.gz. If we decide to support older Windows without XZ we should figure that out.

I didn't document where the oobe.sh script would be since I wasn't certain. I also think WSL is doing something extra since it drops you into the the environment as the correct user after it executes it for you first time - running it manually won't quite be the same.

The documentation Gentoo provides covers all the manual steps, I think: https://wiki.gentoo.org/wiki/Gentoo_in_WSL#Setting_up_a_non-root_default_user.

The wiki is giving me a 504 :/ here's the edits I was going to make so we have it in the thread here:

```
For WSL versions prior to 2.4.4:

Have access to a Windows 10 or 11 installation (VMs should work)

On the Windows host, download the WSL tarball from <somewhere>

Open up a Windows terminal and install WSL itself with "wsl --install"

Import the WSL tarball with "wsl --import Fedora $ENV:LOCALAPPDATA\WSL\Fedora .\Path\To\Fedora.x86_64-Rawhide.tar.xz"

Enter the environment with "wsl -d Fedora -u root"

manually execute the interactive out-of-the-box experience script to set up a new user with "/usr/libexec/wsl/oobe.sh"

exit the environment logged in as root

Enter the environment as the newly created user with "wsl -D Fedora -u <username>"

Install some applications, start some services, see if things fall over.

```

I'll make some adjustments to the wiki based on this, I'll just add a bit about adding an /etc/wsl.conf with the default user.

Thanks for the feedback and testing!

Can you add a WSL plan in https://pagure.io/fedora-kiwi-descriptions/blob/rawhide/f/tmt/plans so that the CI can start building WSL images? You can look at the Vagrant and Cloud plans as inspiration for how to do this.

A few more updates from my testing:

  • Indeed WSL 2.4.4+ is required for the .wsl extension handler.
  • The default version of WSL (2.3.26.0) seems to be the same everywhere Windows 10 22h2 (build 10.0.19045.2965), Windows 11 23h2 (build 10.0.22631.4460), and Windows 11 24h2 (build 10.0.26100.1742)
  • The manual steps for pre-2.4.4 work as described even on Windows 10
  • .tar.xz is fine on all 3 OS versions I tried

I'll see if I can get some Windows-specific automation written in PowerShell next. It would be something along the lines of:

  • Install WSL if not installed already
  • Reboot
  • Ensure that the .wsl (or .tar.xz) can be imported
  • Launch Fedora as root to verify it runs
  • Launch Fedora using default command and check oobe script works, and creates a user
  • Ensure WSL can run as that user, and sudo dnf install something

Once I have that we can figure out whether or not to run it via Vagrant on Azure or other means. I was going to try this locally but unfortunately my old packer scripts no longer work on current release of Windows 11 since local user creation has been locked out. Testing on a cloud provider that donates an account to the project is probably more sustainable than trying to keep a volunteer running an on-premises Windows server for this effort.

rebased onto 88b268c

4 months ago

Can you add a WSL plan in https://pagure.io/fedora-kiwi-descriptions/blob/rawhide/f/tmt/plans so that the CI can start building WSL images? You can look at the Vagrant and Cloud plans as inspiration for how to do this.

Done, and it seems to be working.

I started some rough tests at https://github.com/PatrickLang/fedora-wsl-tests for now.

Do you have any suggestions on where a better long-term place would be for these tests? If there will be a new package to hold the files (oobe.sh, wsl.conf, ...) , would it make sense to dual purpose that repo? That way the tests could be revised at the same time as the packages.

rebased onto 01b6f43

3 months ago

1 new commit added

  • WSL: Add a tmpfiles config for X11
3 months ago

3 new commits added

  • WSL: Add a tmpfiles config for X11
  • WSL: Disable systemd-firstboot service
  • Add a WSL definition and config snippets
3 months ago

3 new commits added

  • WSL: Add a tmpfiles config for X11
  • WSL: Disable systemd-firstboot service
  • Add a WSL definition and config snippets
3 months ago

I think that WSLg may be more accurate here, but am not sure. Since WSLg is part of the internal distro its package might contain systemd. I think the WSL versions should be 2.x or higher.

User still needs to be set in wsl.conf,

rebased onto 90f4f3a

3 months ago

1 new commit added

  • WSL: Add a user-tmpfiles.d config for Wayland and PulseAudio
3 months ago

I've updated the package set to pull in fedora-release-wsl and wsl-setup, so I'm able to drop most of the configs being dumped in the config.sh as well as the setup script.

I added one more tmpfiles related change to link the Wayland socket and pulse directory into the expected location. I was able to start up gnome-sound-recorder, record a sound, and play it back.

User still needs to be set in wsl.conf,

I've moved the script to a package and included a fix for this: https://src.fedoraproject.org/rpms/wsl-setup/blob/rawhide/f/wsl-oobe.sh#_32

The currently-building image includes this.

I think that WSLg may be more accurate here, but am not sure. Since WSLg is part of the internal distro its package might contain systemd. I think the WSL versions should be 2.x or higher.

From what I recall I looked up when WSL first supported booting with systemd. I don't think we should bother testing (or claim to work with) more than 2.3 and 2.4, though.

1 new commit added

  • WSL: Add wget to the image
3 months ago

rebased onto 90f4f3a

2 months ago

Pull-Request has been merged by ngompa

2 months ago