From 5dac94450317ddf2f448c8ee05b71d9b32296572 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Wed, 2 Jun 2021 15:18:34 +0000 Subject: [PATCH] stages/mkfs.ext4: new stage to create an ext4 fs Stage to construct an ext4 file system on a specified device. --- stages/org.osbuild.mkfs.ext4 | 65 ++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 stages/org.osbuild.mkfs.ext4 diff --git a/stages/org.osbuild.mkfs.ext4 b/stages/org.osbuild.mkfs.ext4 new file mode 100755 index 00000000..bb7b438a --- /dev/null +++ b/stages/org.osbuild.mkfs.ext4 @@ -0,0 +1,65 @@ +#!/usr/bin/python3 +""" +Construct an ext4 file-system via mkfs.ext4(8) + +Construct a ext4 file-system with the given options at the device +specified via `device`. + +Buildhost commands used: `mke2fs`. +""" + +import subprocess +import sys + + +import osbuild.api + + +SCHEMA_2 = r""" +"devices": { + "type": "object", + "additionalProperties": false, + "required": ["device"], + "properties": { + "device": { + "type": "object", + "additionalProperties": true + } + } +}, +"options": { + "additionalProperties": false, + "required": ["uuid"], + "properties": { + "uuid": { + "description": "Volume identifier", + "type": "string" + }, + "label": { + "description": "Label for the file system", + "type": "string", + "maxLength": 16 + } + } +} +""" + + +def main(devices, options): + device = devices["device"]["path"] + + uuid = options["uuid"] + label = options.get("label") + opts = [] + + if label: + opts = ["-L", label] + + subprocess.run(["mkfs.ext4", "-U", uuid] + opts + [device], + encoding='utf-8', check=True) + + +if __name__ == '__main__': + args = osbuild.api.arguments() + ret = main(args["devices"], args["options"]) + sys.exit(ret)