From 769ae5571a5501cbe9c3b12c560a3e6916bff4ca Mon Sep 17 00:00:00 2001 From: Gatis Paeglis Date: Sun, 21 Feb 2016 10:37:05 +0100 Subject: NUC: Use custom image layout This patch adds a new image class 'image_dd', by default it has an empty boot partition. image_dd_efi extends this class to support Intel NUC board. The layout of a generated image is a prerequisite for OSTree integarion. Image generated by 'hddimg' produces rootfs.img (ext3 filesystem file) and then "live" boots it from initramfs by mounting rootfs.img via loop device. For OTA integration we need to access contents of rootfs.img already from boot loader. The custom 'image_nuc_efi' layout allow for fully atomic updates on EFI based system, by keeping GRUB-EFI binary on a dedicated EFI system partition (ESP). OSTree currently is not fully atomic on EFI systems, but with this setup we use GRUB-BIOS code path in OSTree, which is atomic. After EFI firmware has loaded the GRUB-EFI binary, everything else is done on rootfs parition. One limitation from the above scenario is that you would need to update /EFI/BOOT/bootx64.efi (GRUB-EFI) binary manually. Not sure how common it is to update a boot loader binary on a deployed system, but its not impossible. Change-Id: Ibf2840aecd548000372131c4ded5cffa11ff1b0f Reviewed-by: Teemu Holappa --- recipes/initramfs-basic/files/init.sh | 102 ++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 recipes/initramfs-basic/files/init.sh (limited to 'recipes/initramfs-basic/files/init.sh') diff --git a/recipes/initramfs-basic/files/init.sh b/recipes/initramfs-basic/files/init.sh new file mode 100644 index 0000000..3db235b --- /dev/null +++ b/recipes/initramfs-basic/files/init.sh @@ -0,0 +1,102 @@ +#!/bin/sh + +PATH=/sbin:/bin:/usr/sbin:/usr/bin +ROOT_MOUNT="/sysroot/" +ROOT_DEVICE="" + +early_setup() { + + mkdir -p /proc + mkdir -p /sys + mount -t proc proc /proc + mount -t sysfs sysfs /sys + mount -t devtmpfs none /dev + + mkdir -p /run + mkdir -p /var/run +} + +read_args() { + + for arg in $(cat /proc/cmdline); do + value=$(echo ${arg} | cut -s -f2- -d '=') + case $arg in + root=*) + root=$value + ;; + debugshell*) + if [ -z "$value" ]; then + shelltimeout=30 + else + shelltimeout=$value + fi + ;; + esac + done + + if [ -z "$root" ] ; then + debug_shell "No root= specified via kernel command line." + else + case $root in + LABEL=*) + label=${root#LABEL=} + ;; + *) + debug_shell "This init script only supports root=LABEL=* for specifying root file system, but root=$root was provided." + ;; + esac + fi +} + +mount_rootfs() { + + mkdir -p $ROOT_MOUNT + mount $ROOT_DEVICE $ROOT_MOUNT + mount -n --move /proc $ROOT_MOUNT/proc + mount -n --move /sys $ROOT_MOUNT/sys + mount -n --move /dev $ROOT_MOUNT/dev + + exec switch_root $ROOT_MOUNT /sbin/init || debug_shell "Couldn't switch_root." +} + +switch_real_root() { + + echo "Searching for media..." + C=0 + while true + do + + rootfs=$(findfs LABEL=$label) + if [ -n "$rootfs" ] ; then + ROOT_DEVICE=$rootfs + mount_rootfs + fi + + # don't wait for more than $shelltimeout seconds, if it's set + if [ -n "$shelltimeout" ]; then + echo -n " " $(( $shelltimeout - $C )) + if [ $C -ge $shelltimeout ]; then + debug_shell "Cannot find root file system." + fi + C=$(( C + 1 )) + fi + + sleep 1 + done +} + +debug_shell() { + + echo ${1} + echo "Dropping to a shell." + exec sh +} + +main() { + + early_setup + read_args + switch_real_root +} + +main -- cgit v1.2.3-54-g00ecf