Skip to content

Instantly share code, notes, and snippets.

@stephenchew
Created February 14, 2024 09:39
Show Gist options
  • Save stephenchew/0647e3671e2a1f3dea3c0f6c1d3c832d to your computer and use it in GitHub Desktop.
Save stephenchew/0647e3671e2a1f3dea3c0f6c1d3c832d to your computer and use it in GitHub Desktop.
WSL import/export and setting default user

Export a WSL instance

wsl --export <distribution name> <export file name>

e.g.

wsl --export Ubuntu-22.04 D:\wsl-backup\Ubuntu.22.04.tar

Import a WSL instance

wsl --import <distribution name> <location of vhdx file> <wsl backup file>

e.g.

wsl --import Ubuntu-22.04 D:\wsl D:\wsl-backup\Ubuntu.22.04.tar

Setting default user

Upon importing of WSL, default user has to be set, or else it'll fall back to root user.

🔗 https://superuser.com/questions/1566022/how-to-set-default-user-for-manually-installed-wsl-distro#answer-1627461

  1. Create a file at /etc/wsl.conf in the distro if it hasn't already existed.
  2. Add the following block
    [user]
    default=username
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment