assembler/qemu: dynamically determine grub2 prefix

Instead of hard-coding "msdos1", determine this partition id
dynamically based on the partition table type and the index
of the partition that contains /boot/grub2, which normally is
either a separate boot partition or the root partition. In
order to be able to do so, set the index of each Partition
when the partition information is read back via `sfdisk`.
NB: partition indexes start at 1 for grub2.
This commit is contained in:
Christian Kellner 2019-12-22 16:15:49 +01:00 committed by Tom Gundersen
parent 33078bf1df
commit e12667914a

View file

@ -197,6 +197,7 @@ class Partition:
self.bootable = bootable
self.name = name
self.filesystem = filesystem
self.index = None
@property
def start_in_bytes(self):
@ -289,6 +290,7 @@ class PartitionTable:
assert len(disk_parts) == len(self.partitions)
for i, part in enumerate(self.partitions):
part.index = i
part.start = disk_parts[i]["start"]
part.size = disk_parts[i]["size"]
part.type = disk_parts[i].get("type")
@ -365,12 +367,18 @@ def install_grub2(image: str, pt: PartitionTable):
else:
raise ValueError(f"unknown boot filesystem type: '{fs_type}'")
# identify the partition containing boot for grub2
if pt.label == "dos":
partid = "msdos" + str(boot_part.index + 1)
else:
raise ValueError(f"unsupported partition type: '{pt.label}'")
# now created the core image
subprocess.run(["grub2-mkimage",
"--verbose",
"--directory", "/usr/lib/grub/i386-pc",
"--prefix", "(,msdos1)/boot/grub2",
"--format", "i386-pc",
"--prefix", f"(,{partid})/boot/grub2",
"--compression", "auto",
"--output", grub2_core] +
modules,