image-info: support images with empty partitions

Official RHEL EC2 images come with an empty partition, simply ignore
it rather than fail.

Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
Tom Gundersen 2019-11-24 16:41:31 +01:00
parent e73b43162d
commit eee08c41ac
12 changed files with 18 additions and 8 deletions

View file

@ -64,8 +64,9 @@ def read_partition(device, bootable, typ=None, start=0, size=0, type=None):
return {
"label": blkid.get("LABEL"), # doesn't exist for mbr
"type": typ,
"uuid": blkid["UUID"],
"fstype": blkid["TYPE"],
"uuid": blkid.get("UUID"),
"partuuid": blkid.get("PARTUUID"),
"fstype": blkid.get("TYPE"),
"bootable": bootable,
"start": start,
"size": size
@ -167,9 +168,10 @@ with nbd_connect(image) as device:
if report["partition-table"]:
n_partitions = len(report["partitions"])
for n in range(1, n_partitions + 1):
with mount(device + f"p{n}") as tree:
append_filesystem(report, tree)
for n in range(n_partitions):
if report["partitions"][n]["fstype"]:
with mount(device + f"p{n + 1}") as tree:
append_filesystem(report, tree)
else:
with mount(device) as tree:
append_filesystem(report, tree)