WSL Ubuntu Distro | How to solve `Operation not permitted` on cloning repository
I had the same issue. Try this:
sudo umount /mnt/c
sudo mount -t drvfs C: /mnt/c -o metadata
Change the drive letter to whatever one you're having the issue with.
You can automatically mount your Windows drives under WSL with the metadata option that allows apps, like git, to use chmod and fix this issue.
Edit /etc/wsl.conf
(create it if it doesn't exist).
Add the following:
[automount]
options = "metadata"
Then either:
- Reboot Windows
- Exit any WSL sessions, run
wsl --shutdown
from PowerShell or CMD, and start WSL again - Exit your only session, terminate it with
wsl --terminate <distroName>
, and start it again,
Then never worry about it again.
/mnt/c/Users/...
is on the Windows NTFS partition itself, and not within the WSL's ext4
formatted system. Therefore you have to treat it as you would an NTFS partition on a USB stick on an actual Ubuntu installation, and accept the limitations of NTFS.
NTFS partitions do not support chmod
or similar Linux permissions commands, and unlike in actual Ubuntu instalations which don't error but don't make any permissions changes, WSL doesn't relay this information back to you, it simply errors out as you see here.
You cannot do a git clone
sanely into the /mnt/c/...
space within WSL because of the Linux permission schemas and chmod
not working right. This is a limitation of WSL in its current form.
I was having the same issue. My solution is to git clone my repo in the default WSL location (it works), and use Visual Studio Code to remote access my WSL's repos. That way you won't have to use /mnt/c at all.
Links: https://code.visualstudio.com/docs/remote/wsl