Initial commit

This commit is contained in:
Your Name
2026-04-23 17:07:55 +08:00
commit b7e39e063b
16725 changed files with 1625565 additions and 0 deletions
@@ -0,0 +1,24 @@
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
SRC_URI += "file://init"
inherit allarch
inherit update-alternatives
do_install() {
install -d ${D}/${base_sbindir}
install -m 0755 ${WORKDIR}/init ${D}/${base_sbindir}/preinit-mounts
}
RDEPENDS:${PN} += "${VIRTUAL-RUNTIME_base-utils}"
FILES:${PN} += "${base_sbindir}/init"
ALTERNATIVE_LINK_NAME[init] = "${base_sbindir}/init"
# Use a number higher than the systemd init alternative so that
# ours is enabled instead.
ALTERNATIVE_PRIORITY[init] ?= "400"
ALTERNATIVE:${PN} = "init"
ALTERNATIVE_TARGET[init] = "${base_sbindir}/preinit-mounts"
@@ -0,0 +1,63 @@
#!/bin/sh
mount_overlay() {
if ! mount overlay /etc -t overlay -o defaults,lowerdir=/etc,upperdir=/var/persist/etc,workdir=/var/persist/etc-work; then
mount overlay /etc -t overlay -o defaults,lowerdir=/etc:/var/persist/etc
fi
}
recreate_overlay() {
# Attempt to re-create the overlay by moving out the overlay contents and
# copying them back to /etc, which would create them back in the overlay
cd /
if ! umount /etc; then
return
fi
rm -rf /var/persist/etc-save
mv /var/persist/etc /var/persist/etc-save
mkdir -p /var/persist/etc
mount_overlay
cp -rp /var/persist/etc-save/* /etc/
rm -rf /var/persist/etc-save
}
if ! mount ubi0:rwfs /var -t ubifs -o defaults; then
if ! mount ubi0:rwfs /var -t ubifs -o defaults,ro; then
mount tmpfs /var -t tmpfs -o defaults
fi
fi
mkdir -p /var/persist/etc /var/persist/etc-work /var/persist/home/root
rm -rf /var/persist/etc-work/*
# rm -rf specifically skips . and .. directories; pipe all output to null to avoid the error message
rm -rf /var/persist/etc-work/.* > /dev/null 2>&1
mount_overlay
# Check if there are any issues accessing the files in /etc after mounting the
# overlay by doing an 'ls' command
error="/var/overlay-error"
recreate_overlay_done=
files=$(find /var/persist/etc -type f | sed 's#/var/persist/etc/##')
for i in $files; do
ls -i "/etc/$i" >/dev/null 2>${error};
if [ -s ${error} ]; then
# We don't have a way to print this error to the journal, delete it
rm -f ${error}
if test -n "$recreate_overlay_done"; then
recreate_overlay
recreate_overlay_done="true"
fi
# Check file once more
ls -i "/etc/$i" >/dev/null 2>${error};
if [ -s ${error} ]; then
# File still corrupted, delete it from the overlay
echo "Removing corrupted file from overlay: $i"
rm -f ${error}
rm -f "/var/persist/etc/$i"
fi
fi
done
exec /lib/systemd/systemd