A quick tip!

I just reinstalled Ubuntu WSL on my freshly-formatted laptop. Everything seemed to be working properly but I ran into an annoying problem cloning one of my git repository:

Cloning into 'alessandrococco.gitlab.io'
error: chmod on /mnt/c/Users/alessandro/Projects/alessandrococco.gitlab.io/.git/config.lock failed: Operation not permitted
fatal: could not set 'core.filemode' to 'false'

It’s weird because it’s the thousandth time that I’ve done it and this is the first time I’ve come across this error!

The problem here is that the content of /mnt/c is located on a NTFS partition so chmod doesn’t work.

After some digging in the Microsoft documentation I found a simple solution to this:

  1. Launch Ubuntu WSL
  2. Create the file /etc/wsl.conf if it doesn’t exist
  3. Open the file (e.g.: nano /etc/wsl.conf) and add the following lines:
    [automount]
    options = "metadata"
    
  4. Save the file and shutdown WSL launching wsl --shutdown from a PowerShell
  5. Relaunch Ubuntu WSL

The metadata option allows Windows to support Linux system permissions: now all chmod/chown-related stuff will work correctly!