Let's assume that a PC contains several storage devices and we have C++/Qt utility which contains 2 blackbox functions (we don't consider their implementation here):
QString get_disk_serial(int drive_number); //for Windows
QString get_disk_serial(const QString& device); //for Linux. For example, "/dev/sda"
I need to know (using C++) which disk is used in the current session (what disk number is active/what device name is active). In my context active disk is a disk which contains the partition, which in turn contains running operating system.
I fear that you're trapped thinking in very Microsoft-ish terms.
"The partition with the operating system" makes very little sense on a Unix machine. You have /boot
with the kernel image, /usr
with the userspace tools and libraries, /opt
with optional userspace tools / libs, /etc
with all the settings... you need all of those (well, except perhaps for /opt
), and they can be located on individual partitions. Which one is "the operating system"?
And Unix does not require the boot partition to be "active" (i.e., flagged active in the partition table) either.
I am frequently working on (virtual) servers where I can't even see the partition the kernel is being booted from, or systems where /boot
is unmounted after the boot process. Then there's the Logical Volume Manager, at which point things get really interesting...
All in all, "active partition" simply does not make sense outside of MS Windows. (Perhaps not even there anymore.) Even AmigaOS could comfortably be spread across multiple volumes back in 1985... ("Please insert volume LIBS: in any drive.")
If you think you know the answer to what constitutes "the operating system", you could inspect the mount table to find which device a specific part of the file system hierachy is located on. Both the output format of the mount
command and the location of any on-file reference of the mount table is, however, platform-specific. (/etc/mtab
and the output of mount
on Linux are identical, but /etc/filesystems
and the output of mount
on AIX are quite different, both from each other and the Linux version of things.)