[Setup USB drive and SAMBA/NAS on OpenWrt from scratch
]After flashing the TP-LINK 703N router from U-boot failsafe webserver, you are having a brand new router. Software need to be installed to perform certain tasks. In this article, we are talking about setup a NAS using a USB drive from scratch.
By default, Openwrt doesn’t include any USB driver, so the first thing you need to do is to install the USB driver.
First you need to setup 703N in router mode (WAN mode), or AP mode (LAN mode). That makes sure 703N can access the internet. The client (your PC) should connect to 703N via wireless.
Lucky, it’s very easy to install software in Openwrt Luci web page.
Go to System menu, software
Like every Linux system, package list need to be updated before install the software. Press the Update button.
In the web page or SSH, install the following packages:
#Those are USB drivers
kmod-usb-core
kmod-usb2
kmod-usb-storage
kmod-usb-storage-extras
block-mount
kmod-usb-uhci
kmod-usb-ohci
#Those are file system support, you may choose only the ones you are using:
kmod-fs-exfat
kmod-fs-ext4
kmod-fs-ntfs
kmod-fs-vfat
#IO charset, IMPORTANT
kmod-nls-cp437
kmod-nls-iso8859-1
#This one is for auto mount
block-mount
#These are samba server and web page configuration software:
luci-app-samba
luci-i18n-samba-en
samba36-server
To enable the auto mount feature, so that you don’t need to mount the USB device manually each time you plug it in, run the following in SSH:
root@OpenWrt:~# block detect > /etc/config/fstab
root@OpenWrt:~# cat /etc/config/fstab
config 'global'
option anon_swap '0'
option anon_mount '0'
option auto_swap '1'
option auto_mount '1'
option delay_root '5'
option check_fs '0'
config 'mount'
option target '/mnt/sda1'
option uuid '40e0-6302'
option enabled '0'
root@OpenWrt:~# /etc/init.d/fstab enable
Simply plug in a USB drive formatted in FAT, reboot the router and check if USB device is mounted by:
df -h
The USB drive should be here in the list other than a few system partitions.
Then let’s configure samba, there are two config files we need to edit. First, edit /etc/config/samba, this file tells samba where are the share point in the system. Here is my configuration:
config samba
option 'name' 'openwrt'
option 'workgroup' 'openwrt'
option 'description' 'openwrt'
option 'homes' '1'
config sambashare
option 'name' 'mnt'
option 'path' '/mnt/'
option 'read_only' 'no'
option 'guest_ok' 'yes'
option 'create_mask' '0700'
option 'dir_mask' '0700'
#option 'users' 'abc'
config sambashare
option 'name' 'root'
option 'path' '/'
option 'read_only' 'no'
option 'guest_ok' 'no'
option 'create_mask' '0700'
option 'dir_mask' '0700'
#option 'users' 'abc'
It shares the file system as well as the mount point.
The second file is /etc/samba/smb.conf, this is the standard samba config file. Refer to Samba manual for detail. Here is my smb.conf file:
[global]
netbios name = |NAME|
workgroup = |WORKGROUP|
server string = |DESCRIPTION|
syslog = 10
encrypt passwords = true
passdb backend = smbpasswd
obey pam restrictions = yes
socket options = TCP_NODELAY
unix charset = utf-8
preferred master = yes
os level = 20
security = user
guest account = nobody
# For safety, disable root user
# invalid users = root
smb passwd file = /etc/samba/smbpasswd
enable samba auto start and reboot the router again:
/etc/init.d/samba enable
Samba should be able to start automatically and can get access to USB immediately after reboot.
Leave a Comment