[olug] Weird Internal HDD Question

Lou Duchez lou at paprikash.com
Fri Oct 28 15:38:37 UTC 2011


The odds are best expressed as "inevitable".  Not long ago my server 
booted up while I had a USB drive plugged in, and the USB picked up 
"sda" while the internal picked up "sdb".  Apparently it all has to do 
with whichever one Linux initializes first, and that involves concurrent 
processes.  It's a random thing.

If you can find a way to force sda and sdb to be mapped to specific 
devices, I'd love to hear about it.

In the meantime, the only answer I can find is that you can assign 
symbolic links to your drives, and then you can make sure to refer to 
the drives by symbolic links rather than by the "sdN" label that Linux 
assigns.  Here are the notes I recorded on how to do it:

---

1) Figure out which drive is your main drive, by running "df" and 
looking for the line that has "/boot" in it. That is the partition you 
boot from. If the partition is listed as "/dev/sda1", then the drive 
itself is "sda".

2) Run "udevadm info --query=env --name=sda | grep ID_SERIAL=". (Change 
"sda" to "sdb" or whatever if you need to.) This gives you the serial number

3) Create /etc/udev/rules.d/aa-local.rules, and put these lines in it 
(replace "SerialNumber" with the serial number from step 2):

KERNEL=="sd[a-z]", SUBSYSTEM=="block", ENV{ID_SERIAL}=="SerialNumber", 
SYMLINK+="bootdrive"
KERNEL=="sd[a-z][1-9]", SUBSYSTEM=="block", 
ENV{ID_SERIAL}=="SerialNumber", SYMLINK+="bootdrive%n"

4) Reboot the computer; you will now have a symbolic link 
"/dev/bootdrive" that points to "/dev/sda", and symbolic links 
"/dev/bootdrive1", "/dev/bootdrive2", etc. that point to partitions.

Incidentally, with regard to my USB drive, I've actually got two 
identical drives that I swap out for the sake of off-site backups.  I 
want to treat them interchangeably for backup purposes, so instead of 
"ID_SERIAL" I use "ID_MODEL" to recognize them by model number, and that 
works just fine.

> Hey all
>
> strange question time.
>
> What are the odds of an internal HDD being referenced as something other
> than sda in today's world?
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> https://lists.olug.org/mailman/listinfo/olug




More information about the OLUG mailing list