OneDrive is a popular cloud storage service offered by Microsoft. It allows users to store and access their files from anywhere and on any device. However, if you are using WSL2 (Windows Subsystem for Linux), you may notice that it takes up a significant amount of space on your OneDrive. In this step-by-step guide, we will show you how to free up space on OneDrive from WSL2.
Step 1: Open WSL2
The first step is to open WSL2 on your Windows computer. You can do this by searching for "WSL" in the Windows search bar and selecting "WSL" from the search results. This will open the WSL2 terminal.
Step 2: Navigate to the OneDrive Folder
Once you have the WSL2 terminal open, you need to navigate to the OneDrive folder. By default, the OneDrive folder is located at /mnt/c/Users/YourUsername/OneDrive. Replace "YourUsername" with your actual Windows username.
To navigate to the OneDrive folder, use the following command:
cd /mnt/c/Users/YourUsername/OneDrive
Step 3: List the Contents of the OneDrive Folder
Next, you should list the contents of the OneDrive folder to see what is taking up space. Use the following command to do this:
ls -lh
This command will list the files and directories in the OneDrive folder, along with their sizes.
Step 4: Identify the WSL2 Files and Directories
In the list of contents from the previous step, you need to identify the files and directories that belong to WSL2. These files and directories typically have names starting with "ext4.vhdx" or "ext4.vhdx.log".
Make a note of these files and directories, as you will need to delete them in the next step.
Step 5: Delete the WSL2 Files and Directories
Now that you have identified the WSL2 files and directories, it's time to delete them to free up space on OneDrive. Use the following command to delete a file or directory:
rm -rf FileNameOrDirectoryName
Replace "FileNameOrDirectoryName" with the actual name of the file or directory you want to delete. For example, if you want to delete a file called "ext4.vhdx", the command would be:
rm -rf ext4.vhdx
Repeat this command for each WSL2 file or directory you want to delete.
Step 6: Verify the Space Freed Up
Once you have deleted the WSL2 files and directories, you should verify that the space has been freed up on OneDrive. You can do this by checking the available space on your OneDrive account.
Step 7: Configure WSL2 to Save Files Elsewhere
If you want to prevent WSL2 from saving files on OneDrive in the future, you can configure it to save files elsewhere. To do this, you need to edit the WSL configuration file.
Open the WSL configuration file using the following command:
sudo nano /etc/wsl.conf
Add the following lines to the file:
[automount]
root = /
options = "metadata,umask=22,fmask=11"
mountFsTab = false
Save the file and exit the text editor.
Step 8: Restart WSL2
Finally, you need to restart WSL2 for the changes to take effect. You can do this by closing the WSL2 terminal and opening it again.
After restarting WSL2, any new files created by WSL2 will be saved outside of the OneDrive folder.
By following these steps, you can free up space on OneDrive from WSL2 and prevent it from using up your cloud storage in the future. Remember to regularly check your OneDrive folder and delete any unnecessary files to keep your storage space optimized.
References
| [1] | Microsoft WSL Documentation |
| [2] | OneDrive Video Training |
| [3] | How-To Geek: How to Access Your Linux (WSL) Files in Windows 10 |