From dc25fb3e4240a23c4e574110ed61ad46628edac7 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Mon, 16 Dec 2019 16:50:57 +0100 Subject: [PATCH] assembler/qemu: helper to root fs partition Introduce a method on the PartitionTable that returns the partition containing the root filesystem. NB: this does not have to be the first partition (which could be the EFI partition, or something else), so we have to iterate through the partitions until we find it. --- assemblers/org.osbuild.qemu | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/assemblers/org.osbuild.qemu b/assemblers/org.osbuild.qemu index 3830f67d..5987db85 100755 --- a/assemblers/org.osbuild.qemu +++ b/assemblers/org.osbuild.qemu @@ -236,6 +236,13 @@ class PartitionTable: parts_fs = filter(lambda p: p.filesystem is not None, self.partitions) return sorted(parts_fs, key=mountpoint_len) + def partition_containing_root(self) -> Partition: + """Return the partition containing the root filesystem""" + for p in self.partitions: + if p.mountpoint and p.mountpoint == "/": + return p + return None + def write_to(self, target, sync=True): """Write the partition table to disk""" # generate the command for sfdisk to create the table @@ -318,11 +325,8 @@ def install_grub2(image: str, pt: PartitionTable): """Install grub2 to image""" grub2_core = "/var/tmp/grub2-core.img" - root_fs_type = "unknown" - for p in pt: - if p.mountpoint and p.mountpoint == "/": - root_fs_type = p.fs_type - break + root_part = pt.partition_containing_root() + root_fs_type = root_part.fs_type or "unknown" if root_fs_type == "ext4": fs_module = "ext2"