summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVyacheslav Yurkov <uvv.mail@gmail.com>2021-12-10 14:01:39 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-12-12 11:27:24 +0000
commit8ac91c0c0dccfdeae9d0bebb5857826b91d40dda (patch)
tree17f592264cc889f29c497ab5588705e81ac0b2f8
parent822adf5c9f84062867988c903170156d94ee3729 (diff)
downloadpoky-8ac91c0c0dccfdeae9d0bebb5857826b91d40dda.tar.gz
overlayfs-etc: mount etc as overlayfs
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 (From OE-Core rev: 610ea808c8b5edb2826bda1f1c42a811bd4ba758) Signed-off-by: Alfred Schapansky <alfred.schapansky@avantys.de> Signed-off-by: Vyacheslav Yurkov <uvv.mail@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes/overlayfs-etc.bbclass76
1 files changed, 76 insertions, 0 deletions
diff --git a/meta/classes/overlayfs-etc.bbclass b/meta/classes/overlayfs-etc.bbclass
new file mode 100644
index 0000000000..4ced07ba11
--- /dev/null
+++ b/meta/classes/overlayfs-etc.bbclass
@@ -0,0 +1,76 @@
1# Class for setting up /etc in overlayfs
2#
3# In order to have /etc directory in overlayfs a special handling at early boot stage is required
4# The idea is to supply a custom init script that mounts /etc before launching actual init program,
5# because the latter already requires /etc to be mounted
6#
7# The configuration must be machine specific. You should at least set these three variables:
8# OVERLAYFS_ETC_MOUNT_POINT ?= "/data"
9# OVERLAYFS_ETC_FSTYPE ?= "ext4"
10# OVERLAYFS_ETC_DEVICE ?= "/dev/mmcblk0p2"
11#
12# To control more mount options you should consider setting mount options:
13# OVERLAYFS_ETC_MOUNT_OPTIONS ?= "defaults"
14#
15# The class provides two options for /sbin/init generation
16# 1. Default option is to rename original /sbin/init to /sbin/init.orig and place generated init under
17# original name, i.e. /sbin/init. It has an advantage that you won't need to change any kernel
18# parameters in order to make it work, but it poses a restriction that package-management can't
19# be used, becaause updating init manager would remove generated script
20# 2. If you are would like to keep original init as is, you can set
21# OVERLAYFS_ETC_USE_ORIG_INIT_NAME = "0"
22# Then generated init will be named /sbin/preinit and you would need to extend you kernel parameters
23# manually in your bootloader configuration.
24#
25# Regardless which mode you choose, update and migration strategy of configuration files under /etc
26# overlay is out of scope of this class
27
28ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "overlayfs-etc", "create_overlayfs_etc_preinit;", "", d)}'
29IMAGE_FEATURES_CONFLICTS_overlayfs-etc = "package-management"
30
31OVERLAYFS_ETC_MOUNT_POINT ??= ""
32OVERLAYFS_ETC_FSTYPE ??= ""
33OVERLAYFS_ETC_DEVICE ??= ""
34OVERLAYFS_ETC_USE_ORIG_INIT_NAME ??= "1"
35OVERLAYFS_ETC_MOUNT_OPTIONS ??= "defaults"
36OVERLAYFS_ETC_INIT_TEMPLATE ??= "${COREBASE}/meta/files/overlayfs-etc-preinit.sh.in"
37
38python create_overlayfs_etc_preinit() {
39 overlayEtcMountPoint = d.getVar("OVERLAYFS_ETC_MOUNT_POINT")
40 overlayEtcFsType = d.getVar("OVERLAYFS_ETC_FSTYPE")
41 overlayEtcDevice = d.getVar("OVERLAYFS_ETC_DEVICE")
42
43 if not overlayEtcMountPoint:
44 bb.fatal("OVERLAYFS_ETC_MOUNT_POINT must be set in your MACHINE configuration")
45 if not overlayEtcDevice:
46 bb.fatal("OVERLAYFS_ETC_DEVICE must be set in your MACHINE configuration")
47 if not overlayEtcFsType:
48 bb.fatal("OVERLAYFS_ETC_FSTYPE should contain a valid file system type on {0}".format(overlayEtcDevice))
49
50 with open(d.getVar("OVERLAYFS_ETC_INIT_TEMPLATE"), "r") as f:
51 PreinitTemplate = f.read()
52
53 useOrigInit = oe.types.boolean(d.getVar('OVERLAYFS_ETC_USE_ORIG_INIT_NAME'))
54 preinitPath = oe.path.join(d.getVar("IMAGE_ROOTFS"), d.getVar("base_sbindir"), "preinit")
55 initBaseName = oe.path.join(d.getVar("base_sbindir"), "init")
56 origInitNameSuffix = ".orig"
57
58 args = {
59 'OVERLAYFS_ETC_MOUNT_POINT': overlayEtcMountPoint,
60 'OVERLAYFS_ETC_MOUNT_OPTIONS': d.getVar('OVERLAYFS_ETC_MOUNT_OPTIONS'),
61 'OVERLAYFS_ETC_FSTYPE': overlayEtcFsType,
62 'OVERLAYFS_ETC_DEVICE': overlayEtcDevice,
63 'SBIN_INIT_NAME': initBaseName + origInitNameSuffix if useOrigInit else initBaseName
64 }
65
66 if useOrigInit:
67 # rename original /sbin/init
68 origInit = oe.path.join(d.getVar("IMAGE_ROOTFS"), initBaseName)
69 bb.debug(1, "rootfs path %s, init path %s, test %s" % (d.getVar('IMAGE_ROOTFS'), origInit, d.getVar("IMAGE_ROOTFS")))
70 bb.utils.rename(origInit, origInit + origInitNameSuffix)
71 preinitPath = origInit
72
73 with open(preinitPath, 'w') as f:
74 f.write(PreinitTemplate.format(**args))
75 os.chmod(preinitPath, 0o755)
76}