Skip to content

Commit

Permalink
meta-phosphor: add phosphor-static-norootfs-init recipe
Browse files Browse the repository at this point in the history
There are two existing recipes for early mounting procedures:
  * preinit-mounts - for obmc-ubi-fs
  * phosphor-mmc-init - for phosphor-mmc

Add one for the static-norootfs image type.  This one is similar to
the preinit-mounts, except for it mounts /var as an overlay to avoid
violating FHS expectations (See #3658 as an example of
why this is problematic).  I did not directly change preinit-mounts and
fix it because there are likely field upgrade issues in doing this for
existing users.

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I62ab288c2d139cfecadeb191d576e2753120e123
  • Loading branch information
williamspatrick committed Feb 10, 2023
1 parent 139d2d6 commit d91b4b3
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ do_install:append() {
}

RDEPENDS:${PN}:append:df-obmc-ubi-fs = " preinit-mounts"
RDEPENDS:${PN}:append:df-obmc-static-norootfs = " phosphor-static-norootfs-init"
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
SUMMARY = "Phosphor OpenBMC pre-init scripts for static-norootfs layout"
DESCRIPTION = "Phosphor OpenBMC filesystem mount implementation for static-norootfs"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/files/common-licenses/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
PR = "r1"

SOURCE_FILES = "\
init \
10-early-mounts \
20-udev \
30-ubiattach-or-format \
50-mount-persistent \
"
SRC_URI += "\
${@' '.join(\
[ 'file://' + x for x in d.getVar('SOURCE_FILES', True).split()])} \
"

S = "${WORKDIR}"

inherit allarch
inherit update-alternatives

PKG_INSTALL_DIR="${libexecdir}/${BPN}"
FILES:${PN} += "${PKG_INSTALL_DIR}"

do_install() {
install -d ${D}${PKG_INSTALL_DIR}

for f in ${SOURCE_FILES} ; do
install -m 0755 ${S}/$f ${D}${PKG_INSTALL_DIR}/$f
done
}

RDEPENDS:${PN} += " \
${VIRTUAL-RUNTIME_base-utils} \
mtd-utils-ubifs \
udev \
"

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] = "${PKG_INSTALL_DIR}/init"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

mount dev dev -tdevtmpfs
mount sys sys -tsysfs
mount proc proc -tproc
mount tmpfs run -t tmpfs -o mode=755,nodev
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

# We need to run udevd in order to get the /dev/mtd volumes to show up.
if udevd --daemon; then
udevadm trigger --type=devices --action=add && \
udevadm settle --timeout=10

udevadm control --exit
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

if [ ! -e /dev/mtd/rwfs ]; then
exit 1
fi

if ! ubiattach -p /dev/mtd/rwfs > /dev/null ; then
if ! ubiformat --yes /dev/mtd/rwfs ; then
exit 1
fi

if ! ubiattach -p /dev/mtd/rwfs ; then
exit 1
fi

if ! ubimkvol /dev/ubi0 -N rwfs -m ; then
exit 1
fi
fi

mkdir -p /run/mnt-persist
mount -t ubifs ubi0:rwfs /run/mnt-persist -o sync,compr=zstd
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/sh

PERSIST=/run/mnt-persist

if [ ! -d $PERSIST ]; then
exit 0
fi

for m in var etc home/root; do
if [ ! -d $PERSIST/$m-data ]; then
mkdir -p $PERSIST/$m-data
fi

if [ ! -d $PERSIST/$m-work ]; then
mkdir -p $PERSIST/$m-work
fi

mount overlay /$m -t overlay -o \
lowerdir=/$m,upperdir=$PERSIST/$m-data,workdir=$PERSIST/$m-work
done
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

cd /

for f in /usr/libexec/phosphor-static-norootfs-init/*; do
if [ "$(basename "$f")" = "init" ]; then
continue
fi

$f
done

exec /lib/systemd/systemd

0 comments on commit d91b4b3

Please sign in to comment.