Skip to content

Instantly share code, notes, and snippets.

@coin8086
Last active January 13, 2024 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coin8086/c0edf4c2f85dc890e3ca1b1e0cc619e0 to your computer and use it in GitHub Desktop.
Save coin8086/c0edf4c2f85dc890e3ca1b1e0cc619e0 to your computer and use it in GitHub Desktop.
WSL settings and issue fixes

WSL Settings and Issue Fixes

Enable systemd

  1. Get the latest version WSL from the Windows Store

  2. Ensure /etc/wsl.conf has

    [boot]
    systemd=true
    
  3. Restart WSL by wsl.exe --shutdown

Refer to

Set custom host name for a distro

  1. Edit /etc/wsl.conf like

    [network]
    hostname=your-host-name
    generateHosts=false
    

    Replace your-host-name with your host name.

  2. Edit /etc/hosts, replacing every occurrence of the old host name with your new host name.

  3. Restart WSL by wsl.exe --shutdown

Refer to:

Change the default login user for a distro

Use a distro command like

ubuntu2204.exe config --default-user your-user-name

Fix the time issue after Windows sleep

The issue is that when a WSL distro is open and Windows starts sleep, then the date time on the distro may be incorrect after the sleep. The fix is to to enable the systemd-timesyncd service on the distro.

  1. Ensure systemd is enabled as said by Enable systemd

  2. Install systemd-timesyncd if not, by

    sudo apt install systemd-timesyncd
  3. Edit its config by

    sudo systemctl edit systemd-timesyncd

    Ensure the config has

    [Unit]
    ConditionVirtualization=
    
  4. Start or restart it by

    sudo systemctl start systemd-timesyncd

    or

    sudo systemctl restart systemd-timesyncd

Refer to

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment