Setup File Sharing (SMB) on OpenWrt with Samba4

Written by

in

Why I write this guide?

Well, there are 2 guides for Samba4 and Samba3 on the OpenWrt Wiki. Each of the guide is missing a “small” piece of information which makes beginner confused.

1.Storage

More information on how to setup the storage on OpenWrt available here.

  • USB Disk (USB stick/ USB to SATA adapter)
opkg update
opkg install kmod-usb-storage
opkg install kmod-usb-storage-uas
opkg install usbutils
lsusb -t
  • Native SATA/NVMe Disk

Usually there is no need to install driver

2. Check if device is detected

ls -l /dev/sd* => if using USB stick or HDD/SSD with SATA to USB adapter
ls -l /dev/nvm* => if using NVMe
opkg install block-mount
block info

3. Create a partition on the disk

For this video/tutorial, I use fdisk

opkg install fdisk
fdisk /dev/nvme0n1 (Replace by your NVMe SSD disk name)
fdisk /dev/sda1 (Replace by your USB/SSD/HDD disk name)

  • d => Delete partition
  • n => New partition
  • w => Write change to disk

4. Create a file system in the partition

This guide is only for ext4 file system. If you wish to use a different file system, please see the document.

opkg install e2fsprogs
opkg install kmod-fs-ext4
mkfs.ext4 /dev/sda1      => if you are using USB Stick/HDD/SSD
mkfs.ext4 /dev/nvme0n1    => if you are using NVMe

5. Auto mount the partition

It is easier to mount the partition using LuCI. See my video for more information. If you wish to do it with CLI, here is the commands

block detect | uci import fstab

uci set fstab.@mount[-1].enabled='1'
uci commit fstab

uci set fstab.@global[0].check_fs='1'
uci commit fstab

6. Install Samba4

opkg update && opkg install luci-app-samba4

Afer that, configure it with the the Web-UI. The Samba4 service should be automatically restart. If it doesn’t work, you can use

/etc/init.d/samba restart

7. Configure Samba Users

The username is stored in /etc/passwd file. To modify it, use VI or Nano

vi /etc/passwd

After that, insert this example line to end of the file. It will create a new username with the below information:

vantc:*:1000:65534:vantc:/var:/bin/false

Hint: Using the same username for Samba4 (OpenWrt) and Windows will cause some problems where you need to change some setting on Local Security Policy. If possible, please use a different username for Samba4 & Windows.

  • user in this example will be called ‘vantc’“ (this is the loginname you need to enter, when Windows pops up the authentication dialogue)
  • with the unique system ID ‘1000’
  • with the group id ‘65534’ (which is the group identifier for ‘nobody’= no special default group)
  • ‘/var’ just means the user will not need a special home folder on the system
  • ‘/bin/false’ means the user will not have a default shell program associated

smbpasswd -a vantc => Set password
service samba restart (Optional)

8.Troubleshoot – No Write Access

  • Modifying the permissions and owner of the folder

If you are using USB stick/ HDD/ SSD

chmod -R 777 /mnt/sda1
chown -R nobody /mnt/sda1

If you are using NVMe

chmod -R 777 /mnt/nvme0n1
chown -R nobody /mnt/nvme0n1

More info: https://openwrt.org/docs/guide-user/services/nas/cifs.server#cannot_write_to_a_samba_share

9. Fine-Tune & others

  • Since netfilter tracks every connection, it may improve throughput to disable conntrack for Samba connections if you use NAT.
    https://openwrt.org/docs/guide-user/services/nas/cifs.server#throughput
  • Remote Access
    Doable, not recommended. You better setup Wireguard VPN to access the NAS locally.
  • Apple Discovery & Network Discovery

10. Enjoy your OpenWrt NAS

Have fun with your OpenWrt NAS.

If you enjoy my content, feel free to give it a like, leave a comment, subscribe to the channel, give me a Super Thanks or support me on Patreon. I will be happy regardless of the action!

Comments

11 responses to “Setup File Sharing (SMB) on OpenWrt with Samba4”

  1. Braulio Avatar
    Braulio

    Lo Instales en WRT3200ACM, Necesito Instalar, Asterisk, Dockers, MariaDB.
    SALUDOS, siempre sigo tus videos de enseñanza.

  2. Harlow Bernard Avatar

    We just wanted to take a moment to acknowledge all the hard work and effort you’ve been putting in lately. Keep up the amazing job, you’re doing great!

  3. Vincent Avatar
    Vincent

    Perfect guide, every step of the way.

  4. tom Avatar
    tom

    Yet another nonworking guide. Did you even read your tutorial?
    Are you really want to help somebody, or just need to generate some content?
    In step 5 you are referring to your video. Which video. Where I can find it? On your YT channel? No success and I won’t watch all 200+ videos you made.
    /etc/init.d/samba restart? Really? Didn’t you install samba4 ? Why to try restarting samba? I found only samba4 in the initd.d.
    I followed all your instructions with no success.
    Another wasted time.

    1. Van Avatar
      Van

      Hello, did you read the whole guide, or just copy & paste?

      Step 5 is about mounting the partition, and step 6 show you how to install samba4 (again, samba4 is a dependencies luci-app-samba4 and it will be automatically installed if you install luci-app-samba4).

      Well, if you read it carefully “The Samba4 service should be automatically restart. If it doesn’t work, you can use the /etc/init.d/samba restart to restart it”

  5. Hoops Avatar
    Hoops

    Your tutorials are very informative. Can you do one on accessing Samba via a wireguard tunnel

  6. TimboSlice Avatar
    TimboSlice

    How are you getting these speeds? For whatever reason, I cannot get ANY (Lexar 128gb flashdrive, Samsung 1 TB T5 ssd, and a Seagate 22TB hdd) to connect via the USB3.0 port at SuperSpeed (usb3.0). I constantly am stuck at hispeed. In the GLI gui, the USB protocol switch only shows my drives when it’s on usb 2.0.

    however in a terminal, lsusb -t shows:

    /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
    /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 480M

    1. Van Avatar
      Van

      May I know what is your host device (router) you are using?

  7. mrtn Avatar
    mrtn

    “/etc/init.d/samba restart” returns “-ash: /etc/init.d/samba: not found”

    1. Van Avatar

      It looks like the samba package is not installed. Can you check this?

  8. Jamaludin Avatar
    Jamaludin

    Thank you and I appreciate your effort and sharing useful knowledge.
    👍

Leave a Reply

Your email address will not be published. Required fields are marked *