Skip to content

Instantly share code, notes, and snippets.

@junkor-1011
Last active November 22, 2024 15:03
Show Gist options
  • Save junkor-1011/945f9cec10a8cfd8a81f01bf926486f3 to your computer and use it in GitHub Desktop.
Save junkor-1011/945f9cec10a8cfd8a81f01bf926486f3 to your computer and use it in GitHub Desktop.
WSL2 cloud-init example
#cloud-config
# EXAMPLE
timezone: Asia/Tokyo
locale: en_US.utf8
users:
- name: wsl-user
groups: [adm, sudo, wheel]
sudo:
- ALL=(ALL) NOPASSWD:ALL
uid: 1000
shell: /usr/bin/fish
package_update: true
package_upgrade: true
packages:
- tmux
- fish
- htop
- fzf
- ripgrep
write_files:
- path: /etc/wsl.conf
append: true
content: |
[boot]
systemd=true
[user]
default=wsl-user
runcmd:
- echo "cloud-init" >> /tmp/sample.txt

WSL2 cloud-init example

setup steps

  1. put <distribution-name>.user-data to %USERPROFILE%\.cloud-init
  2. start wsl2: wsl.exe -d <distribution-name> --cd ~
  3. exec cloud-init.sh
    • cloud-init init --local
    • cloud-init init
    • cloud-init modules --mode=config
    • cloud-init modules --mode=final
  4. restart wsl2
#!/bin/bash
cloud-init init --local
cloud-init init
cloud-init modules --mode=config
cloud-init modules --mode=final
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment