WSL2 (Windows Subsystem for Linux 2) is a powerful tool that allows you to run a Linux environment directly on your Windows computer. By default, WSL2 stores images and files on the C: drive. However, if you have limited space on your C: drive or prefer to store your images on a different disk, you can easily change the default disk that WSL2 uses.
Follow the steps below to change the default disk for storing WSL2 images:
- First, open the WSL2 terminal by searching for "WSL" in the Windows Start menu and selecting the "WSL" application.
- Once the terminal is open, you need to navigate to the WSL2 folder. Type the following command and press Enter:
cd /mnt/
This command will take you to the "mnt" folder, which is where the disks are mounted in WSL2.
- Next, you need to identify the disk you want to use for storing WSL2 images. You can use the "ls" command to list the available disks. Type the following command and press Enter:
ls
This will display a list of available disks. Look for the disk you want to use, such as "D:" or "E:", and remember its name.
- Now, you need to create a new folder on the chosen disk to store the WSL2 images. Type the following command, replacing "disk_name" with the name of your chosen disk:
sudo mkdir /mnt/disk_name/wsl
This command creates a new folder named "wsl" on the chosen disk.
- After creating the folder, you need to edit the WSL2 configuration file to point to the new folder. Type the following command to open the configuration file in the nano text editor:
sudo nano /etc/wsl.conf
This command opens the "wsl.conf" file in the nano text editor.
- Within the nano text editor, add the following lines to the file:
[wsl2]
root = /mnt/disk_name/wsl
Replace "disk_name" with the name of your chosen disk. This configuration tells WSL2 to use the new folder on the chosen disk as the default location for storing images.
- Once you have added the lines, press Ctrl+X to exit nano. Press Y to save the changes, and then press Enter to confirm the file name.
That's it! You have successfully changed the default disk that WSL2 uses to store images. From now on, any new images you create in WSL2 will be stored on the chosen disk.
Remember, if you ever want to change the default disk again, you can simply repeat these steps and choose a different disk.
| References |
|---|
| Microsoft Docs - WSL configuration file |
| https://docs.microsoft.com/en-us/windows/wsl/wsl-config#configure-global-options-with-wslconf |