From e8b8d4c0cd6926b82b9c502e646cf52dc3d80bb2 Mon Sep 17 00:00:00 2001 From: Lucien Mueller Date: Wed, 12 Dec 2018 11:22:33 +0100 Subject: [PATCH] ostree-initrd: Suppressed init-script informational output. Fixed initramfs unmount bug. BugzID: 54171 Signed-off-by: Lucien Mueller --- recipes-sota/ostree-initrd/files/init.sh | 76 +++++++++++++++++++ .../ostree-initrd/ostree-initrd.bbappend | 3 + 2 files changed, 79 insertions(+) create mode 100644 recipes-sota/ostree-initrd/files/init.sh create mode 100644 recipes-sota/ostree-initrd/ostree-initrd.bbappend diff --git a/recipes-sota/ostree-initrd/files/init.sh b/recipes-sota/ostree-initrd/files/init.sh new file mode 100644 index 0000000..09a04e0 --- /dev/null +++ b/recipes-sota/ostree-initrd/files/init.sh @@ -0,0 +1,76 @@ +#!/bin/sh +set -eu + +# ------------------------------------------- + +log_error() { echo "$0[$$]: ERROR $*" >&2; } + +do_mount_fs() { + [[ -e /proc/filesystems ]] && { grep -q "$1" /proc/filesystems || { log_error "Unknown filesystem"; return 1; } } + [[ -d "$2" ]] || mkdir -p "$2" + [[ -e /proc/mounts ]] && { grep -q -e "^$1 $2 $1" /proc/mounts && { return 0; } } + mount -t "$1" "$1" "$2" +} + +bail_out() { + log_error "$@" + #exec reboot -f + exec sh +} + +get_ostree_sysroot() { + for opt in $(cat /proc/cmdline); do + arg=$(echo "$opt" | cut -d'=' -f1) + if [ "$arg" == "ostree_root" ]; then + echo "$opt" | cut -d'=' -f2- + return + fi + done + echo "LABEL=otaroot" +} + +export PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/lib/ostree + + +do_mount_fs proc /proc +do_mount_fs sysfs /sys +do_mount_fs devpts /dev/pts +do_mount_fs tmpfs /dev/shm +do_mount_fs tmpfs /tmp +do_mount_fs tmpfs /run + +# check if smack is active (and if so, mount smackfs) +grep -q smackfs /proc/filesystems && { + do_mount_fs smackfs /sys/fs/smackfs + + # adjust current label and network label + echo System >/proc/self/attr/current + echo System >/sys/fs/smackfs/ambient +} + +mkdir -p /sysroot +ostree_sysroot=$(get_ostree_sysroot) + +mount "$ostree_sysroot" /sysroot || { + # The SD card in the R-Car M3 takes a bit of time to come up + # Retry the mount if it fails the first time + sleep 5 + mount "$ostree_sysroot" /sysroot || bail_out "Unable to mount $ostree_sysroot as physical sysroot" +} +ostree-prepare-root /sysroot > /dev/null 2>&1 + +# move mounted devices to new root +cd /sysroot +for x in dev proc run; do + mount -o move "/$x" "$x" +done + +# switch to new rootfs +mkdir -p run/initramfs + +pivot_root . run/initramfs || bail_out "pivot_root failed." + + +exec chroot . sh -c 'umount /run/initramfs/tmp; umount /run/initramfs/sys; umount /run/initramfs; exec /sbin/init' \ + dev/console 2>&1 + diff --git a/recipes-sota/ostree-initrd/ostree-initrd.bbappend b/recipes-sota/ostree-initrd/ostree-initrd.bbappend new file mode 100644 index 0000000..746c3c5 --- /dev/null +++ b/recipes-sota/ostree-initrd/ostree-initrd.bbappend @@ -0,0 +1,3 @@ +FILESEXTRAPATHS_prepend := "${THISDIR}/files:" + +SRC_URI += "file://init.sh"