diff --git a/assemblers/org.osbuild.qemu b/assemblers/org.osbuild.qemu index dbd50963..b2ce3f2f 100755 --- a/assemblers/org.osbuild.qemu +++ b/assemblers/org.osbuild.qemu @@ -107,7 +107,7 @@ SCHEMA = """ "type": { "description": "Type of the filesystem", "type": "string", - "enum": ["ext4", "xfs", "vfat"] + "enum": ["ext4", "xfs", "vfat", "btrfs"] }, "uuid": { "description": "UUID for the filesystem", @@ -138,7 +138,7 @@ SCHEMA = """ "root_fs_type": { "description": "Type of the root filesystem", "type": "string", - "enum": ["ext4", "xfs"], + "enum": ["ext4", "xfs", "btrfs"], "default": "ext4" } } @@ -169,6 +169,14 @@ def mkfs_xfs(device, uuid, label): encoding='utf-8', check=True) +def mkfs_btrfs(device, uuid, label): + opts = [] + if label: + opts = ["-L", label] + subprocess.run(["mkfs.btrfs", "-U", uuid] + opts + [device], + encoding='utf-8', check=True) + + def mkfs_vfat(device, uuid, label): volid = uuid.replace('-', '') opts = [] @@ -196,6 +204,8 @@ class Filesystem: maker = mkfs_xfs elif fs_type == "vfat": maker = mkfs_vfat + elif fs_type == "btrfs": + maker = mkfs_btrfs else: raise ValueError(f"Unknown filesystem type '{fs_type}'") maker(device, self.uuid, self.label) @@ -515,6 +525,8 @@ def install_grub2(image: str, pt: PartitionTable, options): modules += ["ext2"] elif fs_type == "xfs": modules += ["xfs"] + elif fs_type == "btrfs": + modules += ["btrfs"] else: raise ValueError(f"unknown boot filesystem type: '{fs_type}'") diff --git a/assemblers/org.osbuild.rawfs b/assemblers/org.osbuild.rawfs index 894e3f5a..f932663e 100755 --- a/assemblers/org.osbuild.rawfs +++ b/assemblers/org.osbuild.rawfs @@ -48,7 +48,7 @@ SCHEMA = """ "fs_type": { "description": "Filesystem type", "type": "string", - "enum": ["ext4", "xfs"], + "enum": ["ext4", "xfs", "btrfs"], "default": "ext4" } } @@ -72,6 +72,10 @@ def mkfs_xfs(device, uuid): subprocess.run(["mkfs.xfs", "-m", f"uuid={uuid}", device], encoding='utf-8', check=True) +def mkfs_btrfs(device, uuid): + subprocess.run(["mkfs.btrfs", "-U", uuid, device], encoding='utf-8', check=True) + + def main(tree, output_dir, options, loop_client): filename = options["filename"] root_fs_uuid = options["root_fs_uuid"] @@ -87,8 +91,10 @@ def main(tree, output_dir, options, loop_client): mkfs_ext4(image, root_fs_uuid) elif fs_type == "xfs": mkfs_xfs(image, root_fs_uuid) + elif fs_type == "btrfs": + mkfs_btrfs(image, root_fs_uuid) else: - raise ValueError("`fs_type` must be either ext4 or xfs") + raise ValueError("`fs_type` must be ext4, xfs or btrfs") # Copy the tree into the target image with loop_client.device(image) as loop, mount(loop, mountpoint): diff --git a/test/run/test_assemblers.py b/test/run/test_assemblers.py index 6a6bb30d..70808ac7 100644 --- a/test/run/test_assemblers.py +++ b/test/run/test_assemblers.py @@ -91,15 +91,19 @@ class TestAssemblers(test.TestBase): @unittest.skipUnless(test.TestBase.have_tree_diff(), "tree-diff missing") def test_rawfs(self): - options = { - "filename": "image.raw", - "root_fs_uuid": "016a1cda-5182-4ab3-bf97-426b00b74eb0", - "size": 512 * MEBIBYTE - } - with self.osbuild as osb: - with self.run_assembler(osb, "org.osbuild.rawfs", options, "image.raw") as (tree, image): - self.assertImageFile(image, "raw", options["size"]) - self.assertFilesystem(image, options["root_fs_uuid"], "ext4", tree) + for fs_type in ["ext4", "xfs", "btrfs"]: + with self.subTest(fs_type=fs_type): + print(f" {fs_type}", flush=True) + options = { + "filename": "image.raw", + "root_fs_uuid": "016a1cda-5182-4ab3-bf97-426b00b74eb0", + "size": 512 * MEBIBYTE, + "fs_type": fs_type, + } + with self.osbuild as osb: + with self.run_assembler(osb, "org.osbuild.rawfs", options, "image.raw") as (tree, image): + self.assertImageFile(image, "raw", options["size"]) + self.assertFilesystem(image, options["root_fs_uuid"], fs_type, tree) @unittest.skipUnless(test.TestBase.have_tree_diff(), "tree-diff missing") def test_ostree(self): @@ -138,14 +142,16 @@ class TestAssemblers(test.TestBase): loctl = loop.LoopControl() with self.osbuild as osb: for fmt in ["raw", "raw.xz", "qcow2", "vmdk", "vdi"]: - with self.subTest(fmt=fmt): - print(f" {fmt}", flush=True) + for fs_type in ["ext4", "xfs", "btrfs"]: + with self.subTest(fmt=fmt, fs_type=fs_type): + print(f" {fmt} {fs_type}", flush=True) options = { "format": fmt, "filename": f"image.{fmt}", "ptuuid": "b2c09a39-db93-44c5-846a-81e06b1dc162", "root_fs_uuid": "aff010e9-df95-4f81-be6b-e22317251033", - "size": 512 * MEBIBYTE + "size": 512 * MEBIBYTE, + "root_fs_type": fs_type, } with self.run_assembler(osb, "org.osbuild.qemu", @@ -172,7 +178,7 @@ class TestAssemblers(test.TestBase): ssize = ptable.get("sectorsize", 512) start, size = p1["start"] * ssize, p1["size"] * ssize with loop_open(loctl, target, offset=start, size=size) as dev: - self.assertFilesystem(dev, options["root_fs_uuid"], "ext4", tree) + self.assertFilesystem(dev, options["root_fs_uuid"], fs_type, tree) def test_tar(self): cases = [