3

I am using both Cygwin and WSL (Ubuntu) on Windows. I ran a command that created a file in Cygwin, and then when I view the same file in WSL, it says that I own it and the directory containing it, and that I have all permissions to it. However, when I try to delete it, I get permission denied

> sudo rm file1.txt
rm: cannot remove 'file1.txt': Permission denied
> whoami
jeff
> ls -la
total 4
drwxrwxrwx 1 jeff jeff 512 Dec  1 14:55 .
drwxrwxrwx 1 jeff jeff 512 Dec  1 14:55 ..
-rwxrwxrwx 0 jeff jeff 999 Dec  1 14:40 file1.txt
> cd ..
> ls -la
total 0
drwxrwxrwx 1 jeff jeff 512 Dec  1 14:55 .
drwxrwxrwx 1 jeff jeff 512 Dec  1 14:55 ..
drwxrwxrwx 1 jeff jeff 512 Dec  1 14:55 folder1

I have tried running rm with and without sudo, removing the containing folder, and disowning then owning the file and parent folder again, what else can I try, assuming that using Cygwin or Windows to remove the file is not an option?

14
  • @Ramhound so what can I do? as far as I can tell, WSL is telling me that I already have all the permissions I need
    – Jeffmagma
    Commented Dec 1, 2021 at 23:17
  • Cygwin is not actually Linux. Its simply a POSIX compatible environment while WSL is actually Linux. Where exactly is this file? Only Windows understands the files contained within the WSL instance.
    – Ramhound
    Commented Dec 1, 2021 at 23:19
  • @Ramhound It's near the WSL home directory, equivalent to C:/wsl/rootfs/home/test/folder1/file1.txt and ~/test/folder1/file.txt
    – Jeffmagma
    Commented Dec 1, 2021 at 23:28
  • and where are you attempting to access them from within Cygwin, since that directory, does not exist outside of WSL. I wanted specifics
    – Ramhound
    Commented Dec 1, 2021 at 23:32
  • I can access it in Cygwin through /cygdrive/c/wsl/rootfs/home/test/folder1/file1.txt
    – Jeffmagma
    Commented Dec 1, 2021 at 23:38

1 Answer 1

1

The information in the comments shows a potentially major problem. For starters, please remember to edit your question with the information you provided in the comments. That's critical information to anyone understanding your issue that should be a part of the question, rather than the comments. (Feel free to edit this answer to remove the italicized area once the question has been updated).

Now on to the likely problem ...

Danger! Danger! As @Jeffmagma said in the comments, this doesn't look like WSL2. Since the file is exposed in C:\wsl\rootfs (visible to Cygwin at /cygdrive/c/wsl/rootfs), that looks to be a WSL1 filesystem rather than a WSL2 virtual drive (which would show up as an ext4.vhdx).

And that falls into this Microsoft Warning:

There is one hard-and-fast rule when it comes to WSL on Windows:

DO NOT, under ANY circumstances, access, create, and/or modify Linux files inside of your %LOCALAPPDATA% folder using Windows apps, tools, scripts, consoles, etc.

Creating/changing Linux files in your Appdata folder from Windows will likely result in data corruption and/or damage your Linux environment requiring you to uninstall & reinstall your distro!

... which is actually a bit poorly worded. It references "AppData", but that's the default location for WSL installations.

In this case, it looks like you've created a WSL1 instance at C:\WSL. There's nothing at all wrong with that, but Microsoft's warning still applies. Attempting to create, update, or delete a file using a Windows application (e.g. Cygwin) in that path is almost certain to cause issues.

And unfortunately it sounds like it may very well have caused filesystem corruption in this case.

To attempt recovery, I would try:

  • Another wsl --export of this WSL1 instance
  • Then wsl --import it into a new instance. I'm assuming you are familiar with this process since it's likely what you used to create the instance at C:\wsl\ in the first place. I would add --version 2 to the end of the --import command, personally.
  • See if (a) the problem-file exists in the new instance (it may be culled by the export, actually), and (b) if it does exist, see if you can delete it.
1
  • 1
    I don't know my root cause, and wouldn't recommend, but I ended up here with a similar issue on a WSL1 distro, and the only way I could delete it WAS in the windows rootfs. Deleting it there removed it from WSL. This was preventing a wsl --export
    – MattH
    Commented Sep 3, 2022 at 22:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .