From bf3d7fcdca6e6bf40255959a9689bbaef67a845d Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Mon, 30 Sep 2019 11:34:47 +0200 Subject: [PATCH] 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 39b5b301a..c9c61d57c 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)