Skip to content

Instantly share code, notes, and snippets.

@mmitchel
Last active September 27, 2025 16:40
Show Gist options
  • Select an option

  • Save mmitchel/18f57e434c9816ccaddf7ace709fa586 to your computer and use it in GitHub Desktop.

Select an option

Save mmitchel/18f57e434c9816ccaddf7ace709fa586 to your computer and use it in GitHub Desktop.
#cloud-config
############################################################
# Configuration for Ubuntu 24.04 LTS running on WSL
# - Install content from below of /etc/wslconfig at %USERPROFILE%\.wslconfig
# - Install this file at %USERPROFILE%\.cloud-init\Ubuntu-24.04.user-data
# - Execute "cmd.exe /c setx.exe GNUPGHOME %USERPROFILE%\.gnupg"
# - Execute "cmd.exe /c setx.exe WLSENV USERNAME:USERPROFILE/p"
# - Execute "cmd.exe /c wsl.exe --shutdown"
# - Execute "cmd.exe /c wsl.exe --update"
# - Execute "cmd.exe /c wsl.exe --unregister Ubuntu-24.04"
# - Execute "cmd.exe /c wsl.exe --install Ubuntu-24.04"
# - Execute "cmd.exe /c wsl.exe --list --running" until Ubunu-24.04 is not shown
# - Terminate all instances of Windows Terminal
# - Wait ~60 seconds
# - Start new instances of Windows Terminal CLI prompts
# Interop with USB Mass Storage
# - Install from https://github.com/dorssel/usbipd-win, v5.x
# - Insert USB flash disk
# - Execute Elevated Privileges "cmd.exe /c usbipd.exe list"
# - Execute Elevated Privileges "cmd.exe /c usbipd.exe unbind --all"
# - Execute Elevated Privileges "cmd.exe /c usbipd.exe bind --hardware-id VID:PID --force"
# - Execute "cmd.exe /c usbipd.exe attach --hardware-id VID:PID --wsl"
############################################################
# apt:
# http_proxy: 'http://windows_user:windows_password@10.63.136.30:8080/'
locale: en_US.UTF-8
users:
- name: user
gecos: User
plain_text_passwd: 'password'
groups: [adm,dialout,disk,cdrom,floppy,sudo,audio,dip,video,plugdev,netdev]
shell: /bin/bash
homedir: /home/user
sudo: ['ALL=(ALL) NOPASSWD: ALL']
write_files:
# Install this file at %USERPROFILE%\.wslconfig
- path: /etc/wslconfig
owner: 'root:root'
permissions: '0755'
content: |
[wsl2]
networkingMode=mirrored
firewall=false
defaultVhdSize=549755813888
dnsProxy=false
[experimental]
autoMemoryReclaim=disabled
# Overwrite the original
- path: /etc/wsl.conf
owner: 'root:root'
permissions: '0644'
defer: false
append: false
content: |
[boot]
systemd=true
[user]
default=user
[automount]
enabled=true
mountFsTab=true
options="uid=1000,gid=1000,case=off,fmask=0077,dmask=0077"
[network]
hostname=wsl
[interop]
enabled=true
appendWindowsPath=true
[time]
useWindowsTimezone=true
# Overwrite the original
- path: /usr/lib/wsl/wsl-setup
owner: 'root:root'
permissions: '0755'
defer: false
append: false
content: |
#!/bin/bash
set -euo pipefail
echo "Provisioning the new WSL instance $WSL_DISTRO_NAME"
echo "This might take a while... $WSLENV"
# Wait for cloud-init to finish if systemd and its service is enabled
# by running the script located at the same dir as this one.
this_dir=$(dirname "$(realpath $0)")
source "${this_dir}/wait-for-cloud-init"
echo "Terminate all Windows Terminal instances when returned to the"
echo "command prompt; wait 60 seconds. Start new instances of Windows"
echo "Terminal."
- path: /etc/profile.d/wsl-instance.sh
owner: 'root:root'
permissions: '0644'
content: |
# WSL Instance
export BB_NICE_LEVEL="5"
export BB_NUMBER_THREADS="$(( $(nproc) * 50 / 100 ))"
export PARALLEL_MAKE="-j$(( BB_NUMBER_THREADS * 50 / 100 ))"
export BB_ENV_PASSTHROUGH_ADDITIONS="BB_NICE_LEVEL BB_NUMBER_THREADS PARALLEL_MAKE"
export XDG_RUNTIME_DIR=/run/user/$(id -u)
export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock
if [ "$USER" != "root" ] ; then
if [ -n "$USERPROFILE" ] ; then
if [ -d "$USERPROFILE" ] ; then
mkdir -p "$USERPROFILE/.config" && ln -sf "$USERPROFILE/.config" $HOME/.config && rm -f $HOME/.config/.config
mkdir -p "$USERPROFILE/.gnupg" && ln -sf "$USERPROFILE/.gnupg" $HOME/.gnupg && rm -f $HOME/.gnupg/.gnupg
mkdir -p "$USERPROFILE/.local/bin"
export PATH="$USERPROFILE/.local/bin:$PATH"
[[ -d $HOME/.ssh && ! -h $HOME/.ssh ]] && mv -f $HOME/.ssh $HOME/.ssh.old
mkdir -p "$USERPROFILE/.ssh" && ln -sf "$USERPROFILE/.ssh" $HOME/.ssh && rm -f $HOME/.ssh/.ssh
touch "$USERPROFILE/.netrc" && ln -sf "$USERPROFILE/.netrc" $HOME/.netrc
touch "$USERPROFILE/.s3cfg" && ln -sf "$USERPROFILE/.s3cfg" $HOME/.s3cfg
rm -fr $HOME/.config/systemd/user
rm -fr $HOME/.config/systemd/user.control
fi
fi
fi
- path: /etc/sysctl.d/wsl-instance.conf
owner: 'root:root'
permissions: '0644'
content: |
fs.inotify.max_user_watches = 524288
- path: /etc/smbcredentials
owner: 'root:root'
permissions: '0600'
content: |
username=windows_user
password=windows_password
# Overwrite the original
- path: /etc/fstab
owner: 'root:root'
permissions: '0644'
content: |
# wsl-instance /etc/fstab
# M: /mnt/m drvfs defaults,nosuid,nodev,x-mount.mkdir 0 0
# //10.236.1.99/share /mnt/share cifs credentials=/etc/smbcredentials,nosuid,nodev,x-mount.mkdir 0 0
packages:
# Yocto Development
- build-essential
- chrpath
- cpio
- debianutils
- diffstat
- file
- gawk
- gcc
- git
- git-lfs
- iputils-ping
- libacl1
- liblz4-tool
- locales
- python3
- python3-git
- python3-jinja2
- python3-pexpect
- python3-pip
- python3-subunit
- socat
- texinfo
- unzip
- wget
- xz-utils
- zstd
# General
- wslu
- curl
- gnupg2
- htop
- jq
- pciutils
- usbutils
- python3-paho-mqtt
- python3-serial
- python3-serial-asyncio
- python3-paramiko
- python3-venv
- repo
- rsync
- s3cmd
- uidmap
- mosquitto
- mosquitto-clients
# Disk and Filesystem
- dosfstools
- e2fsprogs
- btrfs-progs
- cryptsetup
- ostree
- cifs-utils
- parted
package_update: true
package_upgrade: true
runcmd:
- |
mkdir -p /srv/repo
chmod 1777 /srv/repo
touch /root/.hushlogin
- |
mkdir -p /home/user
rsync -av /etc/skel/ /home/user/
touch /home/user/.hushlogin
chown -R user:user /home/user
# Terminate WSL instance
- |
shutdown --poweroff now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment