Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
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. >> >> >> 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? > > 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. 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. >>> >>> 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. >> >> >> 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? > > Network devices don't have device nodes. They have interface names, > which are a different concept entirely. OK I'll take your advice and change the script to detect /dev/nvme0n1. - Grant
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
On Mon, Sep 4, 2017 at 11:00 AM, 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? >> >> 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. > > > 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? 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. >>> >>> >>> 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. >> >> 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. > > > 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? Network devices don't have device nodes. They have interface names, which are a different concept entirely.
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
On 4 September 2017 17:00:30 GMT+02:00, 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? >> >> 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. > > > 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? 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. >>> >>> >>> 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. >> >> 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. > > >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 For network devices I tend to use the MAC addresses. USB devices get a different name if you plug it into a different port. -- Joost -- Sent from my Android device with K-9 Mail. Please excuse my brevity.
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
>> 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. 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? >>> >>> 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. >> >> >> 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. > > 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. 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
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
>> 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
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
On Mon, Sep 4, 2017 at 6:26 AM, J. Roeleveld 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. 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
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
On 3 September 2017 20:11:51 GMT+02:00, "Canek Peláez Valdés" wrote: >On Sun, Sep 3, 2017 at 7:59 PM, 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? >> >> >> >> 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.
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
On Sun, Sep 3, 2017 at 9:26 PM, Mike Gilbert 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
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
On Sun, Sep 3, 2017 at 6:41 PM, 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? 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. >>> >>> >>> 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? >> >> 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. > > > 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. 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.
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
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. >> >> >> 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? > > 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. 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
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
On Sun, Sep 3, 2017 at 2:11 PM, 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? >> >> 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. > > > 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? 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.
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
On Sun, Sep 3, 2017 at 7:59 PM, 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? > >> > >> 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". 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. 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
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
>> 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. 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
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
>> 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
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
On Fri, Sep 1, 2017 at 12:10 PM, 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? 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.
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
On Fri, Sep 1, 2017 at 11:10 AM, 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? > > 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. 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
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
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 pgpzaY5zG6AW0.pgp Description: PGP signature
Re: [gentoo-user] Rename /dev/nvme0n1 to /dev/sda
On Fri, Sep 1, 2017 at 11:10 AM, 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? > > 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 > 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.