8

Just for curiosity, what will happen after you run sudo rm -rf /mnt/c/* in WSL (Windows Subsystem for Linux)? Will it remove whole C drive in my computer? Will WSL keep working or not? If sudo rm -rf /*, will it remove the /mnt folder?

2 Answers 2

15

Being root inside WSL does not make you an admin on Windows. So no, it will not remove the entirety of C:. It may however delete enough shared files and/or your stuff in your user profile to do quite some damage. You can still delete a lot there.

It could make it so you either can no longer log in or some of the software you installed fails.

Here’s what happens with protected files:

daniel@db-d-18:/mnt/c/Program Files/Firefox Developer Edition$ sudo rm install.log
rm: cannot remove 'install.log': Permission denied

You totally can destroy your WSL distribution this way of course.

9

what will happend after you run sudo rm -rf /mnt/c/* in wsl

if sudo rm -rf /* will it remove /mnt folder

Both are similar scenarios.

No, it won't remove the whole drive, but it will still do substantial damage (as @DanielB points out as well). See (and pity) this question on Ask Ubuntu, where the user accidentally did exactly what you are asking.

I started getting all sorts of other errors from Windows

Now everything is working weird even in Windows ... too much has been damaged.

While files in C:\Windows would be protected against deletion, those in %userprofile% (C:\Users\<youruser>) would not, including:

  • Local and remote settings for most installed applications, including:

    • Your Start menu (%appdata%\Microsoft\Windows\Start Menu)
    • Your browser settings, cookies, saved passwords, etc.
    • Ironically, your WSL distributions that were installed from the Store (%localappdata%\Packages\<distro_package\)
    • Your desktop.
    • Etc. etc. etc.
  • Documents, Pictures, Downloads, Music, etc.

  • Files stored on OneDrive, typically at %userprofile%\OneDrive. Note that the files that are deleted here would go to the OneDrive Recycle Bin, unlike normal files deleted through WSL.

In short, it would be catastrophic. Windows should still be bootable, but you would need to create a new user to recover.

However, if you were running WSL in UAC elevated (Admin) console, then the damage would be even worse. It still wouldn't be able to remove in-use files, but it would wipe away enough of /mnt/c/Windows/C:\Windows to make it unbootable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.