All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vyacheslav Yurkov <uvv.mail@gmail.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH 2/8] overlayfs-etc: mount etc as overlayfs
Date: Fri, 10 Dec 2021 12:50:21 +0100	[thread overview]
Message-ID: <28b7b8f434ffa0b4dd43a6cd369097e9b39708fd.1639136706.git.uvv.mail@gmail.com> (raw)
In-Reply-To: <cover.1639136706.git.uvv.mail@gmail.com>

This class provides an image feature that mounts /etc as an overlayfs
file system. This is an extension for existing overlayfs class, which
doesn't support /etc

Signed-off-by: Alfred Schapansky <alfred.schapansky@avantys.de>
Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com>
---
 meta/classes/overlayfs-etc.bbclass | 76 ++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 meta/classes/overlayfs-etc.bbclass

diff --git a/meta/classes/overlayfs-etc.bbclass b/meta/classes/overlayfs-etc.bbclass
new file mode 100644
index 0000000000..5e89339269
--- /dev/null
+++ b/meta/classes/overlayfs-etc.bbclass
@@ -0,0 +1,76 @@
+# Class for setting up /etc in overlayfs
+#
+# In order to have /etc directory in overlayfs a special handling at early boot stage is required
+# The idea is to supply a custom init script that mounts /etc before launching actual init program,
+# because the latter already requires /etc to be mounted
+#
+# The configuration must be machine specific. You should at least set these three variables:
+#   OVERLAYFS_ETC_MOUNT_POINT ?= "/data"
+#   OVERLAYFS_ETC_FSTYPE ?= "ext4"
+#   OVERLAYFS_ETC_DEVICE ?= "/dev/mmcblk0p2"
+#
+# To control more mount options you should consider setting mount options:
+#   OVERLAYFS_ETC_MOUNT_OPTIONS ?= "defaults"
+#
+# The class provides two options for /sbin/init generation
+# 1. Default option is to rename original /sbin/init to /sbin/init.orig and place generated init under
+#    original name, i.e. /sbin/init. It has an advantage that you won't need to change any kernel
+#    parameters in order to make it work, but it poses a restriction that package-management can't
+#    be used, becaause updating init manager would remove generated script
+# 2. If you are would like to keep original init as is, you can set
+#    OVERLAYFS_ETC_USE_ORIG_INIT_NAME = "0"
+#    Then generated init will be named /sbin/preinit and you would need to extend you kernel parameters
+#    manually in your bootloader configuration.
+#
+# Regardless which mode you choose, update and migration strategy of configuration files under /etc
+# overlay is out of scope of this class
+
+ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "overlayfs-etc", "create_overlayfs_etc_preinit;", "", d)}'
+IMAGE_FEATURES_CONFLICTS_overlayfs-etc = "package-management"
+
+OVERLAYFS_ETC_MOUNT_POINT ??= ""
+OVERLAYFS_ETC_FSTYPE ??= ""
+OVERLAYFS_ETC_DEVICE ??= ""
+OVERLAYFS_ETC_USE_ORIG_INIT_NAME ??= "1"
+OVERLAYFS_ETC_MOUNT_OPTIONS ??= "defaults"
+OVERLAYFS_ETC_INIT_TEMPLATE ??= "${COREBASE}/meta/files/preinit.sh.in"
+
+python create_overlayfs_etc_preinit() {
+    overlayEtcMountPoint = d.getVar("OVERLAYFS_ETC_MOUNT_POINT")
+    overlayEtcFsType = d.getVar("OVERLAYFS_ETC_FSTYPE")
+    overlayEtcDevice = d.getVar("OVERLAYFS_ETC_DEVICE")
+
+    if not overlayEtcMountPoint:
+        bb.fatal("OVERLAYFS_ETC_MOUNT_POINT must be set in your MACHINE configuration")
+    if not overlayEtcDevice:
+        bb.fatal("OVERLAYFS_ETC_DEVICE must be set in your MACHINE configuration")
+    if not overlayEtcFsType:
+        bb.fatal("OVERLAYFS_ETC_FSTYPE should contain a valid file system type on {0}".format(overlayEtcDevice))
+
+    with open(d.getVar("OVERLAYFS_ETC_INIT_TEMPLATE"), "r") as f:
+        PreinitTemplate = f.read()
+
+    useOrigInit = oe.types.boolean(d.getVar('OVERLAYFS_ETC_USE_ORIG_INIT_NAME'))
+    preinitPath = oe.path.join(d.getVar("IMAGE_ROOTFS"), d.getVar("base_sbindir"), "preinit")
+    initBaseName = oe.path.join(d.getVar("base_sbindir"), "init")
+    origInitNameSuffix = ".orig"
+
+    args = {
+        'OVERLAYFS_ETC_MOUNT_POINT': overlayEtcMountPoint,
+        'OVERLAYFS_ETC_MOUNT_OPTIONS': d.getVar('OVERLAYFS_ETC_MOUNT_OPTIONS'),
+        'OVERLAYFS_ETC_FSTYPE': overlayEtcFsType,
+        'OVERLAYFS_ETC_DEVICE': overlayEtcDevice,
+        'SBIN_INIT_NAME': initBaseName + origInitNameSuffix if useOrigInit else initBaseName
+    }
+
+    if useOrigInit:
+        # rename original /sbin/init
+        origInit = oe.path.join(d.getVar("IMAGE_ROOTFS"), initBaseName)
+        bb.debug(1, "rootfs path %s, init path %s, test %s" % (d.getVar('IMAGE_ROOTFS'), origInit, d.getVar("IMAGE_ROOTFS")))
+        bb.utils.rename(origInit, origInit + origInitNameSuffix)
+        preinitPath = origInit
+
+    with open(preinitPath, 'w') as f:
+        f.write(PreinitTemplate.format(**args))
+    os.chmod(preinitPath, 0o755)
+}
-- 
2.28.0



  parent reply	other threads:[~2021-12-10 11:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-10 11:50 [PATCH v2 0/8] Pull request (cover letter only) Vyacheslav Yurkov
2021-12-10 11:50 ` [PATCH 1/8] files: add preinit.sh.in Vyacheslav Yurkov
2021-12-10 12:42   ` [OE-core] " Richard Purdie
2021-12-10 11:50 ` Vyacheslav Yurkov [this message]
2021-12-10 11:50 ` [PATCH 3/8] wic: image for overlayfs-etc tests Vyacheslav Yurkov
2021-12-10 11:50 ` [PATCH 4/8] image: add overlayfs-etc image feature Vyacheslav Yurkov
2021-12-10 11:50 ` [PATCH 5/8] oeqa/selftest: overlayfs helper function Vyacheslav Yurkov
2021-12-10 11:50 ` [PATCH 6/8] oeqa/selftest: unit tests for overlayfs-etc Vyacheslav Yurkov
2021-12-10 11:50 ` [PATCH 7/8] overlayfs: update notes on /etc Vyacheslav Yurkov
2021-12-10 11:50 ` [PATCH 8/8] overlayfs: move templates to files directory Vyacheslav Yurkov
2021-12-10 13:01 [PATCH v3 0/8] Pull request (cover letter only) Vyacheslav Yurkov
2021-12-10 13:01 ` [PATCH 2/8] overlayfs-etc: mount etc as overlayfs Vyacheslav Yurkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=28b7b8f434ffa0b4dd43a6cd369097e9b39708fd.1639136706.git.uvv.mail@gmail.com \
    --to=uvv.mail@gmail.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.