Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[gentoo-user] Rename /dev/nvme0n1 to /dev/sda

2,425 views
Skip to first unread message

Grant

unread,
Sep 1, 2017, 12:20:03 PM9/1/17
to
My new laptop uses /dev/nvme0n1 instead of /dev/sda which conflicts
with the script I use to manage about 12 similar laptops running
Gentoo. Is there a udev method for renaming the disk that will work
well with any USB disks that happen to also be attached?

crw------- 1 root root 252, 0 Aug 31 11:34 /dev/nvme0
brw-rw---- 1 root disk 259, 0 Aug 31 11:34 /dev/nvme0n1
brw-rw---- 1 root disk 259, 1 Aug 31 11:34 /dev/nvme0n1p1
brw-rw---- 1 root disk 259, 2 Aug 31 11:34 /dev/nvme0n1p2

- Grant

R0b0t1

unread,
Sep 1, 2017, 11:00:04 PM9/1/17
to
Admittedly I don't know how to do what you are asking, but my
experience has shown me the better solution is likely to modify your
management script and to store the device-specific configuration
external to the script and associate it with the device.

R0b0t1.

Andrew Savchenko

unread,
Sep 2, 2017, 2:50:04 AM9/2/17
to
On Fri, 1 Sep 2017 09:10:13 -0700 Grant wrote:
> My new laptop uses /dev/nvme0n1 instead of /dev/sda which conflicts
> with the script I use to manage about 12 similar laptops running
> Gentoo. Is there a udev method for renaming the disk that will work
> well with any USB disks that happen to also be attached?

Yes, you can write an udev rule to create any names or symlinks you
want on any events selected by triggers. See
http://www.reactivated.net/writing_udev_rules.html
and udev docs.

Best regards,
Andrew Savchenko

Canek Peláez Valdés

unread,
Sep 2, 2017, 9:20:04 AM9/2/17
to

On Fri, Sep 1, 2017 at 11:10 AM, Grant <email...@gmail.com> wrote:
>
Isn't so much easier to use labels? Those are automatically available on /dev/disk/by-label, and you can use them in basically any type of partition, including Windows (NTFS and vfat) and swaps.

Regards.
--
Dr. Canek Peláez Valdés
Profesor de Carrera Asociado C
Departamento de Matemáticas
Facultad de Ciencias
Universidad Nacional Autónoma de México

Mike Gilbert

unread,
Sep 2, 2017, 10:40:03 AM9/2/17
to
On Fri, Sep 1, 2017 at 12:10 PM, Grant <email...@gmail.com> wrote:
> My new laptop uses /dev/nvme0n1 instead of /dev/sda which conflicts
> with the script I use to manage about 12 similar laptops running
> Gentoo. Is there a udev method for renaming the disk that will work
> well with any USB disks that happen to also be attached?

I'm not certain what you mean by that, but I would guess that you want
the nvme disk to show up as /dev/sda, and the USB disk(s) to show up
as /dev/sd[b-z].

It is not possible to accomplish this using udev; the kernel owns the
/dev/sdX device namespace, and will sequentially create devices nodes
for SCSI-like block devices using that namespace. There is no way to
change that using a udev rule.

Grant

unread,
Sep 3, 2017, 2:00:04 PM9/3/17
to
>> My new laptop uses /dev/nvme0n1 instead of /dev/sda which conflicts
>> with the script I use to manage about 12 similar laptops running
>> Gentoo. Is there a udev method for renaming the disk that will work
>> well with any USB disks that happen to also be attached?
>>
>> crw------- 1 root root 252, 0 Aug 31 11:34 /dev/nvme0
>> brw-rw---- 1 root disk 259, 0 Aug 31 11:34 /dev/nvme0n1
>> brw-rw---- 1 root disk 259, 1 Aug 31 11:34 /dev/nvme0n1p1
>> brw-rw---- 1 root disk 259, 2 Aug 31 11:34 /dev/nvme0n1p2
>
> Isn't so much easier to use labels? Those are automatically available on
> /dev/disk/by-label, and you can use them in basically any type of partition,
> including Windows (NTFS and vfat) and swaps.


Do labels work with root= in grub and stuff like dd, fdisk, and mkfs?

- Grant

Canek Peláez Valdés

unread,
Sep 3, 2017, 2:20:03 PM9/3/17
to
The label by itself works at boot since it's just another kernel parameter; for example in my latop (that uses NVME, by the way) uses the following in the kernel command line: "root=LABEL=Dell".

For all the other utilities you mention the label by itself probably doesn't work, but the links in /dev/disk/by-label are just symlinks to the corresponding disks and partitions, so every single Unix utility works with them. My links are like so:

dell ~ # ll /dev/disk/by-label/
total 0
lrwxrwxrwx 1 root root 15 Aug 29 06:20 Dell -> ../../nvme0n1p2
lrwxrwxrwx 1 root root 15 Aug 29 06:20 EFI -> ../../nvme0n1p1
lrwxrwxrwx 1 root root 15 Aug 29 06:20 Swap -> ../../nvme0n1p3

And so /dev/disk/by-label/Dell is just the second partition of the first NVME disk (or chip, or wathever). They work with anything, execept with fdisk because there are no labels for whole disks, only for partitions.

Grant

unread,
Sep 3, 2017, 2:20:03 PM9/3/17
to
Can I rename /dev/sda to /dev/sd[b-z] if it's attached via USB, and
then rename /dev/nvme0n1 to /dev/sda if /dev/nvme0n1 exists?

Alternatively, can I rename /dev/sda to /dev/sd[b-z] if /dev/sda and
/dev/nvme0n1 exist, and then rename /dev/nvme0n1 to /dev/sda if
/dev/nvme0n1 exists?

- Grant

Mike Gilbert

unread,
Sep 3, 2017, 6:30:04 PM9/3/17
to
You might technically be able to do it, but I would guess it would
cause some nasty race conditions between the kernel and udev. It's a
bad idea.

Grant

unread,
Sep 3, 2017, 6:50:04 PM9/3/17
to
Is it the conditionals that cause this to be a bad idea? Because I
believe udev has functionality designed to rename devices exactly like
this.

- Grant

Mike Gilbert

unread,
Sep 3, 2017, 9:30:03 PM9/3/17
to
udev doesn't provide any functionality to rename device nodes. You can
adjust their permissions, and create symlinks, but there is no direct
way to rename them.

To rename a device node in a udev rule, you would have to call an
external command, which udev knows nothing about. After having renamed
it this way, the information in the udev device database would no
longer be consistent, and any future device events would not work
properly.

I would suggest you utilize the existing symlinks in one of the
/dev/disk/ sub-directories, or create some udev rules to create your
own symlinks based on whatever metadata you wish. I would also suggest
you read the udev(7) manual page.

Trying to coerce your nvme device to look like an sd device is really
the wrong approach to solving your problem.

Rich Freeman

unread,
Sep 3, 2017, 9:40:04 PM9/3/17
to
On Sun, Sep 3, 2017 at 9:26 PM, Mike Gilbert <flo...@gentoo.org> wrote:
>
> I would suggest you utilize the existing symlinks in one of the
> /dev/disk/ sub-directories, or create some udev rules to create your
> own symlinks based on whatever metadata you wish. I would also suggest
> you read the udev(7) manual page.
>

++

Labels are the most obvious solution to this sort of problem
(especially if you want a generic system image that you can install in
multiple places and not have to tweak). UUIDs are the other obvious
solution, but that does need to be tailored to each install.

I have used extra symlinks with udev in other situations. For
example, I used to control two tuners via pl2303 serial ports and I
used a rule to add a symlink based on the physical USB port each was
plugged into, since otherwise I couldn't rely on the two devices being
enumerated consistently.

--
Rich

J. Roeleveld

unread,
Sep 4, 2017, 12:30:03 AM9/4/17
to
On 3 September 2017 20:11:51 GMT+02:00, "Canek Peláez Valdés" <can...@gmail.com> wrote:
>On Sun, Sep 3, 2017 at 7:59 PM, Grant <email...@gmail.com> wrote:
>>
>> >> My new laptop uses /dev/nvme0n1 instead of /dev/sda which
>conflicts
>> >> with the script I use to manage about 12 similar laptops running
>> >> Gentoo. Is there a udev method for renaming the disk that will
>work
>> >> well with any USB disks that happen to also be attached?
>> >>
>> >> crw------- 1 root root 252, 0 Aug 31 11:34 /dev/nvme0
>> >> brw-rw---- 1 root disk 259, 0 Aug 31 11:34 /dev/nvme0n1
>> >> brw-rw---- 1 root disk 259, 1 Aug 31 11:34 /dev/nvme0n1p1
>> >> brw-rw---- 1 root disk 259, 2 Aug 31 11:34 /dev/nvme0n1p2
>> >
>> > Isn't so much easier to use labels? Those are automatically
>available on
>> > /dev/disk/by-label, and you can use them in basically any type of
>partition,
>> > including Windows (NTFS and vfat) and swaps.
>>
>>
>> Do labels work with root= in grub and stuff like dd, fdisk, and mkfs?
>
>The label by itself works at boot since it's just another kernel
>parameter;
>for example in my latop (that uses NVME, by the way) uses the following
>in
>the kernel command line: "root=LABEL=Dell".

Since when does the kernel support labels? Last time I checked, you need an initramfs to make that work.

--
Joost



--
Sent from my Android device with K-9 Mail. Please excuse my brevity.

Canek Peláez Valdés

unread,
Sep 4, 2017, 1:10:03 AM9/4/17
to


On Mon, Sep 4, 2017 at 6:26 AM, J. Roeleveld <jo...@antarean.org> wrote:
> On 3 September 2017 20:11:51 GMT+02:00, "Canek Peláez Valdés" <can...@gmail.com> wrote:
[ ... ]

> >The label by itself works at boot since it's just another kernel
> >parameter;
> >for example in my latop (that uses NVME, by the way) uses the following
> >in
> >the kernel command line: "root=LABEL=Dell".
>
> Since when does the kernel support labels? Last time I checked, you need an initramfs to make that work.

You are absolutely right; the kernel only supports "PARTUUID=" out-of-the-box (/usr/src/linux/init/do_mounts.c:218), the "LABEL=" ids are implemented by the initramfs, dracut in my case (/usr/lib/dracut/modules.d/98dracut-systemd/rootfs-generator.sh:87).

The "LABEL=" id  gets translated to the corresponding /dev/disks/by-label link, so those are the ones that should be used all the time.

Thanks for the clarification.

Grant

unread,
Sep 4, 2017, 11:00:03 AM9/4/17
to
>> I would suggest you utilize the existing symlinks in one of the
>> /dev/disk/ sub-directories, or create some udev rules to create your
>> own symlinks based on whatever metadata you wish. I would also suggest
>> you read the udev(7) manual page.
>>
>
> ++
>
> Labels are the most obvious solution to this sort of problem
> (especially if you want a generic system image that you can install in
> multiple places and not have to tweak). UUIDs are the other obvious
> solution, but that does need to be tailored to each install.


In order to use labels for this, I would need to label each of my
potentially-connected devices, correct?

- Grant

Grant

unread,
Sep 4, 2017, 11:10:04 AM9/4/17
to
I use stuff like this to rename my USB devices and it works perfectly:

SUBSYSTEM=="net", ACTION=="add", ENV{ID_NET_NAME_PATH}=="enp0s20u2u1",
NAME="net0"

Isn't this a true rename of the device node?

- Grant

J. Roeleveld

unread,
Sep 4, 2017, 11:40:03 AM9/4/17
to
For network devices I tend to use the MAC addresses.

USB devices get a different name if you plug it into a different port.

Mike Gilbert

unread,
Sep 4, 2017, 11:50:04 AM9/4/17
to
Network devices don't have device nodes. They have interface names,
which are a different concept entirely.

Grant

unread,
Sep 4, 2017, 3:30:03 PM9/4/17
to
OK I'll take your advice and change the script to detect /dev/nvme0n1.

- Grant
0 new messages