I have an application developed to run on multiple platforms where the boot disk is either '/dev/nftla1' or 'dev/hdc1'. The Grub bootloader has this information.
But once the kernel takes over & the application starts running, it becomes irrelevant. But, in my application which is mainly in 'C', I would like to know the source of boot because the way the files are accessed is different on these platforms.
My question is: Is there a system command or any tricks that you know that could help with what I am trying to achieve?
You can get what you are looking for under
/proc/mounts
For example:
instead of
/dev/disk/by-uuid/<uuid>
, it can be/dev/disk/by-label/<label>
,/dev/disk/by-id/<id>
or/dev/disk/by-path/<path>
and then
Hope the above is useful in your application.
You can pass kernel boot options from grub and then check them.
More info.
UPDATE: You can use this C code to parse
/proc/cmdline
:Check where
/
is mounted.(Actually, from your description, I guess you should look where the directory you are reading from is mounted. That is not necessarily the boot drive.)
EDIT
You're using rootfs, which means the above won't help you. (It also means I understand even less why you need to find out where you booted from, but let's leave that aside.)
Alexander already pointed to
/proc/cmdline
. Just for completeness, I thought I'd offer yet another option: You could look through the boot messages:(Note that in the
df
command above, you should replace the/tmp/
with the directory where you are reading from.)