1
Is there a way to detect the current boot media used to boot a Linux Live OS? In a live OS system, I would like to uniquely determine the current boot media(CD/USB) that has been used to boot the disk. I would like to determine this at the OS level not at the bootloader level.
Current boot media in my case means the media where the boot loader that was used to start the OS resides.
I have inspected the following but none seem to have the information of the dev path of current boot media (like for instance /dev/sr0 indicating current boot path is cd)
- Checking systemd journalctl logs.
- Checking dmesg logs.
- Possible interfaces in udev and udevadm utility.
- Busybox rdev like suggested in http://free-electrons.com/blog/find-root-device/. The procedure to compare stat / with that of major:minor device number of /dev/sr0 doesn't seem to match.
I also checked in GRUB2, http://git.savannah.gnu.org/cgit/grub.git/tree/grub-core/kern/i386/pc/init.c where the GRUB environment variables root and prefix are set. For instance, on a GRUB2 shell that was booted from a CD, if I type echo $root, I get hd31. Now how do I do a mapping of this to a Linux block device path like /dev/sr0 for CD or some /dev/sdb1 for a pen drive? I also checked Linux: get the current boot disk's device name and https://stackoverflow.com/questions/6787819/how-to-determine-the-booting-device but both of it don't seem to help.
Ideally I would want to avoid mounting every CD/USB (/dev/sr0 or /dev/sdb1 and the like) to manually check for the presence of initrd and kernel files. This method isn't foolproof. Is there any straightforward way to do this ?
Please [edit] to clarify "boot media" in the context of this question. Is it the media on which the boot manager that was used to bootstrap the system is installed? Is it the media that the running kernel binary is stored on? (In principle, then, what if the running kernel's binary has been deleted? That's valid.) Is it the media on which the originally mounted root file system resides? Is it the media on which the currently mounted root file system resides? Is it the media on which the /boot directory resides? Or what? All of these could be valid answers to "which boot media was used?". – a CVn – 2015-09-30T08:15:25.303
For the moment, I have voted to put this question on hold as unclear, simply because "current boot media" can have so many different meanings and the answers are likely to be different for each variant. If you edit your question to clarify exactly which portion of the boot process you are interested in, this should be quite answerable and (if put on hold in the interim) get reopened fairly quickly. – a CVn – 2015-09-30T08:16:58.553
@MichaelKjörling: I have the bootloader, initrd and kernel on the media, CD or USB. After I select the boot media at BIOS, GRUB kicks in and boots the kernel and the initrd is extracted to the Ramdisk. I simply want to mount the block device path of the CD/USB that corresponds to the one I selected at the BIOS. – 1337ninja – 2015-09-30T08:27:01.977
"I simply want to mount the block device path of the CD/USB that corresponds to the one I selected at the BIOS." So you want the device that corresponds to the boot loader's location? (GRUB, in your case, but not guaranteed in the general case even for Linux.) – a CVn – 2015-09-30T08:29:10.910
@MichaelKjörling: Yes. In my particular case all happens to be on the media, GRUB, initrd and the kernel. – 1337ninja – 2015-09-30T08:59:30.047
Not possible, which is why most Live Media have a magic file (of sorts) to help find it. – Daniel B – 2015-12-10T21:05:49.763