Mounting USB drives via the volume label

Have you used the option of mounting an HDD partition via the Label?

The mount manpage says that this is now the preferred way of mounting a partition.

I've recently started doing this for USB-attached HDDs that I use for holding offline backups, i.e. using mount's -L LABEL option, and find that it works really well.

However, I usually run "fsck -p" against the backup immediately after unmounting it and here's where I've hit a snag: neither fsck nor fsck.ext4 support use of a label to identify the partition to be fscked.

This problem exists for both Raspbian Stretch and Fedora 28

I have a rather nasty workround: run the following before unmounting th volume:

usb_dev=$(df --type=ext4 | \ gawk '/\/dev\/sd[b-z]/ { device=$1 } END {print $1} ') umount -f "$usb_disk" fsck -n $usb_dev

This works, but it relies on the disk to be checked being the last volume to be mounted, which makes its details the last line containing /dev/sdx in the df output.

My reason for asking: does anybody have a less mickey mouse way of finding a disk reference that fsck will accept?

If not, I'll attempt to raise a request to add access by label to fsck via the RedHat bugzilla - unless, of course, somebody knows a better way to get this feature added.

--
Martin    | martin at 
Gregorie  | gregorie dot org
Reply to
Martin Gregorie
Loading thread data ...

surely the disk partitins show as /dev/*** even when unmounted?

--
"If you don?t read the news paper, you are un-informed. If you read the  
news paper, you are mis-informed." 
 Click to see the full signature
Reply to
The Natural Philosopher

Have you tried basename $(readlink /dev/disk/by-label/LABEL)

--

Chris Elvidge, England
Reply to
Chris Elvidge

Thanks for that - its in for a trial on tonight's backup.

--
Martin    | martin at 
Gregorie  | gregorie dot org
Reply to
Martin Gregorie

Nice. Safer, get the whole name: readlink -e /dev/disk/by-label/LABEL

Reply to
A. Dumas

fsck?s man page says it supports labels:

fsck is used to check and optionally repair one or more Linux filesys? tems. filesys can be a device name (e.g. /dev/hdc1, /dev/sdb2), a mount point (e.g. /, /usr, /home), or an ext2 label or UUID specifier (e.g. UUID=8868abf6-88c5-4a83-98b8-bfc24057f7bd or LABEL=root). Nor? mally, the fsck program will try to handle filesystems on different physical disk drives in parallel to reduce the total amount of time needed to check all of them.

Does it not work?

--
https://www.greenend.org.uk/rjk/
Reply to
Richard Kettlewell

Used in tonight's backup (after commandline test, natch) instead of the original suggestion.

A quick search shows how and when /dev/disk/by-label gets populated with symlinks, though not how or why they get discarded.

--
Martin    | martin at 
Gregorie  | gregorie dot org
Reply to
Martin Gregorie

missed it, mainly because I was looking for an option like 'mount's -L option. Mutter.. mutter.. consistency!

Thanks - I'll try that out tomorrow after I've seen what readlink can do.

--
Martin    | martin at 
Gregorie  | gregorie dot org
Reply to
Martin Gregorie

No, it does not.

The manual says that labels can be used equivalently to /dev/sdn or UUIDs, but while

usb_label="USB_SNAPSHOT" usb_disk="/media/snapshot" sudo mount -t ext4 -L "$usb_label" "$usb_disk"

works correctly

sudo fsck -n $usb_label

outputs an "Emergency help:" message listing the fsck options etc and

sudo fsck.ext4 -n $usb_label

outputs the error

e2fsck 1.44.2 (14-May-2018) fsck.ext4: No such file or directory while trying to open USB_SNAPSHOT Possibly non-existent device?

I've opened a bug report and in the meanwhile am using

readlink -e $usb_label

to get the device name.

--
Martin    | martin at 
Gregorie  | gregorie dot org
Reply to
Martin Gregorie

sudo fsck -N LABEL=$usb_label

Note: capital N and LABEL= At least, that worked on one of my systems.

To continue:

umount LABEL=$usb_label fsck LABEL=$usb_label

--

Chris Elvidge, England
Reply to
Chris Elvidge

Martin Gregorie wrote, on 28-03-2019 13:32:

From where do you get the -n option? I don't see it in the man page for Linux (Raspbian) fsck except as an option to e2fsck meaning non-interactive non-errorcorrecting mode. Also the man page clearly states, and Richard quoted, how to specify a label: "e.g. UUID=8868abf6-88c5-4a83-98b8-bfc24057f7bd or LABEL=root"

Reply to
A. Dumas

Yes, thats where its documented, along with the fsck manpage saying that any options it doesn't recognise are passed to the filesystem type- specific subsystem, in this case fsck.ext4

Missed seeing that. I'd have laid out the manpage a bit differently, probably using a device specifier per line in a vertical list.

--
Martin    | martin at 
Gregorie  | gregorie dot org
Reply to
Martin Gregorie

Does it work if you use the syntax quoted in the man page, rather than using just the label name?

--
https://www.greenend.org.uk/rjk/
Reply to
Richard Kettlewell

Yes it does.

--
Martin    | martin at 
Gregorie  | gregorie dot org
Reply to
Martin Gregorie

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.