How would I move the ext4.vhdx from my C drive to a different drive? #8637
|
My C drive is getting a bit full, I'd like to move the nearly 40 GB that my Debian distro is taking up on my C drive and move it to a different drive with a bit more space on it. |
Replies: 4 comments 1 reply
|
From PowerShell (normal user, not Administrator): # Modify variables below as needed/desired
$WSL_ROOT="D:\WSL"
$WSL_IMAGE_PATH="${WSL_ROOT}\images"
$WSL_OLD_DISTRO_NAME="Debian"
$WSL_NEW_DISTRO_NAME="Debian_WSL2"
$WSL_INSTANCE_PATH="${WSL_ROOT}\instances\${WSL_NEW_DISTRO_NAME"
mkdir $WSL_IMAGE_PATH
mkdir $WSL_INSTANCE_PATH
# Create a backup/export of the existing Debian in `D:\WSL\images\Debian.backup.tar`
wsl --shutdown
wsl --export $WSL_OLD_DISTRO_NAME "${WSL_IMAGE_PATH}\${WSL_OLD_DISTRO_NAME}.backup.tar"
# Import that backup into the new location/distribution:
wsl --import $WSL_NEW_DISTRO_NAME $WSL_INSTANCE_PATH "${WSL_IMAGE_PATH}\${WSL_OLD_DISTRO_NAME}.backup.tar" --version 2
# Start the new distro:
wsl ~ -d $WSL_NEW_DISTRO_NAMEFrom inside the new Debian distro: sudo -e /etc/wsl.conf
# Yes, you are already root, but `sudo -e` is just a fairly safe way to invoke the default editor regardless of distributionAdd the following: [user]
default=<your_normal_username>Save and exit the editor
Back in the same PowerShell session (so all the variables are still intact): You should now be running as your normal user in the new Debian location. To confirm, ... will show the installed distributions and their locations. After confirming that everything is working properly: Warning: This is a destructive and unrecoverable operation You can also uninstall the Debian app from the Store as well, but I personally recommend keeping it around. Having it still installed means that you can quickly spin up a new Debian to "test something out" with: Set the username/password, to throw it away. |
|
Hi, We know how to export the distribution and how to then move it to another drive and registrer it again. However, this method is error prone. Why? Because a lot of circunstances can fail in the exporting procedure. Futhermore, the registering again can produce some troubles. So, why not provide a simple and direct method to a simple move command? Like So, please consider it. |
|
It's as simple as shutting down the WSL distro, moving the ext4.vhdx file, and changing the BasePath to the new directory. There's no need to export, import, or unregister. However, a --move command that performs these steps would be a nice addition. Fiddling with the registry is always a bit delicate. |
|
Hi xoxo (@go-xoxo) ,
The "BasePath" is stored in the Registry. So the only method to move the ext4.vhdx file is editing the info inside the registry. Therefore, I hope the developers will add the method |
From PowerShell (normal user, not Administrator):