stages: add org.osbuild.btrfs.subvol

A trivial stage to create subvolume on a btrfs partition.
This commit is contained in:
Ondřej Budai 2023-05-18 12:46:27 +02:00 committed by Ondřej Budai
parent f145a877f6
commit 724183b35c

59
stages/org.osbuild.btrfs.subvol Executable file
View file

@ -0,0 +1,59 @@
#!/usr/bin/python3
"""
Create subvolumes on a mounted btrfs partition.
See `btrfs`(8).
Buildhost commands used: `btrfs`.
"""
import os
import subprocess
import sys
import osbuild.api
SCHEMA_2 = r"""
"options": {
"additionalProperties": false,
"properties": {
"subvolumes": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": ["name"],
"properties": {
"name": {
"type": "string"
}
}
}
}
}
},
"devices": {
"type": "object",
"additionalProperties": true
},
"mounts": {
"type": "array"
}
"""
def main(paths, options):
volume = paths["mounts"]
for vol in options["subvolumes"]:
name = vol["name"].lstrip("/")
subvol = os.path.join(volume, name)
cmd = ["btrfs", "subvolume", "create", subvol]
subprocess.run(cmd, encoding='utf-8', check=True)
if __name__ == '__main__':
args = osbuild.api.arguments()
ret = main(args["paths"], args["options"])
sys.exit(ret)