diff options
Diffstat (limited to 'meta/recipes-core/initrdscripts')
25 files changed, 448 insertions, 95 deletions
diff --git a/meta/recipes-core/initrdscripts/files/init-install-efi-testfs.sh b/meta/recipes-core/initrdscripts/files/init-install-efi-testfs.sh index 9c4b263d54..4bd6ace7b3 100644 --- a/meta/recipes-core/initrdscripts/files/init-install-efi-testfs.sh +++ b/meta/recipes-core/initrdscripts/files/init-install-efi-testfs.sh @@ -27,7 +27,7 @@ do # Try sleeping here to avoid getting kernel messages # obscuring/confusing user sleep 5 - echo "Found drive at /dev/${device}. Do you want to install this image there ? [y/n]" + echo "Found drive at /dev/${device}. Do you want to install this image there? [y/n]" read answer if [ "$answer" = "y" ] ; then break @@ -133,12 +133,12 @@ mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /rootmnt echo "Copying rootfs files..." cp -a /rootmnt/* /ssd -touch /ssd/etc/masterimage +touch /ssd/etc/controllerimage if [ -d /ssd/etc/ ] ; then # We dont want udev to mount our root device while we're booting... if [ -d /ssd/etc/udev/ ] ; then - echo "/dev/${device}" >> /ssd/etc/udev/mount.blacklist + echo "/dev/${device}" >> /ssd/etc/udev/mount.ignorelist fi fi diff --git a/meta/recipes-core/initrdscripts/files/init-install-efi.sh b/meta/recipes-core/initrdscripts/files/init-install-efi.sh index 706418fa9c..ffd3870199 100644 --- a/meta/recipes-core/initrdscripts/files/init-install-efi.sh +++ b/meta/recipes-core/initrdscripts/files/init-install-efi.sh @@ -8,8 +8,19 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin -# We need 20 Mb for the boot partition -boot_size=20 +# figure out how big of a boot partition we need +boot_size=$(du -ms /run/media/$1/ | awk '{print $1}') +# remove rootfs.img ($2) from the size if it exists, as its not installed to /boot +if [ -e /run/media/$1/$2 ]; then + boot_size=$(( boot_size - $( du -ms /run/media/$1/$2 | awk '{print $1}') )) +fi +# remove initrd from size since its not currently installed +if [ -e /run/media/$1/initrd ]; then + boot_size=$(( boot_size - $( du -ms /run/media/$1/initrd | awk '{print $1}') )) +fi +# add 10M to provide some extra space for users and account +# for rounding in the above subtractions +boot_size=$(( boot_size + 10 )) # 5% for swap swap_ratio=5 @@ -179,7 +190,7 @@ parted ${device} mkpart boot fat32 0% $boot_size parted ${device} set 1 boot on echo "Creating rootfs partition on $rootfs" -parted ${device} mkpart root ext3 $rootfs_start $rootfs_end +parted ${device} mkpart root ext4 $rootfs_start $rootfs_end echo "Creating swap partition on $swap" parted ${device} mkpart swap linux-swap $swap_start 100% @@ -196,8 +207,8 @@ done echo "Formatting $bootfs to vfat..." mkfs.vfat $bootfs -echo "Formatting $rootfs to ext3..." -mkfs.ext3 $rootfs +echo "Formatting $rootfs to ext4..." +mkfs.ext4 $rootfs echo "Formatting swap partition...($swap)" mkswap $swap @@ -218,7 +229,7 @@ if [ -d /tgt_root/etc/ ] ; then echo "UUID=$boot_uuid /boot vfat defaults 1 2" >> /tgt_root/etc/fstab # We dont want udev to mount our root device while we're booting... if [ -d /tgt_root/etc/udev/ ] ; then - echo "${device}" >> /tgt_root/etc/udev/mount.blacklist + echo "${device}" >> /tgt_root/etc/udev/mount.ignorelist fi fi @@ -244,10 +255,9 @@ if [ -f /run/media/$1/EFI/BOOT/grub.cfg ]; then sed -i "/initrd /d" $GRUBCFG # Delete any LABEL= strings sed -i "s/ LABEL=[^ ]*/ /" $GRUBCFG - # Delete any root= strings - sed -i "s/ root=[^ ]*/ /g" $GRUBCFG - # Add the root= and other standard boot options - sed -i "s@linux /vmlinuz *@linux /vmlinuz root=PARTUUID=$root_part_uuid rw $rootwait quiet @" $GRUBCFG + # Replace root= and add additional standard boot options + # We use root as a sentinel value, as vmlinuz is no longer guaranteed + sed -i "s/ root=[^ ]*/ root=PARTUUID=$root_part_uuid rw $rootwait quiet /g" $GRUBCFG fi if [ -d /run/media/$1/loader ]; then @@ -269,13 +279,24 @@ fi umount /tgt_root -cp /run/media/$1/vmlinuz /boot +# copy any extra files needed for ESP +if [ -d /run/media/$1/esp ]; then + cp -r /run/media/$1/esp/* /boot +fi + +# Copy kernel artifacts. To add more artifacts just add to types +# For now just support kernel types already being used by something in OE-core +for types in bzImage zImage vmlinux vmlinuz fitImage; do + for kernel in `find /run/media/$1/ -name $types*`; do + cp $kernel /boot + done +done umount /boot sync -echo "Remove your installation media, and press ENTER" +echo "Installation successful. Remove your installation media and press ENTER to reboot." read enter diff --git a/meta/recipes-core/initrdscripts/files/init-install-testfs.sh b/meta/recipes-core/initrdscripts/files/init-install-testfs.sh index ac62160528..8ab74ddc5d 100644 --- a/meta/recipes-core/initrdscripts/files/init-install-testfs.sh +++ b/meta/recipes-core/initrdscripts/files/init-install-testfs.sh @@ -158,13 +158,13 @@ mount -o rw,loop,noatime,nodiratime /run/media/$1/$2 /src_root echo "Copying rootfs files..." cp -a /src_root/* /tgt_root -touch /tgt_root/etc/masterimage +touch /tgt_root/etc/controllerimage if [ -d /tgt_root/etc/ ] ; then echo "$bootfs /boot ext3 defaults 1 2" >> /tgt_root/etc/fstab # We dont want udev to mount our root device while we're booting... if [ -d /tgt_root/etc/udev/ ] ; then - echo "/dev/${device}" >> /tgt_root/etc/udev/mount.blacklist + echo "/dev/${device}" >> /tgt_root/etc/udev/mount.ignorelist fi fi umount /tgt_root diff --git a/meta/recipes-core/initrdscripts/files/init-install.sh b/meta/recipes-core/initrdscripts/files/init-install.sh index dade059c8f..df33791ec7 100644 --- a/meta/recipes-core/initrdscripts/files/init-install.sh +++ b/meta/recipes-core/initrdscripts/files/init-install.sh @@ -7,8 +7,19 @@ PATH=/sbin:/bin:/usr/sbin:/usr/bin -# We need 20 Mb for the boot partition -boot_size=20 +# figure out how big of a boot partition we need +boot_size=$(du -ms /run/media/$1/ | awk '{print $1}') +# remove rootfs.img ($2) from the size if it exists, as its not installed to /boot +if [ -e /run/media/$1/$2 ]; then + boot_size=$(( boot_size - $( du -ms /run/media/$1/$2 | awk '{print $1}') )) +fi +# remove initrd from size since its not currently installed +if [ -e /run/media/$1/initrd ]; then + boot_size=$(( boot_size - $( du -ms /run/media/$1/initrd | awk '{print $1}') )) +fi +# add 10M to provide some extra space for users and account +# for rounding in the above subtractions +boot_size=$(( boot_size + 10 )) # 5% for the swap swap_ratio=5 @@ -203,7 +214,7 @@ fi echo "Creating rootfs partition on $rootfs" [ $grub_version -eq 0 ] && pname='primary' || pname='root' -parted ${device} mkpart $pname ext3 $rootfs_start $rootfs_end +parted ${device} mkpart $pname ext4 $rootfs_start $rootfs_end echo "Creating swap partition on $swap" [ $grub_version -eq 0 ] && pname='primary' || pname='swap' @@ -221,8 +232,8 @@ done echo "Formatting $bootfs to ext3..." mkfs.ext3 $bootfs -echo "Formatting $rootfs to ext3..." -mkfs.ext3 $rootfs +echo "Formatting $rootfs to ext4..." +mkfs.ext4 $rootfs echo "Formatting swap partition...($swap)" mkswap $swap @@ -250,15 +261,40 @@ if [ -d /tgt_root/etc/ ] ; then echo "$bootdev /boot ext3 defaults 1 2" >> /tgt_root/etc/fstab # We dont want udev to mount our root device while we're booting... if [ -d /tgt_root/etc/udev/ ] ; then - echo "${device}" >> /tgt_root/etc/udev/mount.blacklist + echo "${device}" >> /tgt_root/etc/udev/mount.ignorelist fi fi umount /tgt_root umount /src_root +echo "Looking for kernels to use as boot target.." +# Find kernel to boot to +# Give user options if multiple are found +kernels="$(find /run/media/$1/ -type f \ + -name bzImage* -o -name zImage* \ + -o -name vmlinux* -o -name vmlinuz* \ + -o -name fitImage* \ + | sed s:.*/::)" +if [ -n "$(echo $kernels)" ]; then + # only one kernel entry if no space + if [ -z "$(echo $kernels | grep " ")" ]; then + kernel=$kernels + echo "$kernel will be used as the boot target" + else + echo "Which kernel do we want to boot by default? The following kernels were found:" + echo $kernels + read answer + kernel=$answer + fi +else + echo "No kernels found, exiting..." + exit 1 +fi + # Handling of the target boot partition mount $bootfs /boot echo "Preparing boot partition..." + if [ -f /etc/grub.d/00_header -a $grub_version -ne 0 ] ; then echo "Preparing custom grub2 menu..." root_part_uuid=$(blkid -o value -s PARTUUID ${rootfs}) @@ -266,9 +302,11 @@ if [ -f /etc/grub.d/00_header -a $grub_version -ne 0 ] ; then GRUBCFG="/boot/grub/grub.cfg" mkdir -p $(dirname $GRUBCFG) cat >$GRUBCFG <<_EOF +timeout=5 +default=0 menuentry "Linux" { search --no-floppy --fs-uuid $boot_uuid --set root - linux /vmlinuz root=PARTUUID=$root_part_uuid $rootwait rw $5 $3 $4 quiet + linux /$kernel root=PARTUUID=$root_part_uuid $rootwait rw $5 $3 $4 quiet } _EOF chmod 0444 $GRUBCFG @@ -282,10 +320,16 @@ if [ $grub_version -eq 0 ] ; then echo "timeout 30" >> /boot/grub/menu.lst echo "title Live Boot/Install-Image" >> /boot/grub/menu.lst echo "root (hd0,0)" >> /boot/grub/menu.lst - echo "kernel /vmlinuz root=$rootfs rw $3 $4 quiet" >> /boot/grub/menu.lst + echo "kernel /$kernel root=$rootfs rw $3 $4 quiet" >> /boot/grub/menu.lst fi -cp /run/media/$1/vmlinuz /boot/ +# Copy kernel artifacts. To add more artifacts just add to types +# For now just support kernel types already being used by something in OE-core +for types in bzImage zImage vmlinux vmlinuz fitImage; do + for kernel in `find /run/media/$1/ -name $types*`; do + cp $kernel /boot + done +done umount /boot diff --git a/meta/recipes-core/initrdscripts/files/init-live.sh b/meta/recipes-core/initrdscripts/files/init-live.sh index 46cab6cc77..b20660b60a 100644..100755 --- a/meta/recipes-core/initrdscripts/files/init-live.sh +++ b/meta/recipes-core/initrdscripts/files/init-live.sh @@ -28,8 +28,7 @@ udev_daemon() { _UDEV_DAEMON=`udev_daemon` early_setup() { - mkdir -p /proc - mkdir -p /sys + mkdir -p /proc /sys /run /var/run mount -t proc proc /proc mount -t sysfs sysfs /sys mount -t devtmpfs none /dev @@ -37,9 +36,6 @@ early_setup() { # support modular kernel modprobe isofs 2> /dev/null - mkdir -p /run - mkdir -p /var/run - $_UDEV_DAEMON --daemon udevadm trigger --action=add } @@ -95,8 +91,11 @@ boot_live_root() { # Move the mount points of some filesystems over to # the corresponding directories under the real root filesystem. for dir in `awk '/\/dev.* \/run\/media/{print $2}' /proc/mounts`; do - mkdir -p ${ROOT_MOUNT}/media/${dir##*/} - mount -n --move $dir ${ROOT_MOUNT}/media/${dir##*/} + # Parse any OCT or HEX encoded chars such as spaces + # in the mount points to actual ASCII chars + dir=`printf $dir` + mkdir -p "${ROOT_MOUNT}/media/${dir##*/}" + mount -n --move "$dir" "${ROOT_MOUNT}/media/${dir##*/}" done mount -n --move /proc ${ROOT_MOUNT}/proc mount -n --move /sys ${ROOT_MOUNT}/sys diff --git a/meta/recipes-core/initrdscripts/initramfs-boot_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-boot_1.0.bb index 7ae7969f5e..198459f2b2 100644 --- a/meta/recipes-core/initrdscripts/initramfs-boot_1.0.bb +++ b/meta/recipes-core/initrdscripts/initramfs-boot_1.0.bb @@ -3,14 +3,18 @@ LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" SRC_URI = "file://init-boot.sh" -PR = "r2" S = "${WORKDIR}" do_install() { install -m 0755 ${WORKDIR}/init-boot.sh ${D}/init + + # Create device nodes expected by some kernels in initramfs + # before even executing /init. + install -d ${D}/dev + mknod -m 622 ${D}/dev/console c 5 1 } inherit allarch -FILES_${PN} += " /init " +FILES:${PN} += "/init /dev/console" diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/exec b/meta/recipes-core/initrdscripts/initramfs-framework/exec new file mode 100644 index 0000000000..a8e2432bb6 --- /dev/null +++ b/meta/recipes-core/initrdscripts/initramfs-framework/exec @@ -0,0 +1,29 @@ +#!/bin/sh +# Copyright (C) 2017 O.S. Systems Software LTDA. +# Licensed on MIT + +EXEC_DIR=/exec.d # place to look for modules + +exec_enabled() { + return 0 +} + +exec_run() { + if [ ! -d $EXEC_DIR ]; then + msg "No contents to exec in $EXEC_DIR. Starting shell ..." + sh + fi + + # Load and run modules + for m in $EXEC_DIR/*; do + # Skip backup files + if [ "`echo $m | sed -e 's/\~$//'`" != "$m" ]; then + continue + fi + + debug "Starting $m" + + # process module + ./$m + done +} diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/finish b/meta/recipes-core/initrdscripts/initramfs-framework/finish index 717383ebac..ac0de9f996 100755 --- a/meta/recipes-core/initrdscripts/initramfs-framework/finish +++ b/meta/recipes-core/initrdscripts/initramfs-framework/finish @@ -12,8 +12,29 @@ finish_run() { fatal "ERROR: There's no '/dev' on rootfs." fi + # Unmount anything that was automounted by busybox via mdev-mount.sh. + # We're about to switch_root, and leaving anything mounted will prevent + # the next rootfs from modifying the block device. Ignore ROOT_DISK, + # if it was set by setup-live, because it'll be mounted over loopback + # to ROOTFS_DIR. + local dev + for dev in /run/media/*; do + if mountpoint -q "${dev}" && [ "${dev##*/}" != "${ROOT_DISK}" ]; then + umount -f "${dev}" || debug "Failed to unmount ${dev}" + fi + done + info "Switching root to '$ROOTFS_DIR'..." + debug "Moving basic mounts onto rootfs" + for dir in `awk '/\/dev.* \/run\/media/{print $2}' /proc/mounts`; do + # Parse any OCT or HEX encoded chars such as spaces + # in the mount points to actual ASCII chars + dir=`printf $dir` + mkdir -p "${ROOTFS_DIR}/media/${dir##*/}" + mount -n --move "$dir" "${ROOTFS_DIR}/media/${dir##*/}" + done + debug "Moving /dev, /proc and /sys onto rootfs..." mount --move /dev $ROOTFS_DIR/dev mount --move /proc $ROOTFS_DIR/proc diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/init b/meta/recipes-core/initrdscripts/initramfs-framework/init index 37527a840a..567694aff7 100755 --- a/meta/recipes-core/initrdscripts/initramfs-framework/init +++ b/meta/recipes-core/initrdscripts/initramfs-framework/init @@ -72,6 +72,7 @@ ROOTFS_DIR="/rootfs" # where to do the switch root MODULE_PRE_HOOKS="" # functions to call before running each module MODULE_POST_HOOKS="" # functions to call after running each module MODULES_DIR=/init.d # place to look for modules +EFI_DIR=/sys/firmware/efi # place to store device firmware information # make mount stop complaining about missing /etc/fstab touch /etc/fstab @@ -81,14 +82,31 @@ mkdir -p /proc /sys /run/lock /var/lock mount -t proc proc /proc mount -t sysfs sysfs /sys +if [ -d $EFI_DIR ];then + mount -t efivarfs none /sys/firmware/efi/efivars +fi + # populate bootparam environment for p in `cat /proc/cmdline`; do + if [ -n "$quoted" ]; then + value="$value $p" + if [ "`echo $p | sed -e 's/\"$//'`" != "$p" ]; then + eval "bootparam_${quoted}=${value}" + unset quoted + fi + continue + fi + opt=`echo $p | cut -d'=' -f1` - opt=`echo $opt | tr '.-' '__'` + opt=`echo $opt | sed -e 'y/.-/__/'` if [ "`echo $p | cut -d'=' -f1`" = "$p" ]; then eval "bootparam_${opt}=true" else value="`echo $p | cut -d'=' -f2-`" + if [ "`echo $value | sed -e 's/^\"//'`" != "$value" ]; then + quoted=${opt} + continue + fi eval "bootparam_${opt}=\"${value}\"" fi done diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/lvm b/meta/recipes-core/initrdscripts/initramfs-framework/lvm new file mode 100644 index 0000000000..7deeccb9a2 --- /dev/null +++ b/meta/recipes-core/initrdscripts/initramfs-framework/lvm @@ -0,0 +1,13 @@ +#!/bin/sh + +lvm_enabled() { + if ! lvscan |grep -i -w "inactive" &>/dev/null;then + return 1 + fi + return 0 +} + +lvm_run() { + lvm pvscan --cache --activate ay + udevadm trigger --action=add +} diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/nfsrootfs b/meta/recipes-core/initrdscripts/initramfs-framework/nfsrootfs new file mode 100644 index 0000000000..e67ee4c25d --- /dev/null +++ b/meta/recipes-core/initrdscripts/initramfs-framework/nfsrootfs @@ -0,0 +1,48 @@ +#!/bin/sh + +nfsrootfs_enabled() { + if [ ${bootparam_root} != "/dev/nfs" ] || [ -z ${bootparam_nfsroot} ]; then + return 1 + fi + return 0 +} + +nfsrootfs_run() { + local nfs_opts + local location + local flags + local server_ip + + nfs_opts="" + if [ "${bootparam_nfsroot#*,}" != "${bootparam_nfsroot}" ]; then + nfs_opts="-o ${bootparam_nfsroot#*,}" + fi + + location="${bootparam_nfsroot%%,*}" + if [ "${location#*:}" = "${location}" ]; then + # server-ip not given. Get server ip from ip option + server_ip="" + if [ "${bootparam_ip#*:}" != "${bootparam_ip}" ]; then + server_ip=$(echo "$bootparam_ip" | cut -d: -f2) + fi + + if [ -z "$server_ip" ]; then + fatal "Server IP is not set. Update ip or nfsroot options." + fi + location=${server_ip}:${location} + fi + + flags="-o nolock" + if [ -n "$bootparam_ro" ] && ! echo "$bootparam_rootflags" | grep -w -q "ro"; then + if [ -n "$bootparam_rootflags" ]; then + bootparam_rootflags="$bootparam_rootflags," + fi + bootparam_rootflags="${bootparam_rootflags}ro" + fi + if [ -n "$bootparam_rootflags" ]; then + flags="$flags -o $bootparam_rootflags" + fi + + mount -t nfs ${flags} ${nfs_opts} ${location} ${ROOTFS_DIR} +} + diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/overlayroot b/meta/recipes-core/initrdscripts/initramfs-framework/overlayroot new file mode 100644 index 0000000000..0d41432878 --- /dev/null +++ b/meta/recipes-core/initrdscripts/initramfs-framework/overlayroot @@ -0,0 +1,118 @@ +#!/bin/sh + +# SPDX-License-Identifier: MIT +# +# Copyright 2022 (C), Microsoft Corporation + +# Simple initramfs module intended to mount a read-write (RW) +# overlayfs on top of /, keeping the original root filesystem +# as read-only (RO), free from modifications by the user. +# +# NOTE: The read-only IMAGE_FEATURE is not required for this to work +# +# This script is based on the overlay-etc.bbclass, which sets up +# an overlay on top of the /etc directory, but in this case allows +# accessing the original, unmodified rootfs at /rofs after boot. +# +# It relies on the initramfs-module-rootfs to mount the original +# root filesystem, and requires 'overlayrootrwdev=<foo>' to be passed as a +# kernel parameter, specifying the device/partition intended to +# use as RW. +# Mount options of the RW device can be tweaked with 'overlayrootfstype=' +# (defaults to 'ext4') and 'overlayrootfsflags=' ('defaults'). +# +# This module needs to be executed after the initramfs-module-rootfs +# since it relies on it to mount the filesystem at initramfs startup +# but before the finish module which normally switches root. +# After overlayroot is executed the usual boot flow continues from +# the real init process. +# +# If something goes wrong while running this module, the rootfs +# is still mounted RO (with no overlay) and the finish module is +# executed to continue booting normally. +# +# It also has a dependency on overlayfs being enabled in the +# running kernel via KERNEL_FEATURES (kmeta) or any other means. + + +PATH=/sbin:/bin:/usr/sbin:/usr/bin + +# We get OLDROOT from the rootfs module +OLDROOT="/rootfs" + +NEWROOT="${RWMOUNT}/root" +RWMOUNT="/overlay" +ROMOUNT="${RWMOUNT}/rofs" +UPPER_DIR="${RWMOUNT}/upper" +WORK_DIR="${RWMOUNT}/work" + +MODULES_DIR=/init.d + +# Something went wrong, make sure / is mounted as read only anyway. +exit_gracefully() { + echo $1 >/dev/console + echo >/dev/console + echo "OverlayRoot mounting failed, starting system as read-only" >/dev/console + echo >/dev/console + + # The following is borrowed from rootfs-postcommands.bbclass + # This basically looks at the real rootfs mounting options and + # replaces them with "ro" + + # Tweak the mount option and fs_passno for rootfs in fstab + if [ -f ${OLDROOT}/etc/fstab ]; then + sed -i -e '/^[#[:space:]]*\/dev\/root/{s/defaults/ro/;s/\([[:space:]]*[[:digit:]]\)\([[:space:]]*\)[[:digit:]]$/\1\20/}' ${OLDROOT}/etc/fstab + fi + + # Tweak the "mount -o remount,rw /" command in busybox-inittab inittab + if [ -f ${OLDROOT}/etc/inittab ]; then + sed -i 's|/bin/mount -o remount,rw /|/bin/mount -o remount,ro /|' ${OLDROOT}/etc/inittab + fi + + # Continue as if the overlayroot module didn't exist to continue booting + . $MODULES_DIR/99-finish + eval "finish_run" +} + +# migrate legacy parameter +if [ ! -z "$bootparam_rootrw" ]; then + bootparam_overlayrootrwdev="$bootparam_rootrw" +fi + +if [ -z "$bootparam_overlayrootrwdev" ]; then + exit_gracefully "overlayrootrwdev= kernel parameter doesn't exist and its required to mount the overlayfs" +fi + +mkdir -p ${RWMOUNT} + +# Mount RW device +if mount -n -t ${bootparam_overlayrootfstype:-ext4} -o ${bootparam_overlayrootfsflags:-defaults} ${bootparam_overlayrootrwdev} ${RWMOUNT} +then + # Set up overlay directories + mkdir -p ${UPPER_DIR} + mkdir -p ${WORK_DIR} + mkdir -p ${NEWROOT} + mkdir -p ${ROMOUNT} + + # Remount OLDROOT as read-only + mount -o bind ${OLDROOT} ${ROMOUNT} + mount -o remount,ro ${ROMOUNT} + + # Mount RW overlay + mount -t overlay overlay -o lowerdir=${ROMOUNT},upperdir=${UPPER_DIR},workdir=${WORK_DIR} ${NEWROOT} || exit_gracefully "initramfs-overlayroot: Mounting overlay failed" +else + exit_gracefully "initramfs-overlayroot: Mounting RW device failed" +fi + +# Set up filesystems on overlay +mkdir -p ${NEWROOT}/proc +mkdir -p ${NEWROOT}/dev +mkdir -p ${NEWROOT}/sys +mkdir -p ${NEWROOT}/rofs + +mount -n --move ${ROMOUNT} ${NEWROOT}/rofs +mount -n --move /proc ${NEWROOT}/proc +mount -n --move /sys ${NEWROOT}/sys +mount -n --move /dev ${NEWROOT}/dev + +exec chroot ${NEWROOT}/ ${bootparam_init:-/sbin/init} || exit_gracefully "Couldn't chroot into overlay" diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/rootfs b/meta/recipes-core/initrdscripts/initramfs-framework/rootfs index 14768f1cd4..e0efbe6ebe 100644 --- a/meta/recipes-core/initrdscripts/initramfs-framework/rootfs +++ b/meta/recipes-core/initrdscripts/initramfs-framework/rootfs @@ -13,7 +13,7 @@ rootfs_run() { C=0 delay=${bootparam_rootdelay:-1} timeout=${bootparam_roottimeout:-5} - while [ ! -d $ROOTFS_DIR/dev ]; do + while ! mountpoint -q $ROOTFS_DIR; do if [ $(( $C * $delay )) -gt $timeout ]; then fatal "root '$bootparam_root' doesn't exist or does not contain a /dev." fi @@ -24,11 +24,15 @@ rootfs_run() { if [ "`echo ${bootparam_root} | cut -c1-5`" = "UUID=" ]; then root_uuid=`echo $bootparam_root | cut -c6-` bootparam_root="/dev/disk/by-uuid/$root_uuid" - fi - - if [ "`echo ${bootparam_root} | cut -c1-9`" = "PARTUUID=" ]; then - root_uuid=`echo $bootparam_root | cut -c10-` - bootparam_root="/dev/disk/by-partuuid/$root_uuid" + elif [ "`echo ${bootparam_root} | cut -c1-9`" = "PARTUUID=" ]; then + root_partuuid=`echo $bootparam_root | cut -c10-` + bootparam_root="/dev/disk/by-partuuid/$root_partuuid" + elif [ "`echo ${bootparam_root} | cut -c1-10`" = "PARTLABEL=" ]; then + root_partlabel=`echo $bootparam_root | cut -c11-` + bootparam_root="/dev/disk/by-partlabel/$root_partlabel" + elif [ "`echo ${bootparam_root} | cut -c1-6`" = "LABEL=" ]; then + root_label=`echo $bootparam_root | cut -c7-` + bootparam_root="/dev/disk/by-label/$root_label" fi if [ -e "$bootparam_root" ]; then @@ -46,14 +50,14 @@ rootfs_run() { flags="$flags -t$bootparam_rootfstype" fi mount $flags $bootparam_root $ROOTFS_DIR - if [ -d $ROOTFS_DIR/dev ]; then + if mountpoint -q $ROOTFS_DIR; then break else # It is unlikely to change, but keep trying anyway. # Perhaps we pick a different device next time. umount $ROOTFS_DIR - fi fi + fi fi debug "Sleeping for $delay second(s) to wait root to settle..." sleep $delay diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/setup-live b/meta/recipes-core/initrdscripts/initramfs-framework/setup-live index 4c79f41285..7e92f93322 100644 --- a/meta/recipes-core/initrdscripts/initramfs-framework/setup-live +++ b/meta/recipes-core/initrdscripts/initramfs-framework/setup-live @@ -1,4 +1,4 @@ -#/bin/sh +#!/bin/sh # Copyright (C) 2011 O.S. Systems Software LTDA. # Licensed on MIT diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/udev b/meta/recipes-core/initrdscripts/initramfs-framework/udev index 79c8867823..4898b89246 100644 --- a/meta/recipes-core/initrdscripts/initramfs-framework/udev +++ b/meta/recipes-core/initrdscripts/initramfs-framework/udev @@ -6,6 +6,7 @@ udev_shutdown_hook_handler() { status=$1 module=$2 if [ "$status" = "pre" ] && [ "$module" = "finish" ]; then + udevadm settle killall `basename $_UDEV_DAEMON` 2>/dev/null fi } @@ -40,6 +41,9 @@ udev_run() { mkdir -p /run mkdir -p /var/run + # Workaround if console=null, systemd-udevd needs valid stdin, stdout and stderr to work + sh -c "exec 4< /dev/console" || { exec 0> /dev/null; exec 1> /dev/null; exec 2> /dev/null; } + $_UDEV_DAEMON --daemon udevadm trigger --action=add udevadm settle diff --git a/meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb index 2afc37ee75..39ea51ccbd 100644 --- a/meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb +++ b/meta/recipes-core/initrdscripts/initramfs-framework_1.0.bb @@ -1,19 +1,23 @@ SUMMARY = "Modular initramfs system" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" -RDEPENDS_${PN} += "${VIRTUAL-RUNTIME_base-utils}" +RDEPENDS:${PN} += "${VIRTUAL-RUNTIME_base-utils}" +RRECOMMENDS:${PN} = "${VIRTUAL-RUNTIME_base-utils-syslog}" -PR = "r4" inherit allarch SRC_URI = "file://init \ + file://exec \ + file://nfsrootfs \ file://rootfs \ file://finish \ file://mdev \ file://udev \ file://e2fs \ file://debug \ + file://lvm \ + file://overlayroot \ " S = "${WORKDIR}" @@ -23,9 +27,13 @@ do_install() { # base install -m 0755 ${WORKDIR}/init ${D}/init + install -m 0755 ${WORKDIR}/nfsrootfs ${D}/init.d/85-nfsrootfs install -m 0755 ${WORKDIR}/rootfs ${D}/init.d/90-rootfs install -m 0755 ${WORKDIR}/finish ${D}/init.d/99-finish + # exec + install -m 0755 ${WORKDIR}/exec ${D}/init.d/89-exec + # mdev install -m 0755 ${WORKDIR}/mdev ${D}/init.d/01-mdev @@ -38,6 +46,12 @@ do_install() { # debug install -m 0755 ${WORKDIR}/debug ${D}/init.d/00-debug + # lvm + install -m 0755 ${WORKDIR}/lvm ${D}/init.d/09-lvm + + # overlayroot needs to run after rootfs module but before finish + install -m 0755 ${WORKDIR}/overlayroot ${D}/init.d/91-overlayroot + # Create device nodes expected by some kernels in initramfs # before even executing /init. install -d ${D}/dev @@ -45,14 +59,18 @@ do_install() { } PACKAGES = "${PN}-base \ + initramfs-module-exec \ initramfs-module-mdev \ initramfs-module-udev \ initramfs-module-e2fs \ + initramfs-module-nfsrootfs \ initramfs-module-rootfs \ initramfs-module-debug \ + initramfs-module-lvm \ + initramfs-module-overlayroot \ " -FILES_${PN}-base = "/init /init.d/99-finish /dev" +FILES:${PN}-base = "/init /init.d/99-finish /dev" # 99-finish in base depends on some other module which mounts # the rootfs, like 90-rootfs. To replace that default, use @@ -60,24 +78,40 @@ FILES_${PN}-base = "/init /init.d/99-finish /dev" # initramfs recipe and install something else, or install # something that runs earlier (for example, a 89-my-rootfs) # and mounts the rootfs. Then 90-rootfs will proceed immediately. -RRECOMMENDS_${PN}-base += "initramfs-module-rootfs" +RRECOMMENDS:${PN}-base += "initramfs-module-rootfs" + +SUMMARY:initramfs-module-exec = "initramfs support for easy execution of applications" +RDEPENDS:initramfs-module-exec = "${PN}-base" +FILES:initramfs-module-exec = "/init.d/89-exec" + +SUMMARY:initramfs-module-mdev = "initramfs support for mdev" +RDEPENDS:initramfs-module-mdev = "${PN}-base busybox-mdev" +FILES:initramfs-module-mdev = "/init.d/01-mdev" + +SUMMARY:initramfs-module-udev = "initramfs support for udev" +RDEPENDS:initramfs-module-udev = "${PN}-base udev" +FILES:initramfs-module-udev = "/init.d/01-udev" + +SUMMARY:initramfs-module-e2fs = "initramfs support for ext4/ext3/ext2 filesystems" +RDEPENDS:initramfs-module-e2fs = "${PN}-base" +FILES:initramfs-module-e2fs = "/init.d/10-e2fs" -SUMMARY_initramfs-module-mdev = "initramfs support for mdev" -RDEPENDS_initramfs-module-mdev = "${PN}-base busybox-mdev" -FILES_initramfs-module-mdev = "/init.d/01-mdev" +SUMMARY:initramfs-module-nfsrootfs = "initramfs support for locating and mounting the root partition via nfs" +RDEPENDS:initramfs-module-nfsrootfs = "${PN}-base" +FILES:initramfs-module-nfsrootfs = "/init.d/85-nfsrootfs" -SUMMARY_initramfs-module-udev = "initramfs support for udev" -RDEPENDS_initramfs-module-udev = "${PN}-base udev" -FILES_initramfs-module-udev = "/init.d/01-udev" +SUMMARY:initramfs-module-rootfs = "initramfs support for locating and mounting the root partition" +RDEPENDS:initramfs-module-rootfs = "${PN}-base" +FILES:initramfs-module-rootfs = "/init.d/90-rootfs" -SUMMARY_initramfs-module-e2fs = "initramfs support for ext4/ext3/ext2 filesystems" -RDEPENDS_initramfs-module-e2fs = "${PN}-base" -FILES_initramfs-module-e2fs = "/init.d/10-e2fs" +SUMMARY:initramfs-module-debug = "initramfs dynamic debug support" +RDEPENDS:initramfs-module-debug = "${PN}-base" +FILES:initramfs-module-debug = "/init.d/00-debug" -SUMMARY_initramfs-module-rootfs = "initramfs support for locating and mounting the root partition" -RDEPENDS_initramfs-module-rootfs = "${PN}-base" -FILES_initramfs-module-rootfs = "/init.d/90-rootfs" +SUMMARY:initramfs-module-lvm = "initramfs lvm rootfs support" +RDEPENDS:initramfs-module-lvm = "${PN}-base" +FILES:initramfs-module-lvm = "/init.d/09-lvm" -SUMMARY_initramfs-module-debug = "initramfs dynamic debug support" -RDEPENDS_initramfs-module-debug = "${PN}-base" -FILES_initramfs-module-debug = "/init.d/00-debug" +SUMMARY:initramfs-module-overlayroot = "initramfs support for mounting a RW overlay on top of a RO root filesystem" +RDEPENDS:initramfs-module-overlayroot = "${PN}-base initramfs-module-rootfs" +FILES:initramfs-module-overlayroot = "/init.d/91-overlayroot" diff --git a/meta/recipes-core/initrdscripts/initramfs-live-boot-tiny_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-live-boot-tiny_1.0.bb index 7a9a8ecae2..847dbc0472 100644 --- a/meta/recipes-core/initrdscripts/initramfs-live-boot-tiny_1.0.bb +++ b/meta/recipes-core/initrdscripts/initramfs-live-boot-tiny_1.0.bb @@ -2,10 +2,9 @@ SUMMARY = "Live image init script" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" DEPENDS = "virtual/kernel" -RDEPENDS_${PN} = "busybox-mdev" +RDEPENDS:${PN} = "busybox-mdev" SRC_URI = "file://init-live.sh" -PR = "r12" S = "${WORKDIR}" @@ -15,7 +14,7 @@ do_install() { mknod -m 622 ${D}/dev/console c 5 1 } -FILES_${PN} += " /init /dev " +FILES:${PN} += " /init /dev " # Due to kernel dependency PACKAGE_ARCH = "${MACHINE_ARCH}" diff --git a/meta/recipes-core/initrdscripts/initramfs-live-boot_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-live-boot_1.0.bb index 57b30254a6..b3b991b8fd 100644 --- a/meta/recipes-core/initrdscripts/initramfs-live-boot_1.0.bb +++ b/meta/recipes-core/initrdscripts/initramfs-live-boot_1.0.bb @@ -2,10 +2,9 @@ SUMMARY = "Live image init script" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" DEPENDS = "virtual/kernel" -RDEPENDS_${PN} = "udev udev-extraconf" +RDEPENDS:${PN} = "udev udev-extraconf" SRC_URI = "file://init-live.sh" -PR = "r12" S = "${WORKDIR}" @@ -15,7 +14,7 @@ do_install() { mknod -m 622 ${D}/dev/console c 5 1 } -FILES_${PN} += " /init /dev " +FILES:${PN} += " /init /dev " # Due to kernel dependency PACKAGE_ARCH = "${MACHINE_ARCH}" diff --git a/meta/recipes-core/initrdscripts/initramfs-live-install-efi-testfs_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-live-install-efi-testfs_1.0.bb index c03bd2d765..495eccbeda 100644 --- a/meta/recipes-core/initrdscripts/initramfs-live-install-efi-testfs_1.0.bb +++ b/meta/recipes-core/initrdscripts/initramfs-live-install-efi-testfs_1.0.bb @@ -3,7 +3,7 @@ LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" SRC_URI = "file://init-install-efi-testfs.sh" -RDEPENDS_${PN} = "parted e2fsprogs-mke2fs dosfstools" +RDEPENDS:${PN} = "parted e2fsprogs-mke2fs dosfstools" S = "${WORKDIR}" @@ -12,5 +12,5 @@ do_install() { } INHIBIT_DEFAULT_DEPS = "1" -FILES_${PN} = " /install-efi.sh " +FILES:${PN} = " /install-efi.sh " COMPATIBLE_HOST = "(i.86|x86_64).*-linux" diff --git a/meta/recipes-core/initrdscripts/initramfs-live-install-efi_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-live-install-efi_1.0.bb index 2a7f84ddc8..e10faadfbe 100644 --- a/meta/recipes-core/initrdscripts/initramfs-live-install-efi_1.0.bb +++ b/meta/recipes-core/initrdscripts/initramfs-live-install-efi_1.0.bb @@ -3,9 +3,9 @@ LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" SRC_URI = "file://init-install-efi.sh" -PR = "r1" -RDEPENDS_${PN} = "parted e2fsprogs-mke2fs dosfstools util-linux-blkid" +RDEPENDS:${PN} = "parted e2fsprogs-mke2fs dosfstools util-linux-blkid ${VIRTUAL-RUNTIME_base-utils}" +RRECOMMENDS:${PN} = "${VIRTUAL-RUNTIME_base-utils-syslog}" S = "${WORKDIR}" @@ -19,6 +19,6 @@ do_install() { #inherit allarch INHIBIT_DEFAULT_DEPS = "1" -FILES_${PN} = " /install-efi.sh " +FILES:${PN} = " /install-efi.sh " COMPATIBLE_HOST = "(i.86.*|x86_64.*|aarch64.*)-linux" diff --git a/meta/recipes-core/initrdscripts/initramfs-live-install-testfs_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-live-install-testfs_1.0.bb index 937bfd4d38..d347e323b3 100644 --- a/meta/recipes-core/initrdscripts/initramfs-live-install-testfs_1.0.bb +++ b/meta/recipes-core/initrdscripts/initramfs-live-install-testfs_1.0.bb @@ -3,7 +3,7 @@ LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" SRC_URI = "file://init-install-testfs.sh" -RDEPENDS_${PN} = "grub parted e2fsprogs-mke2fs" +RDEPENDS:${PN} = "grub parted e2fsprogs-mke2fs" S = "${WORKDIR}" @@ -12,5 +12,5 @@ do_install() { } INHIBIT_DEFAULT_DEPS = "1" -FILES_${PN} = " /install.sh " +FILES:${PN} = " /install.sh " COMPATIBLE_HOST = "(i.86|x86_64).*-linux" diff --git a/meta/recipes-core/initrdscripts/initramfs-live-install_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-live-install_1.0.bb index a553a0d8ba..9046d06c02 100644 --- a/meta/recipes-core/initrdscripts/initramfs-live-install_1.0.bb +++ b/meta/recipes-core/initrdscripts/initramfs-live-install_1.0.bb @@ -3,11 +3,11 @@ LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" SRC_URI = "file://init-install.sh" -PR = "r9" S = "${WORKDIR}" -RDEPENDS_${PN} = "grub parted e2fsprogs-mke2fs util-linux-blkid" +RDEPENDS:${PN} = "grub parted e2fsprogs-mke2fs util-linux-blkid ${VIRTUAL-RUNTIME_base-utils}" +RRECOMMENDS:${PN} = "${VIRTUAL-RUNTIME_base-utils-syslog}" do_install() { install -m 0755 ${WORKDIR}/init-install.sh ${D}/install.sh @@ -19,6 +19,6 @@ do_install() { #inherit allarch INHIBIT_DEFAULT_DEPS = "1" -FILES_${PN} = " /install.sh " +FILES:${PN} = " /install.sh " COMPATIBLE_HOST = "(i.86.*|x86_64.*|aarch64.*)-linux" diff --git a/meta/recipes-core/initrdscripts/initramfs-module-install-efi_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-module-install-efi_1.0.bb index 24b53a8498..b7499644f0 100644 --- a/meta/recipes-core/initrdscripts/initramfs-module-install-efi_1.0.bb +++ b/meta/recipes-core/initrdscripts/initramfs-module-install-efi_1.0.bb @@ -1,13 +1,10 @@ SUMMARY = "initramfs-framework module for EFI installation option" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" -RDEPENDS_${PN} = "initramfs-framework-base parted e2fsprogs-mke2fs dosfstools util-linux-blkid" +RDEPENDS:${PN} = "initramfs-framework-base parted e2fsprogs-mke2fs dosfstools util-linux-blkid ${VIRTUAL-RUNTIME_base-utils}" +RRECOMMENDS:${PN} = "${VIRTUAL-RUNTIME_base-utils-syslog}" -PR = "r4" -inherit allarch - -FILESEXTRAPATHS_prepend := "${THISDIR}/files:" SRC_URI = "file://init-install-efi.sh" S = "${WORKDIR}" @@ -17,4 +14,4 @@ do_install() { install -m 0755 ${WORKDIR}/init-install-efi.sh ${D}/init.d/install-efi.sh } -FILES_${PN} = "/init.d/install-efi.sh" +FILES:${PN} = "/init.d/install-efi.sh" diff --git a/meta/recipes-core/initrdscripts/initramfs-module-install_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-module-install_1.0.bb index ce7f165bfe..11db7124af 100644 --- a/meta/recipes-core/initrdscripts/initramfs-module-install_1.0.bb +++ b/meta/recipes-core/initrdscripts/initramfs-module-install_1.0.bb @@ -1,13 +1,15 @@ SUMMARY = "initramfs-framework module for installation option" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" -RDEPENDS_${PN} = "initramfs-framework-base grub parted e2fsprogs-mke2fs util-linux-blkid" +RDEPENDS:${PN} = "initramfs-framework-base grub parted e2fsprogs-mke2fs util-linux-blkid ${VIRTUAL-RUNTIME_base-utils}" +RRECOMMENDS:${PN} = "${VIRTUAL-RUNTIME_base-utils-syslog}" -PR = "r1" +# The same restriction as grub +COMPATIBLE_HOST = '(x86_64.*|i.86.*|arm.*|aarch64.*|loongarch64.*)-(linux.*|freebsd.*)' +COMPATIBLE_HOST:armv7a = 'null' +COMPATIBLE_HOST:armv7ve = 'null' -inherit allarch -FILESEXTRAPATHS_prepend := "${THISDIR}/files:" SRC_URI = "file://init-install.sh" S = "${WORKDIR}" @@ -17,4 +19,4 @@ do_install() { install -m 0755 ${WORKDIR}/init-install.sh ${D}/init.d/install.sh } -FILES_${PN} = "/init.d/install.sh" +FILES:${PN} = "/init.d/install.sh" diff --git a/meta/recipes-core/initrdscripts/initramfs-module-setup-live_1.0.bb b/meta/recipes-core/initrdscripts/initramfs-module-setup-live_1.0.bb index 4d2fe9dd2b..48a779e9aa 100644 --- a/meta/recipes-core/initrdscripts/initramfs-module-setup-live_1.0.bb +++ b/meta/recipes-core/initrdscripts/initramfs-module-setup-live_1.0.bb @@ -1,13 +1,12 @@ SUMMARY = "initramfs-framework module for live booting" LICENSE = "MIT" LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420" -RDEPENDS_${PN} = "initramfs-framework-base udev-extraconf" +RDEPENDS:${PN} = "initramfs-framework-base udev-extraconf" -PR = "r4" inherit allarch -FILESEXTRAPATHS_prepend := "${THISDIR}/initramfs-framework:" +FILESEXTRAPATHS:prepend := "${THISDIR}/initramfs-framework:" SRC_URI = "file://setup-live" S = "${WORKDIR}" @@ -17,4 +16,4 @@ do_install() { install -m 0755 ${WORKDIR}/setup-live ${D}/init.d/80-setup-live } -FILES_${PN} = "/init.d/80-setup-live" +FILES:${PN} = "/init.d/80-setup-live" |