Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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.

share|improve this answer
1  
This is extremely helpful, although I'm a bit worried about being able to reliably predict the correct pci or scsi address on my preseed config, but this might give me something to work with. –  andyortlieb Oct 19 '11 at 16:36
3  
You got other lookup-methods in the /dev/disk directory as well - maybe by-id or by-label is useful to you? –  Kvisle Oct 19 '11 at 16:48
    
This would work if there was something like by-type/ata-1, but the other lookups are just too complex and subject to change. But you definitely won me over by bringing this to my attention, I've already found two other uses for it. –  andyortlieb Oct 26 '11 at 20:00

The other option would be to create your own symlink (or even a device file) if you can run some sort of script before you actually need to access the device. Something like

#!/bin/sh
for i in  /dev/sd? ; do 
  if detect installation drive somehow ; then ln -s $i /dev/install ; fi ; 
done ;

And as a very last resort solution you could "swap" the sda,sdb,... device files in /dev, but I would try hard to avoid this solution as it could introduce a lot of new problems.

share|improve this answer
    
I just could move them all down with the udev rules instead. I was just hoping for something more reliable, like a kernel switch or blacklisting a module to disable loading USB storage or something. That would allow me to use my same installer on PXE without making assumptions about what order the disks are plugged in. –  andyortlieb Oct 26 '11 at 20:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.