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 ?