Linux – Ensure USB disk is never sda, even when booting from it

debianlinuxpreseed

Some Background…

I think this should be a general linux kernel (or kernel module) related question, though I'm facing the issue while preseeding debian for an automated installation.

Every time I boot the installer from a usb disk, the usb disk turns out to be /dev/sda, but the preseed file I'm using assumes the first hard disk (sata in this case) should be /dev/sda. I'm using the same system for a pxe network installation, and I would prefer to keep them consistent. I also fear that if I wrote a preseed config that assumed the first disk was sdb instead, that for some reason it might not be at some point.

I've tried writing udev rules that changes the device name of the usb disk to "INSTALLMEDIA" which seems to work, however it does not cause the SATA disk to start at sda, they still start at sdb.

My questions…

What determines the order that disks are discovered and named?

What, if anything, can I do to control this?

If I cannot do anything to control it, would it be safe to assume when booting from USB that the USB disk can be more or less guaranteed to be sda and the first SATA disk would always be sdb?

Best Answer

The most reliable answer to this question, that I'm aware of, is to use the newer symlinks that udev can create for you. Udev enumerates the disk drives, and creates several trees with devices - explaining for you what kind of devices they are.

This is located in /dev/disk.

You have, by-path:

/dev/disk/by-path/pci-0000:00:1a.0-usb-0:1.5:1.0-scsi-0:0:0:0-part1
/dev/disk/by-path/pci-0000:00:1a.0-usb-0:1.5:1.0-scsi-0:0:0:0
/dev/disk/by-path/pci-0000:06:00.0-scsi-0:0:0:0
/dev/disk/by-path/pci-0000:00:1f.2-scsi-1:0:0:0-part2
/dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0-part2
/dev/disk/by-path/pci-0000:00:1f.2-scsi-1:0:0:0-part1
/dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0-part1
/dev/disk/by-path/pci-0000:00:1f.2-scsi-0:0:0:0
/dev/disk/by-path/pci-0000:00:1f.2-scsi-1:0:0:0

Which clearly tells you if the device is a usb-device, for instance.