2

I am using WSL 1. My WSL Ubuntu 18.04 rootfs (C:/Users/USERNAME/AppData/Local/Packages/CanonicalGroupLimited.UbuntuonWindows.../LocalState/rootfs/) size on my C: drive is very large due to duplicated data from a mounted disk drive (M:). I would like to remove the duplicated data without affecting the data that is on my M: drive and without adversely affecting my WSL setup. Ideally, I would also like to avoid duplicating the data to my C: drive in the future so I don't put the extra stress on the SSD.

enter image description here

I have tried to unmount the drive from within WSL using sudo umount /mnt/m, but it did not reduce the size of the rootfs on my C: drive. I am afraid of just deleting the data because it is highly recommended not to modify anything within that rootfs from Windows, and I don't want to mess up the WSL image or the data on my M: drive.

bhass1
  • 386

1 Answers1

3

TL;DR: You can safely reduce the size of a WSL instance's rootfs by deleting /mnt/<DRIVE_LETTER>/* from the WSL rootfs after unmounting the underlying disk from within WSL instance. In my case, my WSL instance had a lot of cached data from Windows' M: drive stored in /mnt/m. I cleaned it safely from within the WSL instance by:

sudo umount /mnt/m
rm -rf /mnt/m/*

If you are paranoid, first use mount from within your WSL instance to verify the drive you want to clean. Then after running the unmount command (sudo unmount /mnt/<DRIVE_LETTER>), run mount again and verify the drive no longer appears in the list. Then you can safely proceed to use rm -rf on the files from within the WSL instance to wipe the cached data without affecting the data on the underlying Windows disk.

---- My Findings ----

Looks like WSL 1 uses that rootfs folder as a data cache. I noticed after unmounting my M: drive from within WSL with sudo umount /mnt/m that some of the folders' permissions changed while others didn't (notice the color difference in the below image which was taken after unmounting /mnt/m). The folders whose permissions didn't change are the folders that were taking up space on my Windows' C: drive in that rootfs folder.

listing of /mnt/m after unmounting

My Dropbox folder contributed to 11 GB on my C: drive but takes up much more on my M: drive. Since I knew it was already backed-up on Dropbox's servers, I wiped it from within WSL 1 (after having unmounted /mnt/m from within WSL) with the following: rm -rf /mnt/m/Dropbox then checked and confirmed from Windows with WinDirStat that my C: drive gained 11 GB more free space while my M: drive's Dropbox folder was unaffected. I closed the WSL window and reopened it to trigger auto-mount of my drives. Then checked /mnt/m/Dropbox and it was there with everything again. I unmounted /mnt/m and proceeded to delete everything from within WSL with: rm -rf /mnt/m/*. I double checked my M drive again - all files still there. Then I double checked how WSL behaved by exiting and re-launching it. ls -la /mnt/m showed everything still there. Now my rootfs on C drive is very small... Nice!

listing of windirstat showing zero space used by /mnt/m

bhass1
  • 386