[mythtv-users] Question about fstab - how to mount and umount by UUID?
Stephen Worthington
stephen_agent at jsw.gen.nz
Fri Jun 2 02:18:18 UTC 2017
On Thu, 1 Jun 2017 19:37:24 -0400, you wrote:
>This may be a little off-topic; I have a strange linux problem. Working
>on a new Mythtv build, I have multiple drives installed...
>
>Using all the Sata jacks:
>Sata1: SSD for boot, 120Gig
>Sata2: WD 2.0T (terra byte)
>Sata3: Samsung 2.0T
>Sata4: WD 1.5T
>Sata5: WD 1.0T
>
>Linux sees them as this (very strange, skips d, e, f, g)
>/dev/sda
>/dev/sdb
>/dev/sdc
>/dev/sdh
>/dev/sdi
>
>I've messed around with the bios boot order and gotten some different
>results, but nothing puts them in order. I thought it might be better
>to set up fstab with UUID's, but I don't see any way to manually
>mount/umount each drive, individually . Google only shows "mount -a",
>which I assume mounts everything in fstab. What do you suggest?
The order the kernel puts drives in seems to be determined by the
order it loads its drivers, and then by the order each driver
enumerates the hardware it operates. The gap in your drive lettering
is likely caused by there being another SATA controller in your
chipset that is not connected to any physical ports, or maybe it is
connected to one or two eSATA ports on your back panel. Smaller
motherboards often use the same chipsets as larger motherboards, and
then have hardware in the chipset that is not connected to anything
due to lack of space for connectors.
There is no way I have found to control how the kernel assigns the
drive letters. So it is best to simply not use the drive letters
unless forced to, so using UUIDs or partition labels is the right way
to mount things. UUIDs have been around for this purpose for a long
time, but now partition labels are also available and I find I prefer
to use them. To assign a label to a partition, I prefer to use
gparted (you may need to install it if it is not already available).
It is a GUI version of the parted partitioning program and can assign
a drive label to any unmounted partition for you. Here is an example
from my fstab:
### Disk 8: ST8000AS0002-1NA17Z_Z540HZMD 8 Tbytes (SMR) (vid3)
LABEL=vid3 /mnt/vid3 jfs relatime,errors=remount-ro,nofail 0 2
The advantage I find for using labels is that they can be meaningful -
UUIDs are very hard to remember!
Take a look at the /dev/disk subdirectories for all the different ways
a modern Linux allows you to refer to drives and partitions:
root at mypvr:/mnt# ll /dev/disk
total 0
drwxr-xr-x 8 root root 160 May 27 01:14 ./
drwxr-xr-x 22 root root 6000 May 27 01:15 ../
drwxr-xr-x 2 root root 1360 May 27 01:14 by-id/
drwxr-xr-x 2 root root 400 May 27 01:14 by-label/
drwxr-xr-x 2 root root 160 May 27 01:14 by-partlabel/
drwxr-xr-x 2 root root 480 May 27 01:14 by-partuuid/
drwxr-xr-x 2 root root 580 May 27 01:14 by-path/
drwxr-xr-x 2 root root 440 May 27 01:14 by-uuid/
root at mypvr:/mnt# ll /dev/disk/by-label/
total 0
drwxr-xr-x 2 root root 400 May 27 01:14 ./
drwxr-xr-x 8 root root 160 May 27 01:14 ../
lrwxrwxrwx 1 root root 10 May 27 01:14 rec1 -> ../../sdb3
lrwxrwxrwx 1 root root 10 May 27 01:14 rec1boot -> ../../sdb1
lrwxrwxrwx 1 root root 10 May 27 01:14 rec2 -> ../../sdd2
lrwxrwxrwx 1 root root 10 May 27 01:14 rec2boot -> ../../sdd1
lrwxrwxrwx 1 root root 10 May 27 01:14 rec3 -> ../../sda5
lrwxrwxrwx 1 root root 10 May 27 01:14 rec3boot1 -> ../../sda2
lrwxrwxrwx 1 root root 10 May 27 01:14 rec3boot2 -> ../../sda3
lrwxrwxrwx 1 root root 10 May 27 01:14 rec3boot3 -> ../../sda4
lrwxrwxrwx 1 root root 10 May 27 01:14 rec4 -> ../../sdc1
lrwxrwxrwx 1 root root 10 May 27 01:14 rec5 -> ../../sdn1
lrwxrwxrwx 1 root root 10 May 27 01:14 rec6 -> ../../sdm1
lrwxrwxrwx 1 root root 10 May 27 01:14 rec7 -> ../../sdi1
lrwxrwxrwx 1 root root 15 May 27 01:14 ssd1 -> ../../nvme0n1p3
lrwxrwxrwx 1 root root 15 May 27 01:14 ssd2 -> ../../nvme0n1p4
lrwxrwxrwx 1 root root 10 May 27 01:14 vid1 -> ../../sdj2
lrwxrwxrwx 1 root root 10 May 27 01:14 vid1boot -> ../../sdj1
lrwxrwxrwx 1 root root 10 May 27 01:14 vid2 -> ../../sdk1
lrwxrwxrwx 1 root root 10 May 27 01:14 vid3 -> ../../sdl1
You can use those /dev/disk names in any place you normally use
/dev/sd?? names. So, for example, to do a check on my rec1boot
partition, I can do:
umount /dev/disk/by-label/rec1boot
fsck -C -f /dev/disk/by-label/rec1boot
mount /dev/disk/by-label/rec1boot
Note that the full support of partition labels is fairly new - it will
not work or some things will not work on older kernels from a couple
of years ago.
It is also possible to use a bit of scripting to find out the
/dev/sd?? name for a mounted device. This is what I use (gleaned from
the Internet):
root at mypvr:/mnt# cat /usr/local/bin/dev-mounted
#!/bin/bash
# Return the device that is mounted on the mount point $1
mountp=$1
if ! [[ "$mountp" == *\/* ]]; then
mountp="/mnt/$mountp"
fi
df | grep -w $mountp | awk {'print $1'}
And here is my script that uses dev-mounted to unmount and put to
sleep any of my archive drives that I currently have mounted:
root at mypvr:/mnt# cat /usr/local/bin/uarc.sh
#!/bin/bash
set -x
# Unmount and put to sleep all the archive drives.
arc1dev=$(dev-mounted arc1)
arc2dev=$(dev-mounted arc2)
arc3dev=$(dev-mounted arc3)
if [ ${#arc1dev} -ne 0 ]; then
umount /mnt/arc1
fi
if [ ${#arc2dev} -ne 0 ]; then
umount /mnt/arc2
fi
if [ ${#arc3dev} -ne 0 ]; then
umount /mnt/arc3
fi
sleep 20
if [ ${#arc1dev} -ne 0 ]; then
hdparm -Y $arc1dev
fi
if [ ${#arc2dev} -ne 0 ]; then
hdparm -Y $arc2dev
fi
if [ ${#arc3dev} -ne 0 ]; then
hdparm -Y $arc3dev
fi
More information about the mythtv-users
mailing list