Difference between revisions of "HOW-TO: Backup or Move WSL2 Distro"
(→Backup and Restore WSL2 Distros) |
|||
(34 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | [[File:Wsl-move.png|right|middle|thumb|Moving a WSL2 distro using lxrunoffline]] | |
+ | [[File:WSL2-multi-instance.png|right|middle|thumb|Running multiple distros and instances under WSL2 with Windows Terminal]] | ||
− | + | == References == | |
− | |||
− | Microsoft Windows [Version 10.0. | + | * https://www.jskap.com/notes/how-to-move-wsl2-disto/ |
+ | * https://www.jskap.com/blog/install-move-wsl-distro-from-c-drive-to-another-drive/ | ||
+ | * https://www.howtogeek.com/426562/how-to-export-and-import-your-linux-systems-on-windows-10/ | ||
+ | |||
+ | == Related == | ||
+ | * [[Windows Terminal - settings.json]] | ||
+ | * [[HOW-TO: Rename WSL Distro Name]] | ||
+ | |||
+ | ==Backup and Restore WSL2 Distros== | ||
+ | <syntaxhighlight lang="Shell"> | ||
+ | ## Listing all WSL2 Distros using Windows Powershell running as Administrator | ||
+ | PS C:\WINDOWS\system32> wsl --list -v | ||
+ | NAME STATE VERSION | ||
+ | * Ubuntu Running 2 | ||
+ | Fedora Running 2 | ||
+ | CentOS Running 2 | ||
+ | docker-desktop Running 2 | ||
+ | docker-desktop-data Running 2 | ||
+ | |||
+ | ## Shutdown all WSL2 Distros using Windows Powershell running as Administrator | ||
+ | PS C:\WINDOWS\system32> wsl --shutdown | ||
+ | |||
+ | ## Listing all WSL2 Distros using Windows Powershell running as Administrator | ||
+ | PS C:\WINDOWS\system32> wsl --list -v | ||
+ | NAME STATE VERSION | ||
+ | * Ubuntu Stopped 2 | ||
+ | Fedora Stopped 2 | ||
+ | CentOS Stopped 2 | ||
+ | docker-desktop Stopped 2 | ||
+ | docker-desktop-data Stopped 2 | ||
+ | |||
+ | ## Export using Windows Powershell running as Administrator | ||
+ | ## EXAMPLE: wsl --export distro_name file_name.tar | ||
+ | PS C:\WINDOWS\system32> wsl --export Ubuntu C:\Shared\WSL2\Backups\Ubuntu.tar | ||
+ | PS C:\WINDOWS\system32> wsl --export Fedora C:\Shared\WSL2\Backups\Fedora.tar | ||
+ | PS C:\WINDOWS\system32> wsl --export CentOS C:\Shared\WSL2\Backups\CentOS.tar | ||
+ | |||
+ | ## Remove old WSL instances | ||
+ | wsl --unregister Ubuntu | ||
+ | wsl --unregister Fedora | ||
+ | wsl --unregister CentOS | ||
+ | |||
+ | ## Import using Windows Powershell running as Administrator | ||
+ | ## EXAMPLE: wsl --import distro_name install_location file_name.tar | ||
+ | wsl --import Ubuntu C:\Shared\WSL2\Ubuntu C:\Shared\WSL2\Backups\Ubuntu.tar | ||
+ | wsl --import Fedora C:\Shared\WSL2\Fedora C:\Shared\WSL2\Backups\Fedora.tar | ||
+ | wsl --import CentOS C:\Shared\WSL2\CentOS C:\Shared\WSL2\Backups\CentOS.tar | ||
+ | |||
+ | ## Listing backups under /Shared/WSL2/Backups | ||
+ | Shared/WSL2/Backups on ☁️ (us-east-1) on ☁️ [redacted] | ||
+ | ❯ ls -lah | ||
+ | rwxrwxrwx 1 root root 4 KiB Sun Aug 15 06:22:16 2021 ./ | ||
+ | rwxrwxrwx 1 root root 4 KiB Mon Jun 28 07:06:34 2021 ../ | ||
+ | rwxrwxrwx 1 root root 553 B Thu Aug 12 16:04:20 2021 backup-wsl2-distros.ps1 | ||
+ | rwxrwxrwx 1 root root 2 GiB Thu Aug 12 15:53:59 2021 CentOS.tar | ||
+ | rwxrwxrwx 1 root root 557 B Mon Oct 19 15:10:28 2020 fedora.png | ||
+ | rwxrwxrwx 1 root root 4 GiB Thu Aug 12 15:53:00 2021 Fedora.tar | ||
+ | rwxrwxrwx 1 root root 787 B Mon Oct 19 15:09:44 2020 redhat.png | ||
+ | rwxrwxrwx 1 root root 838 B Thu Aug 12 16:04:09 2021 restore-wsl2-distros.ps1 | ||
+ | rwxrwxrwx 1 root root 20 KiB Sun Jun 27 22:01:44 2021 settings.json | ||
+ | rwxrwxrwx 1 root root 560 B Mon Oct 19 15:11:24 2020 ubuntu.png | ||
+ | rwxrwxrwx 1 root root 12 GiB Thu Aug 12 15:51:57 2021 Ubuntu.tar | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == Move WSL to Another Location == | ||
+ | |||
+ | === Installing LxRunOffline [DEPRECATED with `wsl` replacing `lxrunoffline` functions] === | ||
+ | |||
+ | * Install '''LxRunOffline''' via [https://chocolatey.org/ '''Choco''' ''(Package Manager for Windows)''] | ||
+ | |||
+ | <syntaxhighlight lang="Shell"> | ||
+ | ## From within your Windows PowerShell running as Administrator | ||
+ | PS C:\WINDOWS\system32> choco install lxrunoffline | ||
+ | |||
+ | Chocolatey v0.10.15 | ||
+ | Installing the following packages: | ||
+ | lxrunoffline | ||
+ | By installing you accept licenses for the packages. | ||
+ | Progress: Downloading lxrunoffline 3.5.0... 100% | ||
+ | |||
+ | lxrunoffline v3.5.0 [Approved] | ||
+ | lxrunoffline package files install completed. Performing other installation steps. | ||
+ | The package lxrunoffline wants to run 'chocolateyInstall.ps1'. | ||
+ | Note: If you don't run this script, the installation will fail. | ||
+ | Note: To confirm automatically next time, use '-y' or consider: | ||
+ | choco feature enable -n allowGlobalConfirmation | ||
+ | Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): A | ||
+ | |||
+ | Progress: 100% - Running Microsoft.Dism.Commands.ImageObject | ||
+ | Downloading lxrunoffline | ||
+ | from 'https://github.com/DDoSolitary/LxRunOffline/releases/download/v3.5.0/LxRunOffline-v3.5.0-msvc.zip' | ||
+ | Progress: 100% - Completed download of C:\Users\kenfo\AppData\Local\Temp\lxrunoffline\3.5.0\LxRunOffline-v3.5.0-msvc.zip (2.54 MB). | ||
+ | Download of LxRunOffline-v3.5.0-msvc.zip (2.54 MB) completed. | ||
+ | Hashes match. | ||
+ | Extracting C:\Users\kenfo\AppData\Local\Temp\lxrunoffline\3.5.0\LxRunOffline-v3.5.0-msvc.zip to C:\tools\lxrunoffline... | ||
+ | C:\tools\lxrunoffline | ||
+ | PATH environment variable does not have C:\tools\lxrunoffline in it. Adding... | ||
+ | Environment Vars (like PATH) have changed. Close/reopen your shell to | ||
+ | see the changes (or in powershell/cmd.exe just type `refreshenv`). | ||
+ | The install of lxrunoffline was successful. | ||
+ | Software installed to 'C:\tools\lxrunoffline' | ||
+ | |||
+ | Chocolatey installed 1/1 packages. | ||
+ | See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log). | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | === Listing WSL2 Distros using LxRunOffline [DEPRECATED with `wsl` replacing `lxrunoffline` functions] === | ||
+ | |||
+ | * '''lxrunoffline list''' - List all the installed distros on your system. | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
+ | ## From within your Windows Command Prompt (cmd.exe) | ||
+ | Microsoft Windows [Version 10.0.19042.572] | ||
(c) 2020 Microsoft Corporation. All rights reserved. | (c) 2020 Microsoft Corporation. All rights reserved. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | C:\Users\kenfo>lxrunoffline list | |
− | You can use the same move command to move your distro from default location to a different location inside C Drive. | + | Ubuntu-20.04 |
+ | |||
+ | C:\Users\kenfo> | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | === Moving Distro Locations using LxRunOffline [DEPRECATED with `wsl` replacing `lxrunoffline` functions] === | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
+ | ## From within Windows PowerShell as Administrator | ||
+ | wsl --shutdown | ||
+ | |||
+ | ## From within the Windows Command Prommpt (cmd.exe) | ||
+ | lxrunoffline move -n Ubuntu-20.04 -d M:\Shared\WSL2\ubuntu . | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | === Moving Distro Locations using wsl === | ||
+ | * Example for moving from internal/default to M:\Shared\WSL\Ubuntu | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
+ | ## From within Windows PowerShell as Administrator | ||
+ | |||
+ | ## Prep shared drive (used for backup, restore, and storage) | ||
+ | cd M:\Shared\ | ||
+ | mkdir -p WSL2\Ubuntu | ||
+ | cd M:\Shared\WSL2\Ubuntu | ||
+ | |||
+ | ## Export and Unregister (if desired) from WSL | ||
+ | wsl --export Ubuntu ubuntu.tar | ||
+ | wsl --unregister Ubuntu | ||
+ | |||
+ | ## Import Distro Name to Target from Backup | ||
+ | wsl --import Ubuntu Ubuntu ubuntu.tar | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | * Move your distro to another drive. My distro name here is '''Ubuntu'''. I am moving it to '''M:''' drive and '''\Shared\WSL2''' folder inside it. ''(This will take some time to complete, '''lxrunoffline''' doesn't provide feedback during the move.)'' | ||
+ | * You can use the same '''move''' command to move your distro from default location to a different location inside C Drive. | ||
+ | |||
+ | [[Category:HOW-TO]] | ||
+ | [[Category:Windows_Subsystem_for_Linux_(WSL)]] | ||
+ | [[Category:Windows]] |
Latest revision as of 05:15, 15 August 2021
Contents
- 1 References
- 2 Related
- 3 Backup and Restore WSL2 Distros
- 4 Move WSL to Another Location
- 4.1 Installing LxRunOffline [DEPRECATED with `wsl` replacing `lxrunoffline` functions]
- 4.2 Listing WSL2 Distros using LxRunOffline [DEPRECATED with `wsl` replacing `lxrunoffline` functions]
- 4.3 Moving Distro Locations using LxRunOffline [DEPRECATED with `wsl` replacing `lxrunoffline` functions]
- 4.4 Moving Distro Locations using wsl
References
- https://www.jskap.com/notes/how-to-move-wsl2-disto/
- https://www.jskap.com/blog/install-move-wsl-distro-from-c-drive-to-another-drive/
- https://www.howtogeek.com/426562/how-to-export-and-import-your-linux-systems-on-windows-10/
Related
Backup and Restore WSL2 Distros
## Listing all WSL2 Distros using Windows Powershell running as Administrator
PS C:\WINDOWS\system32> wsl --list -v
NAME STATE VERSION
* Ubuntu Running 2
Fedora Running 2
CentOS Running 2
docker-desktop Running 2
docker-desktop-data Running 2
## Shutdown all WSL2 Distros using Windows Powershell running as Administrator
PS C:\WINDOWS\system32> wsl --shutdown
## Listing all WSL2 Distros using Windows Powershell running as Administrator
PS C:\WINDOWS\system32> wsl --list -v
NAME STATE VERSION
* Ubuntu Stopped 2
Fedora Stopped 2
CentOS Stopped 2
docker-desktop Stopped 2
docker-desktop-data Stopped 2
## Export using Windows Powershell running as Administrator
## EXAMPLE: wsl --export distro_name file_name.tar
PS C:\WINDOWS\system32> wsl --export Ubuntu C:\Shared\WSL2\Backups\Ubuntu.tar
PS C:\WINDOWS\system32> wsl --export Fedora C:\Shared\WSL2\Backups\Fedora.tar
PS C:\WINDOWS\system32> wsl --export CentOS C:\Shared\WSL2\Backups\CentOS.tar
## Remove old WSL instances
wsl --unregister Ubuntu
wsl --unregister Fedora
wsl --unregister CentOS
## Import using Windows Powershell running as Administrator
## EXAMPLE: wsl --import distro_name install_location file_name.tar
wsl --import Ubuntu C:\Shared\WSL2\Ubuntu C:\Shared\WSL2\Backups\Ubuntu.tar
wsl --import Fedora C:\Shared\WSL2\Fedora C:\Shared\WSL2\Backups\Fedora.tar
wsl --import CentOS C:\Shared\WSL2\CentOS C:\Shared\WSL2\Backups\CentOS.tar
## Listing backups under /Shared/WSL2/Backups
Shared/WSL2/Backups on ☁️ (us-east-1) on ☁️ [redacted]
❯ ls -lah
rwxrwxrwx 1 root root 4 KiB Sun Aug 15 06:22:16 2021 ./
rwxrwxrwx 1 root root 4 KiB Mon Jun 28 07:06:34 2021 ../
rwxrwxrwx 1 root root 553 B Thu Aug 12 16:04:20 2021 backup-wsl2-distros.ps1
rwxrwxrwx 1 root root 2 GiB Thu Aug 12 15:53:59 2021 CentOS.tar
rwxrwxrwx 1 root root 557 B Mon Oct 19 15:10:28 2020 fedora.png
rwxrwxrwx 1 root root 4 GiB Thu Aug 12 15:53:00 2021 Fedora.tar
rwxrwxrwx 1 root root 787 B Mon Oct 19 15:09:44 2020 redhat.png
rwxrwxrwx 1 root root 838 B Thu Aug 12 16:04:09 2021 restore-wsl2-distros.ps1
rwxrwxrwx 1 root root 20 KiB Sun Jun 27 22:01:44 2021 settings.json
rwxrwxrwx 1 root root 560 B Mon Oct 19 15:11:24 2020 ubuntu.png
rwxrwxrwx 1 root root 12 GiB Thu Aug 12 15:51:57 2021 Ubuntu.tar
Move WSL to Another Location
Installing LxRunOffline [DEPRECATED with `wsl` replacing `lxrunoffline` functions]
- Install LxRunOffline via Choco (Package Manager for Windows)
## From within your Windows PowerShell running as Administrator
PS C:\WINDOWS\system32> choco install lxrunoffline
Chocolatey v0.10.15
Installing the following packages:
lxrunoffline
By installing you accept licenses for the packages.
Progress: Downloading lxrunoffline 3.5.0... 100%
lxrunoffline v3.5.0 [Approved]
lxrunoffline package files install completed. Performing other installation steps.
The package lxrunoffline wants to run 'chocolateyInstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): A
Progress: 100% - Running Microsoft.Dism.Commands.ImageObject
Downloading lxrunoffline
from 'https://github.com/DDoSolitary/LxRunOffline/releases/download/v3.5.0/LxRunOffline-v3.5.0-msvc.zip'
Progress: 100% - Completed download of C:\Users\kenfo\AppData\Local\Temp\lxrunoffline\3.5.0\LxRunOffline-v3.5.0-msvc.zip (2.54 MB).
Download of LxRunOffline-v3.5.0-msvc.zip (2.54 MB) completed.
Hashes match.
Extracting C:\Users\kenfo\AppData\Local\Temp\lxrunoffline\3.5.0\LxRunOffline-v3.5.0-msvc.zip to C:\tools\lxrunoffline...
C:\tools\lxrunoffline
PATH environment variable does not have C:\tools\lxrunoffline in it. Adding...
Environment Vars (like PATH) have changed. Close/reopen your shell to
see the changes (or in powershell/cmd.exe just type `refreshenv`).
The install of lxrunoffline was successful.
Software installed to 'C:\tools\lxrunoffline'
Chocolatey installed 1/1 packages.
See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
Listing WSL2 Distros using LxRunOffline [DEPRECATED with `wsl` replacing `lxrunoffline` functions]
- lxrunoffline list - List all the installed distros on your system.
## From within your Windows Command Prompt (cmd.exe)
Microsoft Windows [Version 10.0.19042.572]
(c) 2020 Microsoft Corporation. All rights reserved.
C:\Users\kenfo>lxrunoffline list
Ubuntu-20.04
C:\Users\kenfo>
Moving Distro Locations using LxRunOffline [DEPRECATED with `wsl` replacing `lxrunoffline` functions]
## From within Windows PowerShell as Administrator
wsl --shutdown
## From within the Windows Command Prommpt (cmd.exe)
lxrunoffline move -n Ubuntu-20.04 -d M:\Shared\WSL2\ubuntu .
Moving Distro Locations using wsl
- Example for moving from internal/default to M:\Shared\WSL\Ubuntu
## From within Windows PowerShell as Administrator
## Prep shared drive (used for backup, restore, and storage)
cd M:\Shared\
mkdir -p WSL2\Ubuntu
cd M:\Shared\WSL2\Ubuntu
## Export and Unregister (if desired) from WSL
wsl --export Ubuntu ubuntu.tar
wsl --unregister Ubuntu
## Import Distro Name to Target from Backup
wsl --import Ubuntu Ubuntu ubuntu.tar
- Move your distro to another drive. My distro name here is Ubuntu. I am moving it to M: drive and \Shared\WSL2 folder inside it. (This will take some time to complete, lxrunoffline doesn't provide feedback during the move.)
- You can use the same move command to move your distro from default location to a different location inside C Drive.