0
votes

From the list of devices like /dev/sg0 or /dev/sg1 I would like to find which is boot drive in linux.

For different machines getting different type of values.

Case 1:

device = subprocess.check_output(["sudo", "sg_map26", "/dev/sg0"]) which will provide mount path for drives like this “/dev/sda”(for /dev/sg0) or “/dev/sdb”(for dev/sg1).

Out of these two which is the boot drive mount path when I used device path like above?

Case2:

xyx@myhost:~$ mount | grep -E '(/|/boot) '
/dev/sda1 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)

How to map with device path to identify?

But this command is returning LVM2 value for some of the clients like below

case3:

xyz@myhost:~$ mount | grep -E '(/|/boot) '
“/dev/mapper/ubuntu—vg--root”

So its difficult to map with the device path to find which is the boot device when system booted with LVM2.

It would be helpful if you can help to find boot drive with given device path.Thanks!

1

1 Answers

0
votes
from subprocess import check_output

df = check_output(['df']).decode()
dflines = df.split('\n')
for line in dflines:
        if '/boot' in line:
                print(line.split(' ')[0])

This gives the name of the block device / partition which linux booted from. tested with python 3.8 on debian 9