assembler/qemu: add filesystem label support
Add a (optional) property call `label` to the `filesystem` object to support labeling the filesystem. Add the label for the ESP to both UEFI examples.
This commit is contained in:
parent
5cae5283d7
commit
c77313079b
3 changed files with 25 additions and 12 deletions
|
|
@ -73,6 +73,10 @@ STAGE_OPTS = """
|
|||
"type": "object",
|
||||
"required": ["mountpoint", "type", "uuid"],
|
||||
"properties": {
|
||||
"label": {
|
||||
"description": "Label for the filesystem",
|
||||
"type": "string"
|
||||
},
|
||||
"mountpoint": {
|
||||
"description": "Where to mount the partition",
|
||||
"type": "string"
|
||||
|
|
@ -126,23 +130,31 @@ def mount(source, dest):
|
|||
subprocess.run(["umount", "-R", dest], check=True)
|
||||
|
||||
|
||||
def mkfs_ext4(device, uuid):
|
||||
subprocess.run(["mkfs.ext4", "-U", uuid, device], input="y", encoding='utf-8', check=True)
|
||||
def mkfs_ext4(device, uuid, label):
|
||||
opts = []
|
||||
if label:
|
||||
opts = ["-L", label]
|
||||
subprocess.run(["mkfs.ext4", "-U", uuid] + opts + [device],
|
||||
input="y", encoding='utf-8', check=True)
|
||||
|
||||
|
||||
def mkfs_xfs(device, uuid):
|
||||
subprocess.run(["mkfs.xfs", "-m", f"uuid={uuid}", device], encoding='utf-8', check=True)
|
||||
def mkfs_xfs(device, uuid, label):
|
||||
opts = []
|
||||
if label:
|
||||
opts = ["-L", label]
|
||||
subprocess.run(["mkfs.xfs", "-m", f"uuid={uuid}"] + opts + [device],
|
||||
encoding='utf-8', check=True)
|
||||
|
||||
|
||||
def mkfs_vfat(device, uuid, name=None):
|
||||
def mkfs_vfat(device, uuid, label):
|
||||
volid = uuid.replace('-', '')
|
||||
opts = []
|
||||
if name:
|
||||
opts = ["-n", name]
|
||||
if label:
|
||||
opts = ["-n", label]
|
||||
subprocess.run(["mkfs.vfat", "-i", volid] + opts + [device], encoding='utf-8', check=True)
|
||||
|
||||
|
||||
def mkfs_for_type(device, uuid, fs_type):
|
||||
def mkfs_for_type(device, uuid, fs_type, label):
|
||||
if fs_type == "ext4":
|
||||
maker = mkfs_ext4
|
||||
elif fs_type == "xfs":
|
||||
|
|
@ -151,7 +163,7 @@ def mkfs_for_type(device, uuid, fs_type):
|
|||
maker = mkfs_vfat
|
||||
else:
|
||||
raise ValueError(f"Unknown filesystem type '{fs_type}'")
|
||||
maker(device, uuid)
|
||||
maker(device, uuid, label)
|
||||
|
||||
|
||||
def create_partition_table_legacy(image, options):
|
||||
|
|
@ -301,7 +313,8 @@ def main(tree, output_dir, options, loop_client):
|
|||
filesystem = partition["filesystem"]
|
||||
loop = cm.enter_context(loop_client.device(image, offset, size))
|
||||
# make the specified filesystem
|
||||
mkfs_for_type(loop, filesystem["uuid"], filesystem["type"])
|
||||
fs_label = filesystem.get("label")
|
||||
mkfs_for_type(loop, filesystem["uuid"], filesystem["type"], fs_label)
|
||||
# now mount it
|
||||
mountpoint = os.path.normpath(f"{root}/{filesystem['mountpoint']}")
|
||||
os.makedirs(mountpoint, exist_ok=True)
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@
|
|||
"pttype": "gpt",
|
||||
"partitions": [
|
||||
{"start": 2048, "size": 972800, "type": "C12A7328-F81F-11D2-BA4B-00A0C93EC93B",
|
||||
"filesystem": {"type": "vfat", "uuid": "46BB-8120",
|
||||
"filesystem": {"type": "vfat", "uuid": "46BB-8120", "label": "EFI System Partition",
|
||||
"mountpoint": "/boot/efi"}},
|
||||
{"start": 976896,
|
||||
"filesystem": {"type": "ext4", "uuid": "7acfe2cc-4134-482a-a9d4-4979a5a87569",
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@
|
|||
"pttype": "gpt",
|
||||
"partitions": [
|
||||
{"start": 2048, "size": 972800, "type": "C12A7328-F81F-11D2-BA4B-00A0C93EC93B",
|
||||
"filesystem": {"type": "vfat", "uuid": "46BB-8120",
|
||||
"filesystem": {"type": "vfat", "uuid": "46BB-8120", "label": "EFI System Partition",
|
||||
"mountpoint": "/boot/efi"}},
|
||||
{"start": 976896,
|
||||
"filesystem": {"type": "ext4", "uuid": "7acfe2cc-4134-482a-a9d4-4979a5a87569",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue