Setup Network Share (Home/Media Server) on OpenWrt using Samba & USB Drive | Detailed Tutorial

Learn how you can setup a home Samba Server (Network Share) on your OpenWrt device using a USB drive using this step-by-step tutorial.

Does your household or office have multiple computers, sharing files using removable USB devices? Let’s ditch the ancient methods of our ancestors and make a very affordable move to our very own Home/Media Server on OpenWrt. You can very easily setup a Network Share Drive on your OpenWrt router/device. With this setup, every device connected to your network (Android, Windows, Mac, Linux, etc.) will be able to access files stored on the USB drive connected to OpenWrt.

This step-by-step tutorial, based on the original documentation, explains the process of setting up a Samba server on OpenWrt. Since this isn’t a very CPU intensive process, you can try this on almost any router supporting OpenWrt.

If interested, also check out how you can setup your own Jellyfin Media Server on OpenWrt.

Video Tutorial: Setup Samba Server (Network Share) on OpenWrt

For the textual tutorial, keep reading.

How to Setup Samba Server (Home/Media Server) on OpenWrt?

As always, let’s begin with the requirements.

Requirements

Once you have these ready, just jump into the steps below.

Step 1. Install Samba server and dependencies on OpenWrt

  1. Go to terminal/SSH (via Putty) and login to your router as root.
  2. Type opkg update and press Enter.
  3. To install the packages necessary for Samba to run, type opkg install kmod-usb2 kmod-usb-storage-uas usbutils block-mount mount-utils luci-app-hd-idle and press Enter. If your device has a USB 3.0 port, replace kmod-usb2 with kmod-usb3. Some of these packages might already be installed on your device.
  4. Depending on your preferred USB partition format, install the necessary packages. For example, if you want Ext4, exFAT and NTFS to be supported, type opkg install kmod-fs-ext4 kmod-fs-exfat kmod-fs-ntfs3 and press Enter. In this tutorial, we will setup an Ext4 partition on our USB drive. So, I will only install that using the command – opkg install kmod-fs-ext4. You may choose the other formats.
  5. Finally, to install Samba, type opkg install luci-app-samba4 and press Enter.

Step 2. Setup Samba user for security

While you can always use root to access the network share, it is not recommended. Let us check out the steps to setup a non-root user for our Samba drive.

  1. To edit files easier, type opkg install nano and press Enter.
  2. Type nano /etc/passwd and press Enter. This will open the file passwd in Nano text editor. Go to the last line and type noob404:x:1001:1001:smb user:/dev/null:/bin/false. Here, replace noob404 with your preferred username. Also, go through the file and see if 1001 is already used. If used, go for the next number, for example, 1002. When done, press Ctrl + S and then Ctrl + X to save and exit.
  3. Type nano /etc/group and press Enter. This will open the file group in Nano text editor. Go to the last line and type noob404:x:1001:noob404. Here, replace noob404 with your preferred username (supplied in earlier step). Also, replace 1001 if any change was made in the earlier step. When done, press Ctrl + S and then Ctrl + X to save and exit.
  4. Now, type smbpasswd -a noob404, replacing noob404 with your username. Then, press Enter. Enter a secure password and press Enter. Again, enter the password and press Enter to confirm. We will need this password to access the network drive.

Step 3. Format and partition USB drive for Samba

To format the USB drive, you can either use the OpenWrt router or a machine running Linux or even Windows (eg.- exFAT), depending on the format you plan on using. Here are the sample steps to make an Ext4 partition on USB drive using OpenWrt. For Linux, here are the steps. Feel free to use GUI-based partition managers for this, as well, for example, GParted Live. As mentioned above, in this tutorial, I will be setting up an Ext4 partition.

Also keep in mind that if you are already using Extroot and only have a single USB port on the OpenWrt device, you have two options:-

  • Add another partition to the Extroot USB drive by shrinking the Extroot partition.
  • Use a USB hub to add another drive (not recommended).

Once that’s done, move on to the next step.

Step 4. Setup Samba Network Share on OpenWrt

  1. Login to OpenWrt Admin GUI (Luci) and plug your prepared USB drive into the OpenWrt device.
  2. Go to SystemMount Points.
  3. Under Mounted file systems, check if your USB drive is already mounted. If not automatically mounted, check for the drive under Mount Points, check the tick labelled Enabled alongside it, then click Save & Apply. Then, on the top of this page, check on the tick labelled Automount Filesystem and then click on Save & Apply. When done, make a note of the Mount Point of the drive. It should be /mnt/sda1, if only one USB drive is plugged into the device.
  4. Next, go to ServicesNetwork Shares. Make sure Interface is set according to your internet connections. You may leave the other settings to default. Under Shared Directories, set the following:-
    • Name: Set up a preferred folder name, for example, mydrive. A virtual directory by that name will be visible when you access the network drive.
    • Path: Provide the Mount Point here, for example, /mnt/sda1.
    • Allowed users: Provide the username that you setup in Step 2 above, for example, noob404.
    • Allow guests: It is recommended to uncheck it.
    • Other settings may be left unchanged.
  5. Click on Save & Apply.

That’s it! You have successfully setup Network share on OpenWrt using a USB drive.

How to access Samba Network drive setup on OpenWrt?

There are multiple ways to access this drive on various devices. Here’s a quick look at the steps to set it up on various OSes.

Access Network Drive on Windows

  1. Connect to the router’s network.
  2. Open Windows File Explorer.
  3. On address bar, type \\192.168.1.1 and press Enter. Do replace the IP with that of your OpenWrt router/device.
  4. When prompted for username and password, provide the ones setup in Step 2.

Access Network Drive on Android

Using File Manager

For this, you might need a 3rd party file manager supporting network folder, for example, EX File Manager. Once installed, follow these steps:-

  1. Connect to your Router’s network via WiFi or otherwise.
  2. Under LAN on EX File Manager, you will find your network drive. Click on it and login using credentials setup in Step 2.

Using Media Player

You can use VLC for Android to play the media files (videos, audio, etc.) on the Samba drive. Once installed, follow these steps:-

  1. Connect to your Router’s network via WiFi or otherwise.
  2. On VLC, find your network drive under Local Network, click on it and login using credentials setup in Step 2.

Access Network Drive on Linux

The steps are almost similar on every distro. I will explain the easiest way to do this here, but, remember, you can also do this using terminal-based applications.

  1. Install Nautilus File Manager for your distro and open it.
  2. Connect to your Router’s network.
  3. Click on Other Locations. Find your network drive and click on it and login using credentials setup in Step 2.

Troubleshooting: Samba Network Share on OpenWrt

Permission error when writing files

If you face issues when writing (copying, deleting, etc.) files, this is because proper permissions haven’t been applied. To fix this, follow these steps:-

  1. Login to SSH as root.
  2. Type chmod -R 777 /mnt/sda1 and press Enter. Replace /mnt/sda1 with your network share directory or partition.

Conclusion

With this, file sharing over devices connected to the same network in a home or office environment becomes extremely easy. This is a very good affordable alternative for people looking for small-scale home/media servers.

Be the first to comment

Leave a Reply

Your email address will not be published.


*