Score:1

Cannot delete a file on WSL Ubuntu 20.02.2

ru flag

This is probably cause by closing the WSL when delete process not complete. And now I want to delete this file.


ls -lba output this

root@A12581:/HelloWorld/android-kernel/.repo/projects/prebuilts/boot-artifacts.git# ls -lba
ls: cannot access '.repo_config.json': No such file or directory
total 0
drwxr-xr-x 1 root root 4096 Jan 28 09:27 .
drwxr-xr-x 1 root root 4096 Jan 27 15:56 ..
-????????? ? ?    ?       ?            ? .repo_config.json

but I'm unable to delete this file / delete the folder contain this file / rename the folder contain this file


my environment :

WSL1

Ubuntu 20.04.2 LTS

in flag
This is usually a sign of file system corruption. Unfortunately, WSL1 does not have a mechanism to repair its file indices. You may want to do yourself a favour and rebuild the container ... perhaps with WSL2.
Nate T avatar
it flag
The error message is saying that the file does not exist. Check to make sure that the path exists and that it is inside your wsl file system. You most likely either had a typo in the file pathname, or else the file is outside of the WSL filesystem (e.g. it is on your Windows drive). Remember, wsl acts on resources on the wsl filesystem, which is usually created alongside your C drive, and often on a completely different drive..
NotTheDr01ds avatar
vn flag
Did you ever make any progress on this? A similar issue popped up today on the Unix & Linux Stack.
user16387400 avatar
ru flag
@NotTheDr01ds sorry to say, but it seems there's no other way except to take a backup and re-install entire system
Score:0
vn flag

@matigo is probably correct with the comment regarding filesystem corruption. I also agree that the WSL2 use of ext4 is almost certainly more robust if it fits your needs.

If you haven't already, do a wsl --shutdown (from PowerShell) to make sure any handles/locks are released. Then restart and try again. It has a relatively small chance of working, but it's worth a shot since it's so quick.

If that doesn't work, I'd recommend the following for attempting to repair the WSL1 instance.

Basically round-trip the WSL1 instance through a wsl --export/wsl --import. The tar round-trip that this process performs should (hopefully) remove the corrupted file when archiving or unarchiving, one or the other.

From PowerShell:

# Confirm the distribution name
wsl -l -v
# Distribution name may be "Ubuntu" or "Ubuntu-20.04" - Adjust the following lines accordingly:
wsl --shutdown
cd ~\Documents
mkdir WSL\images
mkdir WSL\instances\UbuntuRecovery
wsl --export Ubuntu WSL\images\ubuntu.tar
wsl --import UbuntuRecovery WSL\instances\UbuntuRecovery WSL\images\ubuntu.tar --version 1
wsl -d UbuntuRecovery

See if the file is gone or deletable in that new instance.

If so, and if everything else looks okay in the new instance, then:

  • Set the default username in that instance via a /etc/wsl.conf file per this answer.
  • Exit the instance
  • Again, from PowerShell:
    wsl --terminate UbuntuRecovery
    wsl --set-default UbuntuRecovery
    

The new instance will be the default whenever wsl is run.

Finally, remove the original corrupted instance with:

wsl --unregister Ubuntu

Important: This is a destructive operation. Make sure that everything is working as intended. On the bright side, we've made a backup already ...

You can also uninstall the Ubuntu "App" that was installed from the Store at that point.

You'll launch via wsl (if you haven't been already) or Windows Terminal since the ubuntu.exe (or ubuntu2004.exe) command will be gone.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.