How to configure auto-mounting\auto-stop USB-HDD like in LEDE?

Hello.

I have last version:

|Model|TP-Link TL-WDR4300 v1|
|Architecture|Atheros AR9344 rev 2|
|Firmware Version|OpenWrt 18.06.1 r7258-5eb055306f / LuCI openwrt-18.06 branch (git-18.228.31946-f64b152)|
|Kernel Version|4.9.120|

I want to use samba public sharing (in home network) with auto-mounting USB-HDD like in LEDE
and auto-stop USB-HDD after 10 minutes inactive\unusing USB-HDD. Also need safe remove USB-HDD drive.

My USB-HDD has NTFS filesystem with russian letters in filenames.
I have already installed following packages:

kmod-fs-ntfs
ntfs-3g
ntfs-3g-low
ntfs-3g-utils

luci-app-samba
luci-i18n-samba-ru

samba36-client
samba36-hotplug
samba36-net
samba36-server

kmod-usb-storage
kmod-usb-storage-extras
kmod-usb-storage-uas

After plug USB-HDD to the router, I see it in dmesg log:

[42891.801179] usb-storage 1-1.2:1.0: USB Mass Storage device detected
[42891.826751] scsi host2: usb-storage 1-1.2:1.0
[42892.858153] scsi 2:0:0:0: Direct-Access     WD       My Passport 0832 1065 PQ: 0 ANSI: 6
[42892.870812] scsi 2:0:0:1: Enclosure         WD       SES Device       1065 PQ: 0 ANSI: 6
[42892.881432] sd 2:0:0:0: [sdb] Spinning up disk...
[42893.976666] .
[42895.016689] .
[42896.056672] .
[42896.057667] ready
[42896.060084] sd 2:0:0:0: [sdb] 976707584 512-byte logical blocks: (500 GB/466 GiB)
[42896.069327] sd 2:0:0:0: [sdb] Write Protect is off
[42896.074286] sd 2:0:0:0: [sdb] Mode Sense: 53 00 10 08
[42896.081070] sd 2:0:0:0: [sdb] No Caching mode page found
[42896.086568] sd 2:0:0:0: [sdb] Assuming drive cache: write through
[42896.249570]  sdb: sdb1
[42896.257095] sd 2:0:0:0: [sdb] Attached SCSI disk

Device present:

root@OpenWrt:~# ls -l /dev/sd*
brw-------    1 root     root        8,   0 Nov 29 00:08 /dev/sda
brw-------    1 root     root        8,  16 Nov 29 20:32 /dev/sdb
brw-------    1 root     root        8,  17 Nov 29 20:32 /dev/sdb1
root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 2.5M      2.5M         0 100% /rom
tmpfs                    61.2M      1.5M     59.7M   2% /tmp
/dev/mtdblock3            4.3M      2.6M      1.6M  61% /overlay
overlayfs:/overlay        4.3M      2.6M      1.6M  61% /
tmpfs                   512.0K         0    512.0K   0% /dev

How to configure all it? (Automounting, Autostop after inactive, Safe eject.)

Automount / idle spindown -> https://openwrt.org/docs/guide-user/storage/usb-drives
Samba -> https://openwrt.org/docs/guide-user/services/nas/cifs.server

I did automount by instructions:
but it isn't work.
after reboot router or unplug\plug USB-HDD, "option target '/mnt/sdb1'" changing to "option target '/mnt/sda1'" in "block detect" output
and vice versa every times:
(output 'block detect' command every times diffrent with /etc/config/fstab configfile what a make before)

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    'B4D48115D480DB4E'
        option  enabled '0'

root@OpenWrt:~# block detect
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/sdb1'
        option  uuid    '0000001800000048'
        option  enabled '0'

it's working only hand mounting:

root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 2.5M      2.5M         0 100% /rom
tmpfs                    61.2M    420.0K     60.8M   1% /tmp
/dev/mtdblock3            4.3M      2.8M      1.5M  65% /overlay
overlayfs:/overlay        4.3M      2.8M      1.5M  65% /
tmpfs                   512.0K         0    512.0K   0% /dev

root@OpenWrt:~# mount /dev/sdb1 /mnt/sdb1

root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
/dev/root                 2.5M      2.5M         0 100% /rom
tmpfs                    61.2M    420.0K     60.8M   1% /tmp
/dev/mtdblock3            4.3M      2.8M      1.5M  65% /overlay
overlayfs:/overlay        4.3M      2.8M      1.5M  65% /
tmpfs                   512.0K         0    512.0K   0% /dev
/dev/sdb1               465.7G    146.1G    319.6G  31% /mnt/sdb1

before unpluging USB-HDD:

root@OpenWrt:~# ls -l /dev/sd*
brw-------    1 root     root        8,   0 Nov 30 09:52 /dev/sda
brw-------    1 root     root        8,  16 Nov 30 09:52 /dev/sdb
brw-------    1 root     root        8,  17 Nov 30 09:52 /dev/sdb1

after unplugging USB-HDD:

root@OpenWrt:~# ls -l /dev/sd*
brw-------    1 root     root        8,   0 Nov 30 09:52 /dev/sda

It's been a while since I've tried to auto mount ntfs and I don't know if anything has changed, but in my experience it just wasn't possible with the usual instructions, you can use this line in /etc/rc.local (system>startup in luci) to mount at boot -

sleep 3

ntfs-3g /dev/sda1 /mnt/usb-ntfs -o rw,async

Source, and there's also a couple of scripts at that link you can try for auto mount, but I've never tried them so don't know if they work or not.

root@OpenWrt:~# cat /etc/rc.local
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

umount /mnt/sdb1
ntfs-3g /dev/sdb1 /mnt/sdb1 -o rw,async

yes, it working when I reboot router.
but when I detach USB-HDD and attach again, automount mounting device in readonly mode, like this:

mount /mnt/sdb1

root@OpenWrt:~# touch /mnt/sdb1/qweqwe
touch: /mnt/sdb1/qweqwe: Read-only file system

Use "option 'options' 'rw'".

I think it's not main..

Why after replug USB-HDD, show different mount points?

now - '/mnt/sdc1'

root@OpenWrt:~# block detect

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/sdc1'
        option  uuid    '0000001800000048'
        option  enabled '0'

before was '/mnt/sdb1':

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 '1'

config mount
        option target '/mnt/sdb1'
        option uuid '0000001800000048'
        option enabled '1'
        option fstype 'ntfs'

Have you properly unmounted the USB, then remounted the drive either via

  • LUCI GUI

  • or SSH?

umount /dev/sdb1
ntfs-3g /dev/sdb1 /mnt/sdb1 -o rw,async

Also if getting read-only permissions try applying full directory access to /mnt/sdb1

chmod -R 777 /mnt/sdb1

Linux will assign a different device name like "/dev/sd_" each time you plug in a drive, that is expected behaviour. And "block detect" is giving you info about where is the drive at that moment.

Thats is why you should use UUIDs instead of device names at fstab.

SSH.

if I mount through:
mount /dev/sdb1
i have readonly.

if I mount though:
ntfs-3g /dev/sdb1 /mnt/sdb1 -o rw,async
i have read-write filesystem.

This is automount parameters of mount:

root@OpenWrt:~# mount | grep mnt
/dev/sdc1 on /mnt/sdb1 type ntfs (ro,relatime,uid=0,gid=0,fmask=0177,dmask=077,nls=default,errors=continue,mft_zone_multiplier=1)

Following parameters is manually mount filesystem. It's good paramters. =)
How to learn the automount system mount filesystem with "good parameters" ?

root@OpenWrt:~# mount | grep mnt
/dev/sdc1 on /mnt/sdb1 type fuseblk (rw,relatime,user_id=0,group_id=0,allow_other,blksize=4096)

PS.
changing fstype in /etc/config/fstab doesn't help:

#       option fstype 'ntfs'
        option fstype 'fuseblk'

Hi.
I solve my problem.
Solution found in this topic:

Once kmod-fs-ntfs exists, ntfs-3g doesn't work. So just remove kmod-fs-ntfs.
and reboot router!

Now USB-HDD is readwrite mode and successfuly automounting after plugging:

root@OpenWrt:~# mount | grep mnt
/dev/sdb1 on /mnt/sdb1 type fuseblk (rw,relatime,user_id=0,group_id=0,allow_other,blksize=4096)

and my /etc/rc.local is empty because working 'block mount' in /etc/init.d/fstab .

Now I need add tab "Safe Eject USB" in LUCI interface to execute command "/etc/init.d/fstab stop" .
Is it possible ?

1 Like

If you install block-mount you should see Mount Points under System in Luci, in Mount Points you should see Mounted File Systems and your drive should be listed there with an option to Unmount.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.