assemblers: add btrfs support to qemu and rawfs

This commit is contained in:
Davide Cavalca 2020-07-10 14:02:13 -07:00 committed by Christian Kellner
parent 1e3c0aea1b
commit 925530ac0a
3 changed files with 41 additions and 17 deletions

View file

@ -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}'")

View file

@ -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):