stages: add org.osbuild.btrfs.subvol
A trivial stage to create subvolume on a btrfs partition.
This commit is contained in:
parent
f145a877f6
commit
724183b35c
1 changed files with 59 additions and 0 deletions
59
stages/org.osbuild.btrfs.subvol
Executable file
59
stages/org.osbuild.btrfs.subvol
Executable 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue