Skip to content

Instantly share code, notes, and snippets.

@sgtoj
Last active January 29, 2024 06:11
Show Gist options
  • Star 35 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save sgtoj/f82990bcd9e89db49b84e2d2e70b281d to your computer and use it in GitHub Desktop.
Save sgtoj/f82990bcd9e89db49b84e2d2e70b281d to your computer and use it in GitHub Desktop.
Ubuntu for Windows: Mounting C: Drive to WSL's Root
# allow `mount` cmd without password
echo "$USER ALL=NOPASSWD: /bin/mount" | (sudo su -c 'EDITOR="tee -a" visudo')
# add the mount directive to `fstab`
sudo mkdir -p /c
sudo sh -c "echo '/mnt/c /c none bind' >> /etc/fstab"
# update to `.bashrc` to auto mount at login
echo "sudo mount -a" >> ~/.bashrc
# now reload it
source ~/.bashrc
@ndotb
Copy link

ndotb commented May 4, 2018

This is awesome. Thank you.

@llinfeng
Copy link

llinfeng commented Oct 3, 2018

Changing the settings in wsl.conf would need a system-reboot to take effect. (On Windows 10, this means you need to restart the laptop as a whole.)

@alexjmoore
Copy link

alexjmoore commented Jan 24, 2019

Actually you don't need a full restart, you can just restart the WSL management service with (for example) this PowerShell:

Restart-Service -Name "LxssManager"

@ertwro
Copy link

ertwro commented Mar 7, 2019

Hi. In my case it creates the folders but the mount points remain the same. My wsl.conf is exactly the same but when i do mount -l | grep drvfs I get.

C: on /mnt/c type drvfs (rw,noatime,uid=1000,gid=998,case=off)
D: on /mnt/d type drvfs (rw,noatime,uid=1000,gid=998,case=off)
E: on /mnt/e type drvfs (rw,noatime,uid=1000,gid=998,case=off)
F: on /mnt/f type drvfs (rw,noatime,uid=1000,gid=998,case=off)
G: on /mnt/g type drvfs (rw,noatime,uid=1000,gid=998,case=off)
H: on /mnt/h type drvfs (rw,noatime,uid=1000,gid=998,case=off)

I've restarted the service and the PC but remain the same.

@deserthacker
Copy link

Same here, duplicated the wsl.conf, restarted no-joy. running 18.03

@sgtoj
Copy link
Author

sgtoj commented Apr 1, 2019

@deserthacker

Check the line endings of wsl.conf? I am now using the new method without issue.

@AvMu
Copy link

AvMu commented Jun 12, 2019

works fine on 18.04.2 WSL windows 10 pro. but I see /mnt/c as empty directories

@aXe1
Copy link

aXe1 commented Jan 28, 2020

works fine on 18.04.2 WSL windows 10 pro. but I see /mnt/c as empty directories

Had the same problem. It gone when changed root property in automount section to /mnt/ (from just /).

@fractalspace
Copy link

FYI this is now possible to do it with wsl.conf https://docs.microsoft.com/en-us/windows/wsl/wsl-config
root = /

diego@diego-thinkpad:~$ cat /etc/wsl.conf
# Enable extra metadata options by default
[automount]
enabled = true
root = /
options = "metadata,umask=22,fmask=11"
mountFsTab = false

# Enable DNS – even though these are turned on by default, we’ll specify here just to be explicit.
[network]
generateHosts = true
generateResolvConf = true

diego@diego-thinkpad:~$ mount -l | grep drvfs
C: on /c type drvfs (rw,noatime,uid=1000,gid=1000,umask=22,fmask=11,metadata)
diego@diego-thinkpad:~$

Works for me (wsl 1, Win 10 pro, Version 10.0.18363.1500, Ubuntu 20.04.2 LTS)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment