From b0338ec5ac9e7b3828d16efa2c29d4e978148351 Mon Sep 17 00:00:00 2001 From: Oleksandr Grytsov Date: Sun, 7 Jun 2026 22:58:06 +0300 Subject: [PATCH 1/3] WIP Signed-off-by: Oleksandr Grytsov --- recipes-core/images/aos-image-initramfs.bb | 5 -- .../initramfs-framework/aosoverlay | 46 +++++++++++++++++++ .../initramfs-framework/aosupdate | 2 +- .../initramfs-framework_%.bbappend | 15 ++++++ 4 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 recipes-core/initrdscripts/initramfs-framework/aosoverlay diff --git a/recipes-core/images/aos-image-initramfs.bb b/recipes-core/images/aos-image-initramfs.bb index a4528981..fb3ab177 100644 --- a/recipes-core/images/aos-image-initramfs.bb +++ b/recipes-core/images/aos-image-initramfs.bb @@ -10,11 +10,6 @@ AOS_INITRAMFS_SCRIPTS ?= " \ initramfs-module-vardir \ " -RRECOMMENDS:${PN} = " \ - kernel-module-overlay \ - kernel-module-squashfs \ -" - # Don't allow the initramfs to contain a kernel PACKAGE_EXCLUDE = "kernel-image-*" diff --git a/recipes-core/initrdscripts/initramfs-framework/aosoverlay b/recipes-core/initrdscripts/initramfs-framework/aosoverlay new file mode 100644 index 00000000..b60926ea --- /dev/null +++ b/recipes-core/initrdscripts/initramfs-framework/aosoverlay @@ -0,0 +1,46 @@ +#!/bin/sh + +# This module overlays a source over the rootfs: +# aosoverlay.path - specifies overlay source: a squashfs image file or a directory. +# If a file (or symlink to a file), it is loop-mounted to /mnt/overlay +# before being overlaid. If a directory (or symlink to a directory), +# it is used directly. + +OVERLAY_MOUNT="/mnt/overlay" + +aosoverlay_enabled() { + if [ -z "${bootparam_aosoverlay_path}" ]; then + msg "Aos overlay disabled: boot parameter aosoverlay.path is not set." + return 1 + fi + + if [ ! -e "${bootparam_aosoverlay_path}" ]; then + msg "Aos overlay disabled: ${bootparam_aosoverlay_path} does not exist." + return 1 + fi + + return 0 +} + +aosoverlay_run() { + msg "Aos overlay: applying ${bootparam_aosoverlay_path} over rootfs" + + real_src=$(readlink -f "$bootparam_aosoverlay_path") + + if [ -f "$real_src" ]; then + msg "Aos overlay: mounting image ${real_src} to ${OVERLAY_MOUNT}" + + mkdir -p "$OVERLAY_MOUNT" + mount -t squashfs -o loop "$real_src" "$OVERLAY_MOUNT" + + overlay_dir="$OVERLAY_MOUNT" + elif [ -d "$real_src" ]; then + overlay_dir="$real_src" + else + fatal "Aos overlay: ${real_src} is not a regular file or directory" + fi + + msg "Aos overlay: mounting ${overlay_dir} over ${ROOTFS_DIR}" + + mount -t overlay overlay -o lowerdir="${overlay_dir}":"${ROOTFS_DIR}" "$ROOTFS_DIR" +} diff --git a/recipes-core/initrdscripts/initramfs-framework/aosupdate b/recipes-core/initrdscripts/initramfs-framework/aosupdate index 52f12884..2f5c045b 100644 --- a/recipes-core/initrdscripts/initramfs-framework/aosupdate +++ b/recipes-core/initrdscripts/initramfs-framework/aosupdate @@ -2,7 +2,7 @@ # This module requires the following boot parameters: # aosupdate.device - specifies device where update artifacts are stored; -# aosupdate.path - specifies path whre update artifacts are stored; +# aosupdate.path - specifies path where update artifacts are stored; # aosupdate.selinux_module - specifies SELinux module. # consts diff --git a/recipes-core/initrdscripts/initramfs-framework_%.bbappend b/recipes-core/initrdscripts/initramfs-framework_%.bbappend index dca36484..53d57ea2 100644 --- a/recipes-core/initrdscripts/initramfs-framework_%.bbappend +++ b/recipes-core/initrdscripts/initramfs-framework_%.bbappend @@ -5,11 +5,13 @@ SRC_URI += " \ file://kmsglog \ file://machineid \ file://opendisk \ + file://aosoverlay \ file://rundir \ file://vardir \ " PACKAGES += " \ + initramfs-module-aosoverlay \ initramfs-module-aosupdate \ initramfs-module-kmsglog \ initramfs-module-machineid \ @@ -32,6 +34,16 @@ RRECOMMENDS:initramfs-module-aosupdate = " \ ', '', d)} \ " + +SUMMARY:initramfs-module-aosoverlay = "initramfs support for overlaying a source over rootfs" +RDEPENDS:initramfs-module-aosoverlay = "${PN}-base" +FILES:initramfs-module-aosoverlay = "/init.d/97-aosoverlay" +RRECOMMENDS:initramfs-module-aosoverlay = " \ + kernel-module-loop \ + kernel-module-overlay \ + kernel-module-squashfs \ +" + SUMMARY:initramfs-module-kmsglog = "redirect log messages to kmsg" RDEPENDS:initramfs-module-kmsglog = "${PN}-base" FILES:initramfs-module-kmsglog = "/init.d/00-kmsglog" @@ -53,6 +65,9 @@ RDEPENDS:initramfs-module-vardir = "${PN}-base" FILES:initramfs-module-vardir = "/init.d/02-vardir" do_install:append() { + # aosoverlay + install -m 0755 ${WORKDIR}/aosoverlay ${D}/init.d/97-aosoverlay + # aosupdate install -m 0755 ${WORKDIR}/aosupdate ${D}/init.d/95-aosupdate From deb1cd3342938e81ca8f506e2b3caa55b387b1c2 Mon Sep 17 00:00:00 2001 From: Oleksandr Grytsov Date: Mon, 8 Jun 2026 15:46:48 +0300 Subject: [PATCH 2/3] aosoverlay: support mounting multiple items Signed-off-by: Oleksandr Grytsov --- .../initramfs-framework/aosoverlay | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/recipes-core/initrdscripts/initramfs-framework/aosoverlay b/recipes-core/initrdscripts/initramfs-framework/aosoverlay index b60926ea..817f5924 100644 --- a/recipes-core/initrdscripts/initramfs-framework/aosoverlay +++ b/recipes-core/initrdscripts/initramfs-framework/aosoverlay @@ -1,10 +1,10 @@ #!/bin/sh -# This module overlays a source over the rootfs: -# aosoverlay.path - specifies overlay source: a squashfs image file or a directory. -# If a file (or symlink to a file), it is loop-mounted to /mnt/overlay -# before being overlaid. If a directory (or symlink to a directory), -# it is used directly. +# This module overlays multiple sources over the rootfs: +# aosoverlay.path - specifies a directory containing squashfs image files and +# subdirectories. Each squashfs file is loop-mounted first, then +# all mounted images and subdirectories are stacked over ROOTFS_DIR +# using overlayfs (files take priority over directories). OVERLAY_MOUNT="/mnt/overlay" @@ -14,7 +14,7 @@ aosoverlay_enabled() { return 1 fi - if [ ! -e "${bootparam_aosoverlay_path}" ]; then + if [ ! -d "${bootparam_aosoverlay_path}" ]; then msg "Aos overlay disabled: ${bootparam_aosoverlay_path} does not exist." return 1 fi @@ -25,22 +25,33 @@ aosoverlay_enabled() { aosoverlay_run() { msg "Aos overlay: applying ${bootparam_aosoverlay_path} over rootfs" - real_src=$(readlink -f "$bootparam_aosoverlay_path") + lower_dirs="" - if [ -f "$real_src" ]; then - msg "Aos overlay: mounting image ${real_src} to ${OVERLAY_MOUNT}" + # Mount squashfs files first + for img in "$bootparam_aosoverlay_path"/*; do + [ -f "$img" ] || continue + name=$(basename "$img") + mnt="${OVERLAY_MOUNT}/${name}" - mkdir -p "$OVERLAY_MOUNT" - mount -t squashfs -o loop "$real_src" "$OVERLAY_MOUNT" + msg "Aos overlay: mounting ${img} to ${mnt}" - overlay_dir="$OVERLAY_MOUNT" - elif [ -d "$real_src" ]; then - overlay_dir="$real_src" - else - fatal "Aos overlay: ${real_src} is not a regular file or directory" + mkdir -p "$mnt" + mount -t squashfs -o loop "$img" "$mnt" + + lower_dirs="${lower_dirs}${lower_dirs:+:}${mnt}" + done + + # Add subdirectories + for dir in "$bootparam_aosoverlay_path"/*; do + [ -d "$dir" ] || continue + lower_dirs="${lower_dirs}${lower_dirs:+:}${dir}" + done + + if [ -z "$lower_dirs" ]; then + fatal "Aos overlay: no squashfs files or directories found in ${bootparam_aosoverlay_path}" fi - msg "Aos overlay: mounting ${overlay_dir} over ${ROOTFS_DIR}" + msg "Aos overlay: mounting ${lower_dirs} over ${ROOTFS_DIR}" - mount -t overlay overlay -o lowerdir="${overlay_dir}":"${ROOTFS_DIR}" "$ROOTFS_DIR" + mount -t overlay overlay -o lowerdir="${lower_dirs}:${ROOTFS_DIR}" "$ROOTFS_DIR" } From 4e74aba2e1515a4ebe76f0e092ba2bf018678dcb Mon Sep 17 00:00:00 2001 From: Oleksandr Grytsov Date: Tue, 9 Jun 2026 14:27:01 +0300 Subject: [PATCH 3/3] Add upperdir and workdir Signed-off-by: Oleksandr Grytsov --- .../initramfs-framework/aosoverlay | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/recipes-core/initrdscripts/initramfs-framework/aosoverlay b/recipes-core/initrdscripts/initramfs-framework/aosoverlay index 817f5924..95380a9f 100644 --- a/recipes-core/initrdscripts/initramfs-framework/aosoverlay +++ b/recipes-core/initrdscripts/initramfs-framework/aosoverlay @@ -1,10 +1,12 @@ #!/bin/sh # This module overlays multiple sources over the rootfs: -# aosoverlay.path - specifies a directory containing squashfs image files and -# subdirectories. Each squashfs file is loop-mounted first, then -# all mounted images and subdirectories are stacked over ROOTFS_DIR -# using overlayfs (files take priority over directories). +# aosoverlay.path - specifies a directory containing squashfs image files and +# subdirectories. Each squashfs file is loop-mounted first, then +# all mounted images and subdirectories are stacked over ROOTFS_DIR +# using overlayfs (files take priority over directories). +# aosoverlay.upperdir - (optional) upperdir for the overlay mount, making ROOTFS_DIR writable. +# aosoverlay.workdir - (optional) workdir for the overlay mount; required when upperdir is set. OVERLAY_MOUNT="/mnt/overlay" @@ -25,6 +27,10 @@ aosoverlay_enabled() { aosoverlay_run() { msg "Aos overlay: applying ${bootparam_aosoverlay_path} over rootfs" + if [ -n "${bootparam_aosoverlay_upperdir}" ] && [ -z "${bootparam_aosoverlay_workdir}" ]; then + fatal "Aos overlay: aosoverlay.workdir is required when aosoverlay.upperdir is set" + fi + lower_dirs="" # Mount squashfs files first @@ -48,10 +54,18 @@ aosoverlay_run() { done if [ -z "$lower_dirs" ]; then - fatal "Aos overlay: no squashfs files or directories found in ${bootparam_aosoverlay_path}" + msg "Aos overlay: no squashfs files or directories found in ${bootparam_aosoverlay_path}, skipping" + return fi msg "Aos overlay: mounting ${lower_dirs} over ${ROOTFS_DIR}" - mount -t overlay overlay -o lowerdir="${lower_dirs}:${ROOTFS_DIR}" "$ROOTFS_DIR" + if [ -n "${bootparam_aosoverlay_upperdir}" ] && [ -n "${bootparam_aosoverlay_workdir}" ]; then + mkdir -p "${bootparam_aosoverlay_upperdir}" "${bootparam_aosoverlay_workdir}" + mount -t overlay overlay \ + -o lowerdir="${lower_dirs}:${ROOTFS_DIR}",upperdir="${bootparam_aosoverlay_upperdir}",workdir="${bootparam_aosoverlay_workdir}" \ + "$ROOTFS_DIR" + else + mount -t overlay overlay -o lowerdir="${lower_dirs}:${ROOTFS_DIR}" "$ROOTFS_DIR" + fi }