I've a Linux Centos (5.0) machine with 2 disks. I was changing the SATA cable to one of the disk when I realized that depending on what SATA slot I'm using, the OS starts from sda or sdb.
The problem is that I have daily backups from sda to sdb (merely copies), if by accident someone change the SATA cable, I will screw up and overwrite new data with old data.
The only thing that I know is, that current boot disk is the good one. How I can certainly know which disk is the current boot disk (sda or sdb)?
Additional info: I've no physical access to the machine.
Best Answer
First, use disk UUIDs like @grawity said.
If you want to know the UUIDs of everything that looks like a block device to Linux, use the
blkid
command. I think you can do something likeblkid /dev/sda
to find out the UUID ofsda
as well.Another thing you can do is use the symlinks in
/dev/disk/by-id
which are created for each disk based on the bus it's connected to and its reported model and serial number.Technically, Linux doesn't know or care about the device it was loaded from, because
Now, after Linux loads, boot scripts or whatever other mechanism running under the kernel tries to mount a root file system so you have other things to run besides the kernel, as well as swap, etc. Basically all the stuff in your
/etc/fstab
. This is what you really care about and that file will have the information you need. You can use UUIDs in/etc/fstab
(and I believe most distributions already use them) - so with a couplegrep
's andcut
's you can get UUIDs out of here that you want.Example (this probably can be done better):
cat /etc/fstab | grep "/ " | cut -f 1 -d " "
And you can use the output of that for
blkid
to find the UUID of your root file system or whatever other partition.