mapping usb disks to devices

mapping usb disks to devices

Tzafrir Cohen tzafrir at cohens.org.il
Thu Aug 17 11:28:35 IDT 2017


On Wed, Aug 16, 2017 at 10:21:59PM +0300, Gabor Szabo wrote:
> Hi,
> 
> I have a USB hub connected to my Raspberry Pi and I have several
> external Hard disks connected to the USB hub.
> It seems the order the hard disks are mapped to the device files
> /dev/sda1 /dev/sdb1 /dev/sdc1 is random. On every boot it might be different.
> 
> This of course breaks the mapping I have in /etc/fstab for the mounts.
> 
> How can I solve this so I won't need to update /etc/fstab after every boot?

Standard udev rules create on my system the following 4 subdirectories
under /dev/disk:

  by-id  by-label  by-partuuid  by-path  by-uuid

Each directory has symlinks to either a disk or a partition. One of
those should describe your external disk properly.

If this is not good enough, you can make your own.

$ cat /etc/udev/rules.d/90-backup-usb.rules
ACTION=="add", ENV{ID_FS_LABEL}=="backup-boole-*", \
        SYMLINK+="backup"

And in fstab:

/dev/backup     /mnt/backup     ext4    rw,noauto       0       0


There are several backup disks with different labels. The backup disk
that is connected is mounted by the backup script, but /dev/backup is
created by the udev rule.

-- 
Tzafrir Cohen         | tzafrir at jabber.org | VIM is
http://tzafrir.org.il |                    | a Mutt's
tzafrir at cohens.org.il |                    |  best
tzafrir at debian.org    |                    | friend



More information about the Linux-il mailing list