How to create custom device name in CentOS 7?

Issues related to hardware problems
Post Reply
ScottN
Posts: 2
Joined: 2020/11/12 01:04:12

How to create custom device name in CentOS 7?

Post by ScottN » 2020/11/12 01:19:53

I am building a new CentOS 7 server to replace a CentOS 7 server. I'm having a little difficulty figuring out how I can have various external USB drives be automatically mapped to a custom device name /dev/usbdrive. This worked well previously.

In CentOS 6, I would add something like this to /etc/udev/rules.d/10-local.rules

Code: Select all

BUS=="usb", SYSFS{serial}=="S2K4J1BBA01294", KERNEL=="sd?1", NAME="usbdrive"
Then I could always mount it, without knowing whether it showed up as sdd, sde, etc.:

Code: Select all

mount -t ext4 /dev/usbdrive /mnt/usbdrive
But right now this returns:

Code: Select all

mount: special device /dev/usbdrive does not exist
I've not been able to get this to work on CentOS 7, and my Google-foo has completely let me down. I'll take any help you can give me. :-)

- Scott

User avatar
TrevorH
Site Admin
Posts: 33216
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: How to create custom device name in CentOS 7?

Post by TrevorH » 2020/11/12 10:29:58

Perhaps it would be easier if you mounted using either LABEL or UUID instead. Those are both recognised and recommended ways to mount filesystems. The UUID ought to be unique and not in common with any other filesystem anywhere. The LABEL can be set with utilities like e2label (for ext2/3/4) and I suspect xfs will have something similar so that means you could assign duplicate label names to different sticks if you did want them mounted in the same place.

Also on CentOS 7 and presumably 8, most removable filesystems get automounted under /run/media/$user/$LABEL without any extra rules at all.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

MartinR
Posts: 714
Joined: 2015/05/11 07:53:27
Location: UK

Re: How to create custom device name in CentOS 7?

Post by MartinR » 2020/11/12 11:46:57

FYI:

Code: Select all

# xfs_admin -L mystick /dev/sdc1
Re Trevor's mounting in the same place: all my backup disks (external USB) are labelled "backup", so

Code: Select all

# mount /backup
will always mount whichever one is attached.

ScottN
Posts: 2
Joined: 2020/11/12 01:04:12

Re: How to create custom device name in CentOS 7?

Post by ScottN » 2020/11/13 00:15:57

Thanks so much for the assist! At the moment, when I plug a USB external drive in, it shows up as /dev/sdd1. But sometimes it might be sdc1 or sde1, etc. If I use 'e2label /dev/sdd1 usbdrive' is that creating a label for just that one USB external drive? or creating a label for anything that might now or in the future show up as /dev/sdd1?

For whatever reason, these ext4 formatted USB external drives (I have many that I swap in and out) do not auto mount, and do not show up under /media or /run/media. That's fine, I'm OK with having my script mount them... the script just needs a more predictable device name (i.e. /dev/usbdrive)

- Scott

User avatar
jlehtone
Posts: 4531
Joined: 2007/12/11 08:17:33
Location: Finland

Re: How to create custom device name in CentOS 7?

Post by jlehtone » 2020/11/13 11:47:32

man e2label wrote:e2label - Change the label on an ext2/ext3/ext4 filesystem
...
It is also possible to set the volume label using the -L option of tune2fs(8).
Label is part of filesystem's metadata. It is stored in the disk.
UUID is also part of filesystem's metadata.
You can see both with lsblk -f

You are right that the /dev/{[hsv]d,nvme}* names are not persistenly and predictably enumerated and assigned.

When you add label, you can refer to this specific (filesystem in) USB drive no matter what /dev/sd* it gets.

However, if you have two filesystems with identical label, then you can't differentiate between them with the label.
(I had RAID mirror; both disks had identical copy. Then something broke and system could not enable the mirror; writes went to one and that too changed on reboot.)
That should not be a problem for you; you connect at most one USB drive at any given time.

Similarly, if you had a rule to call every USB drive /dev/johndoe, how would it name two simultaneously connected drives?

Post Reply