Linux, how to know the current boot disk

bootlinux

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 like blkid /dev/sda to find out the UUID of sda 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

  • that's the bootloader's job - which runs before the kernel is running - to load the kernel into memory.
  • anything that's not in the kernel needed at boot is in the initramfs (initrd), such as drivers, early userland utilities - loading this is also the bootloader's job.

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 couple grep's and cut'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.