diff options
| author | Vyacheslav Yurkov <v.yurkov@precitec.de> | 2022-09-07 21:51:36 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-09-09 12:24:43 +0100 |
| commit | e38ef4dcf13f365d018f44fc0216ff596ee94681 (patch) | |
| tree | bbc46941f29f42320f723418ca2e80d847bc7655 /meta/classes | |
| parent | 9277742901e4e63794dc74bb70815518fc1c8c16 (diff) | |
| download | poky-e38ef4dcf13f365d018f44fc0216ff596ee94681.tar.gz | |
classes: Update overlayfs classes to use new bitbake functionality
OverlayFS classes belong to a recipe scope
(From OE-Core rev: 7afa7739e82220729566ccabe2675a8991f9485a)
Signed-off-by: Vyacheslav Yurkov <v.yurkov@precitec.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
| -rw-r--r-- | meta/classes/overlayfs-etc.bbclass | 82 | ||||
| -rw-r--r-- | meta/classes/overlayfs.bbclass | 137 |
2 files changed, 0 insertions, 219 deletions
diff --git a/meta/classes/overlayfs-etc.bbclass b/meta/classes/overlayfs-etc.bbclass deleted file mode 100644 index d0bc3ecfac..0000000000 --- a/meta/classes/overlayfs-etc.bbclass +++ /dev/null | |||
| @@ -1,82 +0,0 @@ | |||
| 1 | # | ||
| 2 | # Copyright OpenEmbedded Contributors | ||
| 3 | # | ||
| 4 | # SPDX-License-Identifier: MIT | ||
| 5 | # | ||
| 6 | |||
| 7 | # Class for setting up /etc in overlayfs | ||
| 8 | # | ||
| 9 | # In order to have /etc directory in overlayfs a special handling at early boot stage is required | ||
| 10 | # The idea is to supply a custom init script that mounts /etc before launching actual init program, | ||
| 11 | # because the latter already requires /etc to be mounted | ||
| 12 | # | ||
| 13 | # The configuration must be machine specific. You should at least set these three variables: | ||
| 14 | # OVERLAYFS_ETC_MOUNT_POINT ?= "/data" | ||
| 15 | # OVERLAYFS_ETC_FSTYPE ?= "ext4" | ||
| 16 | # OVERLAYFS_ETC_DEVICE ?= "/dev/mmcblk0p2" | ||
| 17 | # | ||
| 18 | # To control more mount options you should consider setting mount options: | ||
| 19 | # OVERLAYFS_ETC_MOUNT_OPTIONS ?= "defaults" | ||
| 20 | # | ||
| 21 | # The class provides two options for /sbin/init generation | ||
| 22 | # 1. Default option is to rename original /sbin/init to /sbin/init.orig and place generated init under | ||
| 23 | # original name, i.e. /sbin/init. It has an advantage that you won't need to change any kernel | ||
| 24 | # parameters in order to make it work, but it poses a restriction that package-management can't | ||
| 25 | # be used, becaause updating init manager would remove generated script | ||
| 26 | # 2. If you are would like to keep original init as is, you can set | ||
| 27 | # OVERLAYFS_ETC_USE_ORIG_INIT_NAME = "0" | ||
| 28 | # Then generated init will be named /sbin/preinit and you would need to extend you kernel parameters | ||
| 29 | # manually in your bootloader configuration. | ||
| 30 | # | ||
| 31 | # Regardless which mode you choose, update and migration strategy of configuration files under /etc | ||
| 32 | # overlay is out of scope of this class | ||
| 33 | |||
| 34 | ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "overlayfs-etc", "create_overlayfs_etc_preinit;", "", d)}' | ||
| 35 | IMAGE_FEATURES_CONFLICTS_overlayfs-etc = "${@ 'package-management' if bb.utils.to_boolean(d.getVar('OVERLAYFS_ETC_USE_ORIG_INIT_NAME'), True) else ''}" | ||
| 36 | |||
| 37 | OVERLAYFS_ETC_MOUNT_POINT ??= "" | ||
| 38 | OVERLAYFS_ETC_FSTYPE ??= "" | ||
| 39 | OVERLAYFS_ETC_DEVICE ??= "" | ||
| 40 | OVERLAYFS_ETC_USE_ORIG_INIT_NAME ??= "1" | ||
| 41 | OVERLAYFS_ETC_MOUNT_OPTIONS ??= "defaults" | ||
| 42 | OVERLAYFS_ETC_INIT_TEMPLATE ??= "${COREBASE}/meta/files/overlayfs-etc-preinit.sh.in" | ||
| 43 | |||
| 44 | python create_overlayfs_etc_preinit() { | ||
| 45 | overlayEtcMountPoint = d.getVar("OVERLAYFS_ETC_MOUNT_POINT") | ||
| 46 | overlayEtcFsType = d.getVar("OVERLAYFS_ETC_FSTYPE") | ||
| 47 | overlayEtcDevice = d.getVar("OVERLAYFS_ETC_DEVICE") | ||
| 48 | |||
| 49 | if not overlayEtcMountPoint: | ||
| 50 | bb.fatal("OVERLAYFS_ETC_MOUNT_POINT must be set in your MACHINE configuration") | ||
| 51 | if not overlayEtcDevice: | ||
| 52 | bb.fatal("OVERLAYFS_ETC_DEVICE must be set in your MACHINE configuration") | ||
| 53 | if not overlayEtcFsType: | ||
| 54 | bb.fatal("OVERLAYFS_ETC_FSTYPE should contain a valid file system type on {0}".format(overlayEtcDevice)) | ||
| 55 | |||
| 56 | with open(d.getVar("OVERLAYFS_ETC_INIT_TEMPLATE"), "r") as f: | ||
| 57 | PreinitTemplate = f.read() | ||
| 58 | |||
| 59 | useOrigInit = oe.types.boolean(d.getVar('OVERLAYFS_ETC_USE_ORIG_INIT_NAME')) | ||
| 60 | preinitPath = oe.path.join(d.getVar("IMAGE_ROOTFS"), d.getVar("base_sbindir"), "preinit") | ||
| 61 | initBaseName = oe.path.join(d.getVar("base_sbindir"), "init") | ||
| 62 | origInitNameSuffix = ".orig" | ||
| 63 | |||
| 64 | args = { | ||
| 65 | 'OVERLAYFS_ETC_MOUNT_POINT': overlayEtcMountPoint, | ||
| 66 | 'OVERLAYFS_ETC_MOUNT_OPTIONS': d.getVar('OVERLAYFS_ETC_MOUNT_OPTIONS'), | ||
| 67 | 'OVERLAYFS_ETC_FSTYPE': overlayEtcFsType, | ||
| 68 | 'OVERLAYFS_ETC_DEVICE': overlayEtcDevice, | ||
| 69 | 'SBIN_INIT_NAME': initBaseName + origInitNameSuffix if useOrigInit else initBaseName | ||
| 70 | } | ||
| 71 | |||
| 72 | if useOrigInit: | ||
| 73 | # rename original /sbin/init | ||
| 74 | origInit = oe.path.join(d.getVar("IMAGE_ROOTFS"), initBaseName) | ||
| 75 | bb.debug(1, "rootfs path %s, init path %s, test %s" % (d.getVar('IMAGE_ROOTFS'), origInit, d.getVar("IMAGE_ROOTFS"))) | ||
| 76 | bb.utils.rename(origInit, origInit + origInitNameSuffix) | ||
| 77 | preinitPath = origInit | ||
| 78 | |||
| 79 | with open(preinitPath, 'w') as f: | ||
| 80 | f.write(PreinitTemplate.format(**args)) | ||
| 81 | os.chmod(preinitPath, 0o755) | ||
| 82 | } | ||
diff --git a/meta/classes/overlayfs.bbclass b/meta/classes/overlayfs.bbclass deleted file mode 100644 index bdc6dd9d57..0000000000 --- a/meta/classes/overlayfs.bbclass +++ /dev/null | |||
| @@ -1,137 +0,0 @@ | |||
| 1 | # | ||
| 2 | # Copyright OpenEmbedded Contributors | ||
| 3 | # | ||
| 4 | # SPDX-License-Identifier: MIT | ||
| 5 | # | ||
| 6 | |||
| 7 | # Class for generation of overlayfs mount units | ||
| 8 | # | ||
| 9 | # It's often desired in Embedded System design to have a read-only rootfs. | ||
| 10 | # But a lot of different applications might want to have a read-write access to | ||
| 11 | # some parts of a filesystem. It can be especially useful when your update mechanism | ||
| 12 | # overwrites the whole rootfs, but you want your application data to be preserved | ||
| 13 | # between updates. This class provides a way to achieve that by means | ||
| 14 | # of overlayfs and at the same time keeping the base rootfs read-only. | ||
| 15 | # | ||
| 16 | # Usage example. | ||
| 17 | # | ||
| 18 | # Set a mount point for a partition overlayfs is going to use as upper layer | ||
| 19 | # in your machine configuration. Underlying file system can be anything that | ||
| 20 | # is supported by overlayfs. This has to be done in your machine configuration. | ||
| 21 | # QA check fails to catch file existence if you redefine this variable in your recipe! | ||
| 22 | # | ||
| 23 | # OVERLAYFS_MOUNT_POINT[data] ?= "/data" | ||
| 24 | # | ||
| 25 | # Per default the class assumes you have a corresponding fstab entry or systemd | ||
| 26 | # mount unit (data.mount in this case) for this mount point installed on the | ||
| 27 | # image, for instance via a wks script or the systemd-machine-units recipe. | ||
| 28 | # | ||
| 29 | # If the mount point is handled somewhere else, e.g. custom boot or preinit | ||
| 30 | # scripts or in a initramfs, then this QA check can be skipped by adding | ||
| 31 | # mount-configured to the related OVERLAYFS_QA_SKIP flag: | ||
| 32 | # | ||
| 33 | # OVERLAYFS_QA_SKIP[data] = "mount-configured" | ||
| 34 | # | ||
| 35 | # To use the overlayfs, you just have to specify writable directories inside | ||
| 36 | # their recipe: | ||
| 37 | # | ||
| 38 | # OVERLAYFS_WRITABLE_PATHS[data] = "/usr/share/my-custom-application" | ||
| 39 | # | ||
| 40 | # To support several mount points you can use a different variable flag. Assume we | ||
| 41 | # want to have a writable location on the file system, but not interested where the data | ||
| 42 | # survive a reboot. Then we could have a mnt-overlay.mount unit for a tmpfs file system: | ||
| 43 | # | ||
| 44 | # OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay" | ||
| 45 | # OVERLAYFS_WRITABLE_PATHS[mnt-overlay] = "/usr/share/another-application" | ||
| 46 | # | ||
| 47 | # If your recipe deploys a systemd service, then it should require and be | ||
| 48 | # started after the ${PN}-overlays.service to make sure that all overlays are | ||
| 49 | # mounted beforehand. | ||
| 50 | # | ||
| 51 | # Note: the class does not support /etc directory itself, because systemd depends on it | ||
| 52 | # For /etc directory use overlayfs-etc class | ||
| 53 | |||
| 54 | REQUIRED_DISTRO_FEATURES += "systemd overlayfs" | ||
| 55 | |||
| 56 | inherit systemd features_check | ||
| 57 | |||
| 58 | OVERLAYFS_CREATE_DIRS_TEMPLATE ??= "${COREBASE}/meta/files/overlayfs-create-dirs.service.in" | ||
| 59 | OVERLAYFS_MOUNT_UNIT_TEMPLATE ??= "${COREBASE}/meta/files/overlayfs-unit.mount.in" | ||
| 60 | OVERLAYFS_ALL_OVERLAYS_TEMPLATE ??= "${COREBASE}/meta/files/overlayfs-all-overlays.service.in" | ||
| 61 | |||
| 62 | python do_create_overlayfs_units() { | ||
| 63 | from oe.overlayfs import mountUnitName | ||
| 64 | |||
| 65 | with open(d.getVar("OVERLAYFS_CREATE_DIRS_TEMPLATE"), "r") as f: | ||
| 66 | CreateDirsUnitTemplate = f.read() | ||
| 67 | with open(d.getVar("OVERLAYFS_MOUNT_UNIT_TEMPLATE"), "r") as f: | ||
| 68 | MountUnitTemplate = f.read() | ||
| 69 | with open(d.getVar("OVERLAYFS_ALL_OVERLAYS_TEMPLATE"), "r") as f: | ||
| 70 | AllOverlaysTemplate = f.read() | ||
| 71 | |||
| 72 | def prepareUnits(data, lower): | ||
| 73 | from oe.overlayfs import helperUnitName | ||
| 74 | |||
| 75 | args = { | ||
| 76 | 'DATA_MOUNT_POINT': data, | ||
| 77 | 'DATA_MOUNT_UNIT': mountUnitName(data), | ||
| 78 | 'CREATE_DIRS_SERVICE': helperUnitName(lower), | ||
| 79 | 'LOWERDIR': lower, | ||
| 80 | } | ||
| 81 | |||
| 82 | bb.debug(1, "Generate systemd unit %s" % mountUnitName(lower)) | ||
| 83 | with open(os.path.join(d.getVar('WORKDIR'), mountUnitName(lower)), 'w') as f: | ||
| 84 | f.write(MountUnitTemplate.format(**args)) | ||
| 85 | |||
| 86 | bb.debug(1, "Generate helper systemd unit %s" % helperUnitName(lower)) | ||
| 87 | with open(os.path.join(d.getVar('WORKDIR'), helperUnitName(lower)), 'w') as f: | ||
| 88 | f.write(CreateDirsUnitTemplate.format(**args)) | ||
| 89 | |||
| 90 | def prepareGlobalUnit(dependentUnits): | ||
| 91 | from oe.overlayfs import allOverlaysUnitName | ||
| 92 | args = { | ||
| 93 | 'ALL_OVERLAYFS_UNITS': " ".join(dependentUnits), | ||
| 94 | 'PN': d.getVar('PN') | ||
| 95 | } | ||
| 96 | |||
| 97 | bb.debug(1, "Generate systemd unit with all overlays %s" % allOverlaysUnitName(d)) | ||
| 98 | with open(os.path.join(d.getVar('WORKDIR'), allOverlaysUnitName(d)), 'w') as f: | ||
| 99 | f.write(AllOverlaysTemplate.format(**args)) | ||
| 100 | |||
| 101 | mountUnitList = [] | ||
| 102 | overlayMountPoints = d.getVarFlags("OVERLAYFS_MOUNT_POINT") | ||
| 103 | for mountPoint in overlayMountPoints: | ||
| 104 | bb.debug(1, "Process variable flag %s" % mountPoint) | ||
| 105 | for lower in d.getVarFlag('OVERLAYFS_WRITABLE_PATHS', mountPoint).split(): | ||
| 106 | bb.debug(1, "Prepare mount unit for %s with data mount point %s" % | ||
| 107 | (lower, d.getVarFlag('OVERLAYFS_MOUNT_POINT', mountPoint))) | ||
| 108 | prepareUnits(d.getVarFlag('OVERLAYFS_MOUNT_POINT', mountPoint), lower) | ||
| 109 | mountUnitList.append(mountUnitName(lower)) | ||
| 110 | |||
| 111 | # set up one unit, which depends on all mount units, so users can set | ||
| 112 | # only one dependency in their units to make sure software starts | ||
| 113 | # when all overlays are mounted | ||
| 114 | prepareGlobalUnit(mountUnitList) | ||
| 115 | } | ||
| 116 | |||
| 117 | # we need to generate file names early during parsing stage | ||
| 118 | python () { | ||
| 119 | from oe.overlayfs import strForBash, unitFileList | ||
| 120 | |||
| 121 | unitList = unitFileList(d) | ||
| 122 | for unit in unitList: | ||
| 123 | d.appendVar('SYSTEMD_SERVICE:' + d.getVar('PN'), ' ' + unit) | ||
| 124 | d.appendVar('FILES:' + d.getVar('PN'), ' ' + | ||
| 125 | d.getVar('systemd_system_unitdir') + '/' + strForBash(unit)) | ||
| 126 | |||
| 127 | d.setVar('OVERLAYFS_UNIT_LIST', ' '.join([strForBash(s) for s in unitList])) | ||
| 128 | } | ||
| 129 | |||
| 130 | do_install:append() { | ||
| 131 | install -d ${D}${systemd_system_unitdir} | ||
| 132 | for unit in ${OVERLAYFS_UNIT_LIST}; do | ||
| 133 | install -m 0444 ${WORKDIR}/${unit} ${D}${systemd_system_unitdir} | ||
| 134 | done | ||
| 135 | } | ||
| 136 | |||
| 137 | addtask create_overlayfs_units before do_install | ||
