# Recommended way to manage block device names in Gentoo

## lesha_n

Hi all,

What is the best or recommended way to manage the assignment of block device names in Gentoo? Is it just udev or something on top of it (udisks?). If udev, are there guidelines on writing rules? The udev guide (https://wiki.gentoo.org/wiki/Udev) is fairly sketchy on that (e.g no rules).

Background: I have 3 internal disks that got assigned to /dev/sd[abc]. Most of the time, the way they were assigned does not matter to me, since the important things seem to be done though UUIDs (e.g. GRUB in LVM configurations). However, sometimes it matters:

 /dev/sd[abc] device names are easier to remember and use. Ideally I'd like to assign 'a', 'b' and 'c' in a controlled way, such that the system disk is always /dev/sda -- however, is controlling device names explicitly the right way of doing things? What are advantages and drawbacks? Are there better ways?

 What about external disks -- how to ensure predictable device names for them? I booted with an external disk attached and powered and surely enough it bumped one of my internal disks to another device (/dev/hdd) -- this is the sort of thing one would really like to avoid.

Would really appreciate opinions and pointers to relevant Gentoo docs.

Cheers,

Aleksey

----------

## frostschutz

 *Quote:*   

>  Ideally I'd like to assign 'a', 'b' and 'c' in a controlled way 

 

Not really possible. First come first serve.

You can configure your kernel with built in drivers so in most cases it will not change. But there is no guarantee for that.

Don't write your own rules. Use the existing /dev/disk/by*/* names.

Set (unique) labels for your filesystems, create noauto fstab entries (in this case using UUIDs) for stuff you want to manually appear when you "mount /mnt/thingamajig"

If you're using GPT partitions, those have names too. (by-partlabel)

----------

## NeddySeagoon

There is a problem with the existing /dev/disk/by*/* names.

As they are all symlinks, they don't exist until udev creates them.  That opens the door to localmount trying to use them before they have been created during bootup.

Its not a problem right now but that's probably just luck.

Do not /dev/disk/by*/* names in /etc/fstab.

PARTUUID=, UUID= and LABEL= all work.  

Then you don't care about physical device names and names changing.  Everything ends up on the right mountpoint anyway, which is what matters.

----------

## lesha_n

Thank you for the pointers. I found excellent articles for Arch Linux on fstab and Persistent block device naming. I imagine most of this info is directly relevant to Gentoo. Is there anything like this but Gentoo-specific? 

Cheers

----------

## NeddySeagoon

lesha_n,

That link is not distro specific, so its correct for Gentoo too.

----------

## szatox

Persistent naming by udev ain't persistent enough  :Laughing:  I remember the pain caused by a similar bug* introduced to network devices.

Just use either labels for human-readable names or uuids for unique, machine-only IDs.

* I don't consider behaviour a feature based solely on that behaviour being documented. Insane behaviour that has been documented is something I call "a known bug"

----------

## frostschutz

 *Quote:*   

> Persistent naming by udev ain't persistent enough

 

For example?

At least it uses disk serial numbers and such things. Works regardless where you plug those disks in, so that seems quite persistent to me.

 *Quote:*   

> I remember the pain caused by a similar bug* introduced to network devices.

 

I agree the network device thing (enp8s2 or whatever) is just silly. That is most similar to /dev/disk/by-path which is rarely useful. I turn those off everywhere.

Should have used the MAC Address instead of the pci path. MAC Address is a mouthful but same goes for /dev/disk/by-uuid.

----------

## szatox

For example when they simply changed the algorithm generating those names completely breaking any scripts that relied on _persistent_ names.

Also, as you mentioned *by-path*, deriving names from slot is a horrible mistake, but udev used to do that anyway. With PCI devices this is a minor concern, but you can't rely on user plugging some particular device into only one, arbitrarily chosen USB port.

Perhaps the authors learnt their lesson and gave up on such smart approach so it's actually persistent now (if not "predictable", what I'd rather see instead), but I have definitely learnt mine. LABELs and UUIDs work just fine. There is no need to make things more complex by renaming devices just for sake of renaming them.

----------

## Logicien

I have two internal sata hard drives who are always named sda and sdb. It respect the Sata connector number they use. I have 3 Usb keys and one Sd card. The Sd card is always named sdi but the Usb keys change their names between sdc, sdd and sde according to the Usb connector they are plugged in.

I have created Udev rules who symlink each external block device to a unique name I can remember using their serial numbers, vendor and product Id's to create the rules. So, no matter how Udev named them I can access the good Usb key using those personnal symlinks names. If I prefer, I can use the lsblk command to find their Udev names.

----------

## lesha_n

Thanks to frostschutz, NeddySeagoon, szatox and all for weighing in on this. My take-away message is that trying to work directly with the kernel block names (/dev/*) and trying to control their naming through udev rules is not worth it anymore: it seems cumbersome and not completely reliable. It appears that the recommended way for putting together /etc/fstab is to use partition labels (LABEL, PARTLABEL for GPT disks) or UUIDs (UUID, PARTUUID for GPT disks), which provide a level of abstraction over the kernel assigned names. The ArchWiki page cited above is an excellent source of info on that.

----------

