From decb8215f950bb4a299edf2907fe6a81402b9a32 Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Mon, 30 Sep 2019 11:33:22 +0200 Subject: [PATCH 1/3] image-info: assume bootable=False if key is not present sfdisk doesn't include the "bootable" key in its output when a partition is not marked as bootable. --- tools/image-info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/image-info b/tools/image-info index 7cb3bd2073..4575b76915 100755 --- a/tools/image-info +++ b/tools/image-info @@ -52,7 +52,7 @@ def read_partition_table(device): for p in ptable["partitions"]: partitions.append({ "type": p["type"], - "bootable": p["bootable"], + "bootable": p.get("bootable", False), "start": p["start"] * 512, "size": p["size"] * 512 }) From 69230d9af05312007d0101e44d42e4cccbd27b0a Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Mon, 30 Sep 2019 11:34:08 +0200 Subject: [PATCH 2/3] image-info: bootloader=unknown instead of creashing --- tools/image-info | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/image-info b/tools/image-info index 4575b76915..39b5b301aa 100755 --- a/tools/image-info +++ b/tools/image-info @@ -65,7 +65,7 @@ def read_bootloader_type(device): if b"GRUB" in f.read(512): return "grub" else: - raise RuntimeError("unkown bootloader") + return "unknown" def read_os_release(tree): From 3c6910cfc05885fb24126efaca76c331462c84f2 Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Mon, 30 Sep 2019 11:34:47 +0200 Subject: [PATCH 3/3] image-info: add basic support for multiple partitions For each partition, find out if its the root or boot partition and gather only the relevant information. Make sure that we don't get information from /boot twice. --- tools/image-info | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/tools/image-info b/tools/image-info index 39b5b301aa..c9c61d57c5 100755 --- a/tools/image-info +++ b/tools/image-info @@ -87,23 +87,32 @@ with nbd_connect(image) as device: report["bootloader"] = read_bootloader_type(device) report["partition_table"], report["partitions"] = read_partition_table(device) - # only one partition containing the root filesystem supported for now - assert len(report["partitions"]) == 1 + n_partitions = len(report["partitions"]) - with mount(device + "p1") as tree: - report["packages"] = sorted(subprocess_check_output(["rpm", "--root", tree, "-qa"], str.split)) - report["os_release"] = read_os_release(tree) - with open(f"{tree}/etc/fstab") as f: - report["fstab"] = sorted([line.split() for line in f.read().split("\n") if line and not line.startswith("#")]) + for n in range(1, n_partitions + 1): + with mount(device + f"p{n}") as tree: + # subprocess.run(["ls", "-l", tree]) + if os.path.exists(f"{tree}/etc/os-release"): + report["packages"] = sorted(subprocess_check_output(["rpm", "--root", tree, "-qa"], str.split)) + report["os_release"] = read_os_release(tree) - with open(f"{tree}/etc/passwd") as f: - report["passwd"] = sorted(f.read().strip().split("\n")) + with open(f"{tree}/etc/fstab") as f: + report["fstab"] = sorted([line.split() for line in f.read().split("\n") if line and not line.startswith("#")]) - with open(f"{tree}/etc/group") as f: - report["groups"] = sorted(f.read().strip().split("\n")) + with open(f"{tree}/etc/passwd") as f: + report["passwd"] = sorted(f.read().strip().split("\n")) - report["bootmenu"] = [read_bls_conf(f) for f in glob.glob(f"{tree}/boot/loader/entries/*.conf")] + with open(f"{tree}/etc/group") as f: + report["groups"] = sorted(f.read().strip().split("\n")) + + if os.path.exists(f"{tree}/boot") and len(os.listdir(f"{tree}/boot")) > 0: + assert "bootmenu" not in report + report["bootmenu"] = [read_bls_conf(f) for f in glob.glob(f"{tree}/boot/loader/entries/*.conf")] + + elif len(glob.glob(f"{tree}/vmlinuz-*")) > 0: + assert "bootmenu" not in report + report["bootmenu"] = [read_bls_conf(f) for f in glob.glob(f"{tree}/loader/entries/*.conf")] json.dump(report, sys.stdout, sort_keys=True, indent=2)