1

How can I connect to a SMB share from Ubuntu running in Windows Subsystem for Linux (WSL)?

This took me a while to sift through, a lot of questions and answers have been posted throughout the years, and some put me on the right track, but it still took me more than a day to do it.

First here is my setup:

Client: Windows 10 Home 20H2 19042.804 | Ubuntu for WSL 20.04.2 LTS build 20210222
Server: FreeBSD 12.1-RELEASE
Network: Class C

Purpose

Briefly, my purpose was to have a unified home directory across my various accounts on my machines, and virtual machines.

So in more words, this is quite a very simple setup, but my purpose was to have a single home directory across all my machines. So right now, my home directory on my Windows machine is the same as my home directory on my FreeBSD server, and now, finally, also on my Linux account on Ubuntu for WSL.

The advantages of this should be obvious: it's just a lot more comfortable to work. I also have this file manager called CX File Manager on my Android phone that can connect to my NFS share, so putting all my pictures and videos on my server when my phone gets full is a breeze! I just move the DCIM folder to the SMB share, and it does it in the background while I sleep, or whatever.

Method

Some of you might be drooling already, so here's how.

  1. Your NFS share has to be added to your Windows account as a drive. You go in the File Explorer > Map Network Drive > Enter the information, assign a drive letter. Mine is Z: for my personal home directory.

  2. Then you add this line to /etc/fstab in Ubuntu for WSL

    //192.168.0.110/ /home/ drvfs auto,rw,nosuid,exec,uid=<1000>,gid=<1000> 0 0

Of course, you'll want to plug in the right names, the UID/GID of your user on your server, and make sure it fits your requirements, but that's essentially it!

Explanation

Because Ubuntu for Linux doesn't support CIFS, you need to use drvfs instead of mounting your share directly from Ubuntu. You can also specify the drive letter instead of the SMB share name (Z: instead of 192.168.0.110), but that makes so you can't use the drive in Windows anymore, Ubuntu takes sole control of the drive, and it shows as being disconnected in Windows, so that wasn't extremely useful.

It shouldn't work

This isn't backed-up by any documentation, but your credentials are already stored in Windows. As we saw, you could specify your Windows drive letter instead of the share name, and it would kinda work, but Windows would see the drive as busy, however we know drvfs is "using those credentials", or at least it's mounting through the Windows SMB share that's already connected with your credentials. Somehow, specifyinng the share name instead of the drive letter allows us to use the drive in both WSL, and Windows, at the same time.

I've just managed to get this to work, I've not seen any conflicts, sync problems, etc. but if you're not too hard on it, it should work just fine. Most code editors recognize external changes to files anymore, now, anyway, and that's probably what's going to be happening with it. I just tested with vi, and it said the file was modified, Windows saw the file on the share right away... Looks like it's working pretty solid.

1 Answer 1

0

Method

This is in the text above, but some of you might be drooling already, so here's how.

  1. Your NFS share has to be added to your Windows account as a drive. You go in the File Explorer > Map Network Drive > Enter the information, assign a drive letter. Mine is Z: for my personal home directory.

  2. Then you add this line to /etc/fstab in Ubuntu for WSL

    //192.168.0.110/ /home/ drvfs auto,rw,nosuid,exec,uid=<1000>,gid=<1000> 0 0

Of course, you'll want to plug in the right names, the UID/GID of your user on your server, and make sure it fits your requirements, but that's essentially it!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .