mirror of
https://git.yoctoproject.org/poky
synced 2026-05-01 15:32:12 +02:00
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>
This commit is contained in:
committed by
Richard Purdie
parent
9277742901
commit
e38ef4dcf1
@@ -1,82 +0,0 @@
|
||||
#
|
||||
# Copyright OpenEmbedded Contributors
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
# 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' if bb.utils.to_boolean(d.getVar('OVERLAYFS_ETC_USE_ORIG_INIT_NAME'), True) else ''}"
|
||||
|
||||
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/overlayfs-etc-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)
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
#
|
||||
# Copyright OpenEmbedded Contributors
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
|
||||
# Class for generation of overlayfs mount units
|
||||
#
|
||||
# It's often desired in Embedded System design to have a read-only rootfs.
|
||||
# But a lot of different applications might want to have a read-write access to
|
||||
# some parts of a filesystem. It can be especially useful when your update mechanism
|
||||
# overwrites the whole rootfs, but you want your application data to be preserved
|
||||
# between updates. This class provides a way to achieve that by means
|
||||
# of overlayfs and at the same time keeping the base rootfs read-only.
|
||||
#
|
||||
# Usage example.
|
||||
#
|
||||
# Set a mount point for a partition overlayfs is going to use as upper layer
|
||||
# in your machine configuration. Underlying file system can be anything that
|
||||
# is supported by overlayfs. This has to be done in your machine configuration.
|
||||
# QA check fails to catch file existence if you redefine this variable in your recipe!
|
||||
#
|
||||
# OVERLAYFS_MOUNT_POINT[data] ?= "/data"
|
||||
#
|
||||
# Per default the class assumes you have a corresponding fstab entry or systemd
|
||||
# mount unit (data.mount in this case) for this mount point installed on the
|
||||
# image, for instance via a wks script or the systemd-machine-units recipe.
|
||||
#
|
||||
# If the mount point is handled somewhere else, e.g. custom boot or preinit
|
||||
# scripts or in a initramfs, then this QA check can be skipped by adding
|
||||
# mount-configured to the related OVERLAYFS_QA_SKIP flag:
|
||||
#
|
||||
# OVERLAYFS_QA_SKIP[data] = "mount-configured"
|
||||
#
|
||||
# To use the overlayfs, you just have to specify writable directories inside
|
||||
# their recipe:
|
||||
#
|
||||
# OVERLAYFS_WRITABLE_PATHS[data] = "/usr/share/my-custom-application"
|
||||
#
|
||||
# To support several mount points you can use a different variable flag. Assume we
|
||||
# want to have a writable location on the file system, but not interested where the data
|
||||
# survive a reboot. Then we could have a mnt-overlay.mount unit for a tmpfs file system:
|
||||
#
|
||||
# OVERLAYFS_MOUNT_POINT[mnt-overlay] = "/mnt/overlay"
|
||||
# OVERLAYFS_WRITABLE_PATHS[mnt-overlay] = "/usr/share/another-application"
|
||||
#
|
||||
# If your recipe deploys a systemd service, then it should require and be
|
||||
# started after the ${PN}-overlays.service to make sure that all overlays are
|
||||
# mounted beforehand.
|
||||
#
|
||||
# Note: the class does not support /etc directory itself, because systemd depends on it
|
||||
# For /etc directory use overlayfs-etc class
|
||||
|
||||
REQUIRED_DISTRO_FEATURES += "systemd overlayfs"
|
||||
|
||||
inherit systemd features_check
|
||||
|
||||
OVERLAYFS_CREATE_DIRS_TEMPLATE ??= "${COREBASE}/meta/files/overlayfs-create-dirs.service.in"
|
||||
OVERLAYFS_MOUNT_UNIT_TEMPLATE ??= "${COREBASE}/meta/files/overlayfs-unit.mount.in"
|
||||
OVERLAYFS_ALL_OVERLAYS_TEMPLATE ??= "${COREBASE}/meta/files/overlayfs-all-overlays.service.in"
|
||||
|
||||
python do_create_overlayfs_units() {
|
||||
from oe.overlayfs import mountUnitName
|
||||
|
||||
with open(d.getVar("OVERLAYFS_CREATE_DIRS_TEMPLATE"), "r") as f:
|
||||
CreateDirsUnitTemplate = f.read()
|
||||
with open(d.getVar("OVERLAYFS_MOUNT_UNIT_TEMPLATE"), "r") as f:
|
||||
MountUnitTemplate = f.read()
|
||||
with open(d.getVar("OVERLAYFS_ALL_OVERLAYS_TEMPLATE"), "r") as f:
|
||||
AllOverlaysTemplate = f.read()
|
||||
|
||||
def prepareUnits(data, lower):
|
||||
from oe.overlayfs import helperUnitName
|
||||
|
||||
args = {
|
||||
'DATA_MOUNT_POINT': data,
|
||||
'DATA_MOUNT_UNIT': mountUnitName(data),
|
||||
'CREATE_DIRS_SERVICE': helperUnitName(lower),
|
||||
'LOWERDIR': lower,
|
||||
}
|
||||
|
||||
bb.debug(1, "Generate systemd unit %s" % mountUnitName(lower))
|
||||
with open(os.path.join(d.getVar('WORKDIR'), mountUnitName(lower)), 'w') as f:
|
||||
f.write(MountUnitTemplate.format(**args))
|
||||
|
||||
bb.debug(1, "Generate helper systemd unit %s" % helperUnitName(lower))
|
||||
with open(os.path.join(d.getVar('WORKDIR'), helperUnitName(lower)), 'w') as f:
|
||||
f.write(CreateDirsUnitTemplate.format(**args))
|
||||
|
||||
def prepareGlobalUnit(dependentUnits):
|
||||
from oe.overlayfs import allOverlaysUnitName
|
||||
args = {
|
||||
'ALL_OVERLAYFS_UNITS': " ".join(dependentUnits),
|
||||
'PN': d.getVar('PN')
|
||||
}
|
||||
|
||||
bb.debug(1, "Generate systemd unit with all overlays %s" % allOverlaysUnitName(d))
|
||||
with open(os.path.join(d.getVar('WORKDIR'), allOverlaysUnitName(d)), 'w') as f:
|
||||
f.write(AllOverlaysTemplate.format(**args))
|
||||
|
||||
mountUnitList = []
|
||||
overlayMountPoints = d.getVarFlags("OVERLAYFS_MOUNT_POINT")
|
||||
for mountPoint in overlayMountPoints:
|
||||
bb.debug(1, "Process variable flag %s" % mountPoint)
|
||||
for lower in d.getVarFlag('OVERLAYFS_WRITABLE_PATHS', mountPoint).split():
|
||||
bb.debug(1, "Prepare mount unit for %s with data mount point %s" %
|
||||
(lower, d.getVarFlag('OVERLAYFS_MOUNT_POINT', mountPoint)))
|
||||
prepareUnits(d.getVarFlag('OVERLAYFS_MOUNT_POINT', mountPoint), lower)
|
||||
mountUnitList.append(mountUnitName(lower))
|
||||
|
||||
# set up one unit, which depends on all mount units, so users can set
|
||||
# only one dependency in their units to make sure software starts
|
||||
# when all overlays are mounted
|
||||
prepareGlobalUnit(mountUnitList)
|
||||
}
|
||||
|
||||
# we need to generate file names early during parsing stage
|
||||
python () {
|
||||
from oe.overlayfs import strForBash, unitFileList
|
||||
|
||||
unitList = unitFileList(d)
|
||||
for unit in unitList:
|
||||
d.appendVar('SYSTEMD_SERVICE:' + d.getVar('PN'), ' ' + unit)
|
||||
d.appendVar('FILES:' + d.getVar('PN'), ' ' +
|
||||
d.getVar('systemd_system_unitdir') + '/' + strForBash(unit))
|
||||
|
||||
d.setVar('OVERLAYFS_UNIT_LIST', ' '.join([strForBash(s) for s in unitList]))
|
||||
}
|
||||
|
||||
do_install:append() {
|
||||
install -d ${D}${systemd_system_unitdir}
|
||||
for unit in ${OVERLAYFS_UNIT_LIST}; do
|
||||
install -m 0444 ${WORKDIR}/${unit} ${D}${systemd_system_unitdir}
|
||||
done
|
||||
}
|
||||
|
||||
addtask create_overlayfs_units before do_install
|
||||
Reference in New Issue
Block a user