From 0d625f34ea7647fcceb7d1940a79eac95f932e3f Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Sun, 6 Jun 2021 14:59:30 +0000 Subject: [PATCH] stages/fstab: add support for OSTree Add experimental support for writing the fstab file to `/etc` in on OSTree deployment. Experimental here means that options might be replaced in the near future with a different mechanism and are thus not considered stable API. --- stages/org.osbuild.fstab | 50 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/stages/org.osbuild.fstab b/stages/org.osbuild.fstab index 8bd7624f..f7e145e9 100755 --- a/stages/org.osbuild.fstab +++ b/stages/org.osbuild.fstab @@ -2,24 +2,53 @@ """ Create /etc/fstab entries for filesystems -Create /etc/fstab entries for the given `filesystems`. - Each filesystem item must have at least `uuid` or `label` and a `path` (mount point). This stage replaces /etc/fstab, removing any existing entries. + +NB: The ostree configuration options are experimental and might +be replaced with a different mechanism in the near future. """ import sys import osbuild.api +from osbuild.util import ostree SCHEMA = """ "additionalProperties": false, "required": ["filesystems"], "properties": { + "ostree": { + "type": "object", + "additionalProperties": false, + "required": ["deployment"], + "properties": { + "deployment": { + "type": "object", + "additionalProperties": false, + "required": ["osname","ref"], + "properties": { + "osname": { + "description": "Name of the stateroot to be used in the deployment", + "type": "string" + }, + "ref": { + "description": "OStree ref to create and use for deployment", + "type": "string" + }, + "serial": { + "description": "The deployment serial (usually '0')", + "type": "number", + "default": 0 + } + } + } + } + }, "filesystems": { "type": "array", "description": "array of filesystem objects", @@ -72,8 +101,23 @@ SCHEMA = """ def main(tree, options): filesystems = options["filesystems"] + ostree_options = options.get("ostree") - with open(f"{tree}/etc/fstab", "w") as f: + path = f"{tree}/etc/fstab" + + if ostree_options: + deployment = ostree_options["deployment"] + osname = deployment["osname"] + ref = deployment["ref"] + serial = deployment.get("serial", 0) + + root = ostree.deployment_path(tree, osname, ref, serial) + + print(f"ostree support active: {root}") + + path = f"{root}/etc/fstab" + + with open(path, "w") as f: for filesystem in filesystems: uuid = filesystem.get("uuid") path = filesystem["path"]