Support for vaults in Windows Subsystem for Linux (WSL)

I initially created an account just to +1 this feature request, however, there’s actually a relatively simple workaround we can do which does not involve complex scripts or rsync etc… If you’re in Windows 11 and using WSL2. We can use a bind mount!

My goal was to store my notes in /home/purplproto/OneDrive/Documents/Work Notes in WSL so I could have them backed up since I try to keep work and personal stuff separate where possible and all my work-related things are already in this WSL instance, so it just made sense to store my notes here as well.

Let’s get into the steps to achieve this.


Config

First, I’ll start with my system configuration because this matters. Running automount for fstab entries seems to be inconsistent across different versions of Windows and WSL.

  • OS: Windows 11 22H2
  • WSL version: 1.0.0.0
  • Distro: Ubuntu
  • Distro WSL version: 2

You can find your WSL version by running wsl --version and the WSL version your distro uses with wsl -l -v in cmd.

If your versions match here, or are higher, you should be able to safely move onto the setup section, or else keep reading this section first.

If your WSL version number is below 0.67.6, then you should update to the new Windows store release of WSL by opening cmd and running wsl --update (note this might only work on Win11, I can’t confirm this). After doing so, you’ll need to shutdown WSL, this can be done using wsl.exe --shutdown in cmd. We need this update so we can enable systemd, since the old method of enabling mountFsTab in the /etc/wsl.conf file no longer appears to work, at least when attempting to mount Windows directories with my current configuration.

Setup

  1. Launch a terminal with your distro.
  2. Execute sudo nano /etc/wsl.conf.
  3. Add the following to the file (note if the [boot] label already exists, then append systemd=true below it):
    [boot]
    systemd=true
    
  4. Write and close the file.
  5. Now it’s time to add your bind mounts, execute sudo nano /etc/fstab
  6. Add a new line and enter:
    <src> <dest> none defaults,bind,uid=1000,gid=1000,umask=022 0 0
    
    replacing <src> and <dest> with your chosen paths, for example, mine looks like this:
    /mnt/c/Users/PurplProto/Documents/Work\040Notes /home/purplproto/OneDrive/Documents/Work\040Notes none defaults,bind,uid=1000,gid=1000,umask=022 0 0
    
    The keen-eyed will notice the seemingly random \040 in Work\040Notes, this is for escaping spaces, if your paths have spaces in them you must replace spaces with \040.
  7. Write and close the fstab file.
  8. Terminate your distro by opening cmd and executing wsl --shutdown.
  9. Then reopen a terminal with your distro again.
  10. Execute ls -a on your folder, in my case ls -a "~/OneDrive/Documents/Work Notes" and you should see your .obsidian folder in there.

If you would like to add any more vaults, re-run steps 5 through 7 and then sudo mount -a which will mount them immediately. We only needed to restart on step 8 instead since we had updated the /etc/wsl.conf file.


Non-systemd method

Bind mounts should also be achievable on older WSL versions and possibly distros running under WSL1. If you for whatever reason are on those versions and can’t update, then you could try something like:

mount --bind "/mnt/c/Users/PurplProto/Documents/Work Notes" "/home/purplproto/OneDrive/Documents/Work Notes"

If this works for you, then you could just add that command to the bottom of your .bashrc file.


Hope this helps some folks :slightly_smiling_face:

5 Likes