Post

Linux(Ubuntu), Export & Import

Let's manage Ubuntu history, just like snapshots in VirtualBox.

Linux(Ubuntu), Export & Import

In WSL (Windows Subsystem for Linux), Ubuntu is managed and stored in a virtual disk file called ext4.vhdx. Since I plan to conduct various tests, there will be times when I need to revert to a previous version. VirtualBox provides a snapshot feature, but unfortunately, WSL does not.Therefore, I will use WSL’s export and import functions to manage system versions.

Export & Import Ubuntu

Follow the commands below to proceed. Be cautious: if you use wsl --unregister Ubuntu, the ext4.vhdx file will also be deleted!!! Use it carefully.

wsl --export Ubuntu "D:\01.WSL\ubuntu-1-install_wsl.tar"
wsl --unregister Ubuntu
wsl --import Ubuntu "D:\01.WSL" "D:\01.WSL\ubuntu-1-install_wsl.tar"
ubuntu config --default-user jaoneol

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#####################################################################
PS C:\Windows\system32> wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Running         2
PS C:\Windows\system32> wsl --shutdown
PS C:\Windows\system32> wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Stopped         2
#####################################################################
PS C:\Windows\system32> wsl --export  Ubuntu "D:\01.WSL\ubuntu-1-install_wsl.tar"
내보내기가 진행 중입니다. 이 작업은 몇 분 정도 걸릴 수 있습니다...
작업을 완료했습니다.
######################################################################
# Very Important, Run the following command to remove the distribution.
# Be extremely careful!, If you run this command, the `ext4.vhdx` file will also be deleted!!!
PS C:\Windows\system32> wsl --unregister Ubuntu
등록 취소 중입니다.
작업을 완료했습니다.
######################################################################
# Running this command will create `ext4.vhdx` in the `D:\01.WSL` directory.
PS C:\Windows\system32> wsl --import Ubuntu "D:\01.WSL" "D:\01.WSL\ubuntu-1-install_wsl.tar"
가져오기가 진행 중입니다. 이 작업은 몇 분 정도 걸릴 수 있습니다.
작업을 완료했습니다.
PS C:\Windows\system32> wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Stopped         2
#####################################################################
# If you run this command, you will log in with the `jaoneol` account instead of the root account when accessing Ubuntu.
PS C:\Windows\system32> ubuntu config --default-user jaoneol
PS C:\Windows\system32>
This post is licensed under CC BY 4.0 by the author.