Mounting USB drives to fixed mounting points by UUID

Post new topic   Reply to topic    DD-WRT Forum Index -> Atheros WiSOC based Hardware
Author Message
ArjenR49
DD-WRT Guru


Joined: 05 Oct 2008
Posts: 666
Location: Helsinki, Finland / nr. Alkmaar, Netherlands

PostPosted: Sun Jul 29, 2018 23:21    Post subject: Mounting USB drives to fixed mounting points by UUID Reply with quote
In an attempt to solve the problem of a NAS getting mounted at random to sda1 or sdb1 thus breaking file sharing on my R7800 running Kong's r36375M I cobbled together the following startup script borrowing bits and pieces from many sources.

It sets a fixed mounting point (NAS1) based on the UUID of the drive.

The mount command in the script combined with the appropriate settings on the NAS page of the GUI looks like a working starting point.

sleep 10
logger -t --- 'Begin startup script execution'
logger -t --- '1. Mounting USB drive NAS1 (UUID=b354d930-0940-4fd6-9f32-635f06cc08e2)'
mount -o noatime $(findfs UUID=b354d930-0940-4fd6-9f32-635f06cc08e2) /opt/NAS1 || logger -t --- 'ERROR Mounting opt/NAS1'
logger -t --- '2. Starting rc.unslung'
/opt/etc/init.d/rc.unslung start
logger -t --- 'End startup script execution'

The USB drive I tested this with is a 16 GB Thumb drive. Partition table is GPT, having one partition formatted to ext2 format.
Some or all of those details may be essential for the above mount command to work.

The mount command provided with the r36375M version firmware does not seem to allow mounting by UUID directly.

Eventually I will want to use a Verbatim 2 TB USB HDD, but that currently has an MBR partition table and one partition formatted to NTFS and from earlier testing it looked like it somehow doesn't agree with DD-WRT, although automount does work for that drive.


Last edited by ArjenR49 on Wed Oct 17, 2018 8:37; edited 1 time in total
Sponsor
ArjenR49
DD-WRT Guru


Joined: 05 Oct 2008
Posts: 666
Location: Helsinki, Finland / nr. Alkmaar, Netherlands

PostPosted: Thu Aug 02, 2018 19:22    Post subject: Reply with quote
Despite negative test results when mounting an NTFS formatted partition in an SSH terminal, in the startup script mounting to a fixed point of an NTFS partition appears to work just as well as mounting an EXT2 partition on my test Thumb drive after all.

Current startup script:

sleep 10
logger -t --- 'Begin startup script execution'
#logger -t --- '1. Mounting USB drive NAS1 (UUID=b354d930-0940-4fd6-9f32-635f06cc08e2)'
#mount -o noatime $(findfs UUID=b354d930-0940-4fd6-9f32-635f06cc08e2) /opt/NAS1 || logger -t --- 'ERROR Mounting to opt/NAS1'
logger -t --- '1. Mounting USB drive NAS1 (UUID=B298F12198F0E4AF)'
mount -o noatime $(findfs UUID=B298F12198F0E4AF) /opt/NAS1 || logger -t --- 'ERROR Mounting to opt/NAS1'
logger -t --- '2. Starting rc.unslung'
/opt/etc/init.d/rc.unslung start
logger -t --- 'End startup script execution'


results in the following entries towards the end of the syslog after rebooting:

Aug 2 19:37:26 R7800 user.notice ---: Begin startup script execution
Aug 2 19:37:26 R7800 user.notice ---: 1. Mounting USB drive NAS1 (UUID=B298F12198F0E4AF)
Aug 2 19:37:28 R7800 user.notice ---: 2. Starting rc.unslung
Aug 2 19:37:28 R7800 user.notice ---: End startup script execution

The drive partition is now mounted under /opt/NAS1, as defined in the NAS page of the GUI, and in my case can be accessed with:
smb://NAS_user@r7800.xyz/nas1/
independent of at which USB port it is plugged in and what the firmware initially assigns, sdaX or sdbX.
ArjenR49
DD-WRT Guru


Joined: 05 Oct 2008
Posts: 666
Location: Helsinki, Finland / nr. Alkmaar, Netherlands

PostPosted: Thu Aug 09, 2018 0:20    Post subject: Reply with quote
An external drive on the eSATA port is automounted by the firmware like any USB drive (currently Kong's r36500M on a NetGear R7800 router). (eSATA signal light on R7800 remains off even though port is connected.)

As device names get assigned in varying order, there's no telling which drive gets to be which NAS after a reboot, which likely causes problems down the road.
This script can remedy that situation. In addition to the script one should set names etc. on the Services/NAS page of the GUI.

The script uses a FOR loop, an IF statement and a kind of array variables and array variable referencing which were quite tricky to get right as documentation on the ASH shell is very thin on the ground. In addition I have but very little experience with Linux shell scripting.

The script can easily be extended to any number of UUID's.
ArjenR49
DD-WRT Guru


Joined: 05 Oct 2008
Posts: 666
Location: Helsinki, Finland / nr. Alkmaar, Netherlands

PostPosted: Wed Oct 17, 2018 8:32    Post subject: Reply with quote
Latest version of this script with one change suggested by <Kong> when findfs went missing in fw version 37400M for R7800.
Should work in previous fw versions, too, although I didn't try.
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Atheros WiSOC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum