Backing up WSL on Windows

Posted on Monday, March 2, 2026


 


 

I recently wrote a quick article on setting up WSL with Ubuntu on Windows.  https://www.whiteboardcoder.com/2026/01/replacing-cygwin-with-ubuntu-using-wsl.html [1]

I am concerned once I get it set up like I want that it accidentally gets deleted.

 

For example I can open up powershell as admin and run this command

 

> wsl --list --verbose

 

 


 

And I can remove the Ubuntu-24.04 by running this.

 

> wsl --unregister Ubuntu-24.04

 


And now it’s wiped out.

 



If I attempt to open it again from my menu bar (which I pined in my last post)



It reinstalls Ubuntu.

That is neat but not what I want.
How can I back it up?
Also how can I lock it so it can’t be removed to begin with?

Poking around I do not see any way to lock it down.
So how can I back it up and restore it.


Backing up

Shut down the WSL Ubuntu.

Create a folder to store the backups in.
I am creating a folder in D:\WSL\Ubuntu\
to back it up in.

Then run this command in Powershell

 

> wsl --export Ubuntu-24.04 "D:\WSL\Ubuntu\Ubuntu-24.04-$(Get-Date -Format yyyy-MM-dd).tar"


This may take a few min depending on side

 



 

 

Now let me unregister (delete the current one)

 

> wsl --unregister Ubuntu-24.04

Now to run this command to recreate the WSL using the backup

 

> wsl --import Ubuntu-24.04 D:\WSL\Ubuntu\  D:\WSL\Ubuntu\Ubuntu-24.04-2026-03-02.tar


Opening my pinned menu bar gets me this


A few checks confirms it worked but… it logged me in as root, not my user.

Looks like the answer to fix that is to export it in another format vhd vs the tar file.

Ok let me recreate the WSL ubuntu from scratch, so I have my user setup the way I want.


   > wsl --export Ubuntu-24.04 "D:\WSL\Ubuntu\Ubuntu-24.04-$(Get-Date -Format yyyy-MM-dd).vhdx" --vhd



 

 

Now let me unregister (delete the current one)

 

> wsl --unregister Ubuntu-24.04

Now to run this command to recreate the WSL using the backup

 

> wsl --import Ubuntu-24.04 D:\WSL\Ubuntu\  D:\WSL\Ubuntu\Ubuntu-24.04-2026-03-02.vhdx --vhd --version 2

 


Opening my pinned menu bar gets me this



OK still root…

 


Fixing it with /etc/wsl.conf

 

There appears a way to fix this.
Let me reset and install it fresh.

 

> wsl --unregister Ubuntu-24.04
> wsl --install ubuntu-24.04

Now edit the /etc/wsl.conf file

 

> sudo vi /etc/wsl.conf

   

Add

 

[user]

default=patman

 


Now let me shut it down and back it up in a tar file then restore it.

Then run this command in Powershell

 

> wsl --export Ubuntu-24.04 "D:\WSL\Ubuntu\Ubuntu-24.04-$(Get-Date -Format yyyy-MM-dd).tar"

Now let me unregister (delete the current one)

 

> wsl --unregister Ubuntu-24.04

Now to run this command to recreate the WSL using the backup

 

> wsl --import Ubuntu-24.04 D:\WSL\Ubuntu\  D:\WSL\Ubuntu\Ubuntu-24.04-2026-03-02.tar

 


Wahoo that worked!

I am going to set up a reminder in Slack to remind me every month to back up my WSL.

 

 


References

[1]  Replacing Cygwin with Ubuntu Using WSL on Windows

       https://www.whiteboardcoder.com/2026/01/replacing-cygwin-with-ubuntu-using-wsl.html
       Visited 1/2013

No comments:

Post a Comment