From 53fe311bcd066671770f383db6400a6107ef8d28 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Sat, 24 Aug 2019 23:26:51 +0200 Subject: [PATCH] assembler/qcow2: copy the tree into the target image We used to let mkfs.ext4 initialize the filesystem for us, but it turns out that the metadata attributes of the root directory were not being initialized from the source tree. In particular, this meant that the SELinu labels were left as unconfined_t, rather than root_t, which would not allow us to boot in enforcing mode. An alternative approach might be to fixup the root inode manually, while still doing the rest using mkfs.ext4, but let's leave that for the future if it turns out to be worth it. Signed-off-by: Tom Gundersen --- assemblers/org.osbuild.qcow2 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/assemblers/org.osbuild.qcow2 b/assemblers/org.osbuild.qcow2 index 60ec860f..f68e9d4b 100755 --- a/assemblers/org.osbuild.qcow2 +++ b/assemblers/org.osbuild.qcow2 @@ -71,13 +71,15 @@ def main(tree, output_dir, options, loop_client): # Populate the first partition of the image with an ext4 fs and fill it with the contents of the # tree we are operating on. - subprocess.run(["mkfs.ext4", "-d", tree, "-U", root_fs_uuid, "-E", f"offset={partition_offset}", image, + subprocess.run(["mkfs.ext4", "-U", root_fs_uuid, "-E", f"offset={partition_offset}", image, f"{int(partition_size / 1024)}k"], input="y", encoding='utf-8', check=True) # Mount the created image as a loopback device with loop_device(loop_client, image, partition_offset) as loop_block, \ loop_device(loop_client, image, partition_size, partition_offset) as loop_part, \ mount(loop_part, mountpoint): + # Copy the tree into the target image + subprocess.run(["cp", "-a", f"{tree}/.", mountpoint], check=True) # Install grub2 into the boot sector of the image, and copy the grub2 imagise into /boot/grub2 with mount_api(mountpoint): subprocess.run(["chroot", mountpoint, "grub2-install", "--no-floppy",