brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: exporting a WSL distro packs your Windows setup into one tar file

Windows
~/tips/tip-windows-wsl-export-backup

wsl --terminate Ubuntu

Save a whole WSL distribution to a tar file you can import again.

Everything I install inside a WSL distro lives in one place that is easy to forget about when making backups. WSL can write the whole thing to a single file.

First look up the exact name with wsl --list. Then stop the distro so files aren’t changing, and export it:

wsl --terminate Ubuntu
wsl --export Ubuntu D:\Backups\ubuntu.tar

The default format is tar. On WSL 2 you can add --vhd to get a .vhdx virtual disk instead.

To bring it back, or to make a throwaway copy for an experiment, import the file under a new name and give it a folder to live in:

wsl --import Ubuntu-test D:\WSL\Ubuntu-test D:\Backups\ubuntu.tar

Now you have two separate systems, and you can break the second one without worry.

Two things to keep in mind. The tar file contains everything in the distro, including SSH keys, tokens and shell history, so store it somewhere you trust. And an imported distro has no launcher program, which means the usual config --default-user command doesn’t work for it. Set the default user in /etc/wsl.conf inside the copy if it starts as root.

Further reading: Basic commands for WSL

More Windows tips Win+Ctrl+C Win+Shift+Left arrow Win+Ctrl+Left arrow Alt+PrtScn Left Alt + Left Shift + Print Screen All Windows tips (33) All topics

Link