Permanent device/mount name for a USB disk
Permanent device/mount name for a USB disk
When I feel like doing some actual work I plug a USB disk labelled "WorkUSB". Could it always be known as /dev/workusb? So that it'd be automatically mounted as /mnt/workusb (or /mnt/workusb1 if more than 1 partition I guess)? At the moment I get /mnt/sdb or /mnt/sdc depending which letter is still available after automatically mounting whatever host disks etc., which isn't permanent.
I think I need to "write a udev rule", but I've never done it before and don't even know where to look and what where to edit on my Porteus 5rc2. Please help
I think I need to "write a udev rule", but I've never done it before and don't even know where to look and what where to edit on my Porteus 5rc2. Please help
-
- Samurai
- Posts: 142
- Joined: 18 Aug 2013, 12:09
- Distribution: Slackware PartedMagic Xubuntu
- Location: The Netherlands
Permanent device/mount name for a USB disk
/etc/udev/rules.d/73-burdi01.rules:
will create symlinks in /dev/ pointing to whatever the "real" sdXn happens to be -- e.g. /dev/sdxb1 -> sdc1 and /dev/sdxd5 -> /dev/sdf5. These symlinks then can be used in your fstab.
The vendor, model and, if necessary, e.g. the serial# can be derived from lsusb.

Code: Select all
# External USB disk is sometimes /dev/sdb, sometimes /dev/sdf or whatever
KERNEL=="sd*", SUBSYSTEMS=="scsi", ATTRS{vendor}=="WD", ATTRS{model}=="Elements 25A3", SYMLINK+="sdxb%n"
KERNEL=="sd*", SUBSYSTEMS=="scsi", ATTRS{vendor}=="TOSHIBA", ATTRS{model}=="External USB 3.0", SYMLINK+="sdxd%n"
The vendor, model and, if necessary, e.g. the serial# can be derived from lsusb.

Permanent device/mount name for a USB disk
burdi01, Thanks, but it is already known to the system by a symlink as
I don't think I need yet another symlink for it, do I?
Anyway, I guess I can then write a fstab for mounting those symlinks (--another thing I'm not too familiar with) ...
But, could I have the true device node name as /dev/workusb ?! Am I allowed to do that? So my udev rule should use the assignment key below and be placed higher in the rules priority, maybe as 10-myudev.rules:
Would fstab magic swallow that frivolity with the names and auto-mount it to /mnt/workusb for me?
Code: Select all
/dev/disk/by-label/WorkUSB
Anyway, I guess I can then write a fstab for mounting those symlinks (--another thing I'm not too familiar with) ...
But, could I have the true device node name as /dev/workusb ?! Am I allowed to do that? So my udev rule should use the assignment key below and be placed higher in the rules priority, maybe as 10-myudev.rules:
Code: Select all
NAME=workusb
Permanent device/mount name for a USB disk
OK, actually I don't care about the original /dev/* name. As I anyway get the symlink:
I just want it to be always and uniquely mounted to
My /etc/fstab says this:
What "automounter" put it there like that? I love everything about that line except that if my disk (partition) had a <LABEL>, then I want to be auto-mounted to /mnt/<LABEL> instead of /mnt/sdb (or /mnt/sdb1). Where do I modify what?
Code: Select all
/dev/disk/by-label/WorkUSB
Code: Select all
/mnt/WorkUSB
Code: Select all
# Do not edit this file as fstab is recreated automatically during every boot.
# Please use /etc/rc.d/rc.local or sysvinit scripts if you want to mount/unmount
# ...
/dev/sdb /mnt/sdb ext4 comment=x-gvfs-show,comment=x-gvfs-icon=drive-removable-media,user,noatime,nodiratime,suid,dev,exec,async 0 0
-
- Samurai
- Posts: 142
- Joined: 18 Aug 2013, 12:09
- Distribution: Slackware PartedMagic Xubuntu
- Location: The Netherlands
Permanent device/mount name for a USB disk
Hmm, it never occurred to me to use /dev/disk/by-label/foo as such -- thks for this tip.
As per man fstab(5) a LABEL=<label> or UUID=<uuid> may be given instead of a device name.
IIRC (I do not have the time right now to research) the fstab is recreated somewhere in the init procedure.

As per man fstab(5) a LABEL=<label> or UUID=<uuid> may be given instead of a device name.
IIRC (I do not have the time right now to research) the fstab is recreated somewhere in the init procedure.

Permanent device/mount name for a USB disk
burdi01, I've found this (in porteus 4 at least):
which is run by /etc/udev/rules.d/10-porteus-fstab-update.rules,
and which indeed has the relevant line:
I'm thinking of an edit as follows please check my conditional assignment and overall approach:
Code: Select all
/sbin/udev-fstab-update
and which indeed has the relevant line:
Code: Select all
# Variables initialized by the udev environment:
# $ACTION (add, change, remove)
# $DEVNAME (device name including path)
# $ID_FS_TYPE (filesystem type)
...
# Our variables:
FSTAB=/etc/fstab
DEVICE=`echo $DEVNAME | sed s_^/dev/__`
MNTPT=/mnt/$DEVICE
...
Code: Select all
# Variables initialized by the udev environment:
# $ACTION (add, change, remove)
# $DEVNAME (device name including path)
# $ID_FS_TYPE (filesystem type)
# $ID_FS_LABEL (filesystem label presumably)
...
# Our variables:
FSTAB=/etc/fstab
DEVICE=`echo $DEVNAME | sed s_^/dev/__`
MNTPT=/mnt/${ID_FS_LABEL:-$DEVICE}
...
-
- Samurai
- Posts: 142
- Joined: 18 Aug 2013, 12:09
- Distribution: Slackware PartedMagic Xubuntu
- Location: The Netherlands
Permanent device/mount name for a USB disk
Your conditional assignment is syntactically ok. Whether or not udev initializes an ID_FS_LABEL variable would require some research/fiddling to be answered.
However, I do not like your approach: replacing code instead of just adding, doing things for all labelled filesystems etc. etc.
What I would do is letting Porteus mount the USB as is and at the end of /sbin/udev-fstab-update add some code to create the workusb mountpoint as a symlink to the real mountpoint (derived from /dev/disk/by-label).

However, I do not like your approach: replacing code instead of just adding, doing things for all labelled filesystems etc. etc.
What I would do is letting Porteus mount the USB as is and at the end of /sbin/udev-fstab-update add some code to create the workusb mountpoint as a symlink to the real mountpoint (derived from /dev/disk/by-label).

Permanent device/mount name for a USB disk
OK, I'm going back then to my old script that I run after I plug in my WorkUSB and am ready to work. It makes a symbolic link and is reentrant, i. e. save to re-execute. I hope you approve it, burdi01, and thanks for advising me so far.
Code: Select all
'/W' -> '/mnt/sda1'
Code: Select all
#!/bin/bash
# some disks in fstab might need a second chance to mount, e.g. NVMe
mount -a
#
# Work disk: either on a separate (NTFS) USB or the same disk as Porteus itself
#
# use either of these:
#Wdisk=$(findmnt $(readlink -mn /dev/disk/by-label/WorkUSB) -no TARGET)
#Wdisk=$(lsblk $(readlink -mn /dev/disk/by-label/*Work*) -no MOUNTPOINT)
Wdisk=$(lsblk $(readlink -mn /dev/disk/by-label/WorkUSB) -no MOUNTPOINT)
if [[ ! -z $Wdisk ]]
then
echo "WorkUSBDisk: $Wdisk"
else
echo "No WorkUSB disk: re-using porteus USB"
#exit 1
#Wdisk=$(lsblk $(readlink -mn /dev/disk/by-label/Porteus) -no MOUNTPOINT)
Wdisk=$PORTPORT
fi
ln -sfnv $Wdisk /W