From 6b7fed082874a85659f622efcb0d95e77bb62726 Mon Sep 17 00:00:00 2001 From: David Cassany Date: Thu, 18 Mar 2021 16:48:55 +0100 Subject: [PATCH 1/4] Drop isoscan use and limit dracut hooks usage This commit it two fold: * Drop isoscan use in favor of a self provided script that is not devoted to ISO images and offers some further flexibility. For instance this enables `rd.cos.debugrw` kernel parameter to boot on readwrite mode. Fixes #65 * Drop most dracut hooks in favor of early boot systemd services. This is relevant in case we want or need to recode the layout tools so we are not tied to shell scripts. This also properly adds the rootfs stage into cos-setup. This is relevant for #220 so early boot configurations can be easily applied. Signed-off-by: David Cassany --- packages/cos-setup/02cos-setup-initramfs.conf | 1 + packages/cos-setup/build.yaml | 6 +- .../cos-setup/cos-setup-initramfs.service | 16 ++++ packages/cos-setup/cos-setup-rootfs.service | 14 +++ packages/grub-config/config/bootargs.cfg | 2 +- packages/grub-config/definition.yaml | 2 +- .../cos-config-launcher.sh | 30 ------ .../30cos-immutable-rootfs/cos-generator.sh | 91 +++++++++++++++++-- .../cos-immutable-rootfs.service | 13 +++ .../30cos-immutable-rootfs/cos-loop-img.sh | 42 +++++++++ .../cos-mount-layout.sh | 61 +++---------- .../30cos-immutable-rootfs/cos-wait-oem.sh | 36 -------- .../30cos-immutable-rootfs/module-setup.sh | 17 +++- .../parse-cos-cmdline.sh | 45 +++++++++ .../parse-cos-overlay.sh | 66 -------------- packages/immutable-rootfs/build.yaml | 2 +- packages/immutable-rootfs/definition.yaml | 2 +- packages/installer/reset.sh | 4 +- packages/installer/upgrade.sh | 2 +- 19 files changed, 252 insertions(+), 200 deletions(-) create mode 100644 packages/cos-setup/02cos-setup-initramfs.conf create mode 100644 packages/cos-setup/cos-setup-initramfs.service create mode 100644 packages/cos-setup/cos-setup-rootfs.service delete mode 100644 packages/immutable-rootfs/30cos-immutable-rootfs/cos-config-launcher.sh create mode 100644 packages/immutable-rootfs/30cos-immutable-rootfs/cos-immutable-rootfs.service create mode 100755 packages/immutable-rootfs/30cos-immutable-rootfs/cos-loop-img.sh mode change 100644 => 100755 packages/immutable-rootfs/30cos-immutable-rootfs/cos-mount-layout.sh delete mode 100644 packages/immutable-rootfs/30cos-immutable-rootfs/cos-wait-oem.sh create mode 100755 packages/immutable-rootfs/30cos-immutable-rootfs/parse-cos-cmdline.sh delete mode 100755 packages/immutable-rootfs/30cos-immutable-rootfs/parse-cos-overlay.sh diff --git a/packages/cos-setup/02cos-setup-initramfs.conf b/packages/cos-setup/02cos-setup-initramfs.conf new file mode 100644 index 00000000000..3e47a0ec23b --- /dev/null +++ b/packages/cos-setup/02cos-setup-initramfs.conf @@ -0,0 +1 @@ +install_items=" /lib/systemd/system/cos-setup-initramfs.service /etc/systemd/system/initrd.target.requires/cos-setup-initramfs.service " diff --git a/packages/cos-setup/build.yaml b/packages/cos-setup/build.yaml index 0408298cff4..0294463c572 100644 --- a/packages/cos-setup/build.yaml +++ b/packages/cos-setup/build.yaml @@ -4,11 +4,15 @@ requires: version: ">=0" steps: - mkdir -p /lib/systemd/system +- mkdir -p /etc/dracut.conf.d +- cp 02cos-setup-initramfs.conf /etc/dracut.conf.d - cp -rfv *.service /lib/systemd/system - cp -rfv *.timer /lib/systemd/system - cp -rfv cos-setup /usr/bin/ - chmod +x /usr/bin/cos-setup +- systemctl enable cos-setup-rootfs.service +- systemctl enable cos-setup-initramfs.service - systemctl enable cos-setup-reconcile.timer - systemctl enable cos-setup-fs.service - systemctl enable cos-setup-boot.service -- systemctl enable cos-setup-network.service \ No newline at end of file +- systemctl enable cos-setup-network.service diff --git a/packages/cos-setup/cos-setup-initramfs.service b/packages/cos-setup/cos-setup-initramfs.service new file mode 100644 index 00000000000..7e6e5798427 --- /dev/null +++ b/packages/cos-setup/cos-setup-initramfs.service @@ -0,0 +1,16 @@ +[Unit] +Description=cOS system initramfs setup before swith root +DefaultDependencies=no +After=initrd-fs.target +Requires=initrd-fs.target +Before=initrd.target + +[Service] +RootDirectory=/sysroot +MountAPIVFS=true +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/bin/cos-setup initramfs + +[Install] +RequiredBy=initrd.target diff --git a/packages/cos-setup/cos-setup-rootfs.service b/packages/cos-setup/cos-setup-rootfs.service new file mode 100644 index 00000000000..0d7044a20b0 --- /dev/null +++ b/packages/cos-setup/cos-setup-rootfs.service @@ -0,0 +1,14 @@ +[Unit] +Description=cOS system early rootfs setup +DefaultDependencies=no +After=initrd-root-fs.target +Requires=initrd-root-fs.target +Conflicts=initrd-switch-root.target + +[Service] +Type=oneshot +ExecStartPre=/usr/bin/ln -s /sysroot/system /system +ExecStart=/usr/bin/cos-setup rootfs + +[Install] +RequiredBy=initrd-fs.target diff --git a/packages/grub-config/config/bootargs.cfg b/packages/grub-config/config/bootargs.cfg index 374dfe0c1d6..a79dba77849 100644 --- a/packages/grub-config/config/bootargs.cfg +++ b/packages/grub-config/config/bootargs.cfg @@ -2,7 +2,7 @@ set kernel=/boot/vmlinuz if [ -n "$recoverylabel" ]; then set kernelcmd="console=tty1 root=live:LABEL=$recoverylabel rd.live.dir=/ rd.live.squashimg=$img panic=5" else - set kernelcmd="console=tty1 root=LABEL=$label iso-scan/filename=$img panic=5 security=selinux selinux=1" + set kernelcmd="console=tty1 root=LABEL=$label cos-img/filename=$img panic=5 security=selinux selinux=1" fi set initramfs=/boot/initrd diff --git a/packages/grub-config/definition.yaml b/packages/grub-config/definition.yaml index 74d306f5db7..6e3d2110705 100644 --- a/packages/grub-config/definition.yaml +++ b/packages/grub-config/definition.yaml @@ -1,3 +1,3 @@ name: "grub-config" category: "system" -version: 0.0.6+2 +version: "0.0.7" diff --git a/packages/immutable-rootfs/30cos-immutable-rootfs/cos-config-launcher.sh b/packages/immutable-rootfs/30cos-immutable-rootfs/cos-config-launcher.sh deleted file mode 100644 index 5056df896f9..00000000000 --- a/packages/immutable-rootfs/30cos-immutable-rootfs/cos-config-launcher.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh - -#====================================== -# Functions -#-------------------------------------- -function chroot_mounts { - local mountpoint=$1 - mount -t proc /proc "${mountpoint}/proc/" - mount -t sysfs /sys "${mountpoint}/sys/" - mount --bind /dev "${mountpoint}/dev/" -} - -function chroot_umounts { - local mountpoint=$1 - umount "${mountpoint}/proc/" - umount "${mountpoint}/sys/" - umount "${mountpoint}/dev/" -} - -#====================================== -# Trigger pre-pivot config stage -#-------------------------------------- - -if ismounted /sysroot; then - chroot_mounts /sysroot - chroot /sysroot /usr/bin/cos-setup initramfs - chroot_umounts /sysroot -fi diff --git a/packages/immutable-rootfs/30cos-immutable-rootfs/cos-generator.sh b/packages/immutable-rootfs/30cos-immutable-rootfs/cos-generator.sh index 53946da36b5..5fca31a6383 100755 --- a/packages/immutable-rootfs/30cos-immutable-rootfs/cos-generator.sh +++ b/packages/immutable-rootfs/30cos-immutable-rootfs/cos-generator.sh @@ -2,13 +2,24 @@ type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh +cos_unit="cos-immutable-rootfs.service" +cos_layout="/run/cos/cos-layout.env" + +# Disable the service unless we override it +mkdir -p "/run/systemd/system/${cos_unit}.d" + [ -z "${root}" ] && root=$(getarg root=) -root_perm="ro" -if getargbool 0 rd.cos.debug.rw; then - root_perm="rw" +cos_root_perm="ro" +if getargbool 0 rd.cos.debugrw; then + cos_root_perm="rw" fi +oem_timeout=$(getarg rd.cos.oemtimeout=) +[ -z "${oem_timeout}" ] && oem_timeout="10" +cos_overlay=$(getarg rd.cos.overlay=) +[ -z "${cos_overlay}" ] && cos_overlay="tmpfs:20%" + case "${root}" in LABEL=*) \ root="${root//\//\\x2f}" @@ -27,8 +38,7 @@ GENERATOR_DIR="$2" [ -z "$GENERATOR_DIR" ] && exit 1 [ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR" -dev="${root//-/\\x2d}" -dev="${_dev//\//-}" +dev=$(dev_unit_name "${root}") { echo "[Unit]" echo "Before=initrd-root-fs.target" @@ -36,7 +46,7 @@ dev="${_dev//\//-}" echo "[Mount]" echo "Where=/sysroot" echo "What=${root}" - echo "Options=${root_perm},suid,dev,exec,auto,nouser,async" + echo "Options=${cos_root_perm},suid,dev,exec,auto,nouser,async" } > "$GENERATOR_DIR"/sysroot.mount if [ ! -e "$GENERATOR_DIR/initrd-root-fs.target.requires/sysroot.mount" ]; then @@ -48,6 +58,71 @@ fi mkdir -p "$GENERATOR_DIR/$dev.device.d" { echo "[Unit]" - echo "JobTimeoutSec=3000" - echo "JobRunningTimeoutSec=3000" + echo "JobTimeoutSec=300" + echo "JobRunningTimeoutSec=300" +} > "$GENERATOR_DIR/$dev.device.d/timeout.conf" + +dev=$(dev_unit_name /dev/disk/by-label/COS_OEM) +{ + echo "[Unit]" + echo "DefaultDependencies=no" + echo "Before=cos-setup-rootfs.service" + echo "Conflicts=initrd-switch-root.target" + echo "[Mount]" + echo "Where=/oem" + echo "What=/dev/disk/by-label/COS_OEM" + echo "Options=rw,suid,dev,exec,noauto,nouser,async" +} > "$GENERATOR_DIR"/oem.mount + +if [ ! -e "$GENERATOR_DIR/cos-setup-rootfs.service.wants/oem.mount" ]; then + mkdir -p "$GENERATOR_DIR"/cos-setup-rootfs.service.wants + ln -s "$GENERATOR_DIR"/oem.mount \ + "$GENERATOR_DIR"/cos-setup-rootfs.service.wants/oem.mount +fi + +mkdir -p "$GENERATOR_DIR/$dev.device.d" +{ + echo "[Unit]" + echo "Before=initrd-root-fs.target" + echo "JobRunningTimeoutSec=${oem_timeout}" } > "$GENERATOR_DIR/$dev.device.d/timeout.conf" + +if [ ! -e "$GENERATOR_DIR/initrd-root-fs.target.wants/$dev.device" ]; then + mkdir -p "$GENERATOR_DIR"/initrd-root-fs.target.wants + ln -s "$GENERATOR_DIR"/"$dev".device \ + "$GENERATOR_DIR"/initrd-root-fs.target.wants/"$dev".device +fi + +case "${cos_overlay}" in + UUID=*) \ + cos_overlay="block:/dev/disk/by-uuid/${cos_overlay#UUID=}" + ;; + LABEL=*) \ + cos_overlay="block:/dev/disk/by-label/${cos_overlay#LABEL=}" + ;; +esac + +cos_mounts=() +for mount in $(getargs rd.cos.mount=); do + case "${mount}" in + UUID=*) \ + mount="/dev/disk/by-uuid/${mount#UUID=}" + ;; + LABEL=*) \ + mount="/dev/disk/by-label/${mount#LABEL=}" + ;; + esac + cos_mounts+=("${mount}") +done + +mkdir -p "${cos_layout%/*}" +#> "${cos_layout}" + +{ + echo "[Service]" + echo "Environment=\"cos_mounts=${cos_mounts[@]}\"" + echo "Environment=\"cos_overlay=${cos_overlay}\"" + echo "Environment=\"cos_root_perm=${cos_root_perm}\"" + echo "Environment=\"root=${root}\"" + echo "EnvironmentFile=${cos_layout}" +} > "/run/systemd/system/${cos_unit}.d/override.conf" diff --git a/packages/immutable-rootfs/30cos-immutable-rootfs/cos-immutable-rootfs.service b/packages/immutable-rootfs/30cos-immutable-rootfs/cos-immutable-rootfs.service new file mode 100644 index 00000000000..4125e753ebd --- /dev/null +++ b/packages/immutable-rootfs/30cos-immutable-rootfs/cos-immutable-rootfs.service @@ -0,0 +1,13 @@ +[Unit] +Description=cOS system immutable rootfs mounts +DefaultDependencies=no +After=initrd-root-fs.target cos-setup-rootfs.service +Requires=initrd-root-fs.target +Before=initrd-fs.target +Conflicts=initrd-switch-root.target + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStartPre=-/usr/bin/systemctl stop oem.mount +ExecStart=/sbin/cos-mount-layout diff --git a/packages/immutable-rootfs/30cos-immutable-rootfs/cos-loop-img.sh b/packages/immutable-rootfs/30cos-immutable-rootfs/cos-loop-img.sh new file mode 100755 index 00000000000..1bf8f4f441f --- /dev/null +++ b/packages/immutable-rootfs/30cos-immutable-rootfs/cos-loop-img.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +function doLoopMount { + local label + + for label in "${dev_labels[@]}"; do + [ -e "/tmp/cosloop-${label}" ] && continue + [ -e "/dev/disk/by-label/${label}" ] || continue + > "/tmp/cosloop-${label}" + mount -t auto -o "${cos_root_perm}" "/dev/disk/by-label/${label}" "${cos_state}" || continue + if [ -f "${cos_state}/${cos_img}" ]; then + losetup -f "${cos_state}/${cos_img}" + exit 0 + else + umount "${cos_state}" + fi + done +} + +type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh + +PATH=/usr/sbin:/usr/bin:/sbin:/bin + +declare cos_img=$1 +declare cos_root_perm="ro" +declare cos_state="/run/initramfs/cos-state" +declare dev_labels=("COS_STATE" "COS_RECOVERY") + +[ -z "${cos_img}" ] && exit 1 + +if getargbool 0 rd.cos.debugrw; then + cos_root_perm="rw" +fi + +ismounted "${cos_state}" && exit 0 + +mkdir -p "${cos_state}" + +doLoopMount + +rm -r "${cos_state}" +exit 1 diff --git a/packages/immutable-rootfs/30cos-immutable-rootfs/cos-mount-layout.sh b/packages/immutable-rootfs/30cos-immutable-rootfs/cos-mount-layout.sh old mode 100644 new mode 100755 index 2bb65a19f93..48cbe806fd8 --- a/packages/immutable-rootfs/30cos-immutable-rootfs/cos-mount-layout.sh +++ b/packages/immutable-rootfs/30cos-immutable-rootfs/cos-mount-layout.sh @@ -1,5 +1,5 @@ #!/bin/bash -# cos_root_perm, cos_mounts and cos_overlay variables are already processed +# cos_root_perm, cos_mounts and cos_overlay variables already processsed #====================================== # Functions @@ -57,38 +57,9 @@ function parseCOSMount { echo "${mount}" } -function setupLayout { - local o_mnt=0 - local so_mnt=0 - - if [ -e "/dev/disk/by-label/${oem_label}" ]; then - info "Mounting ${oem_mount}" - mkdir -p "${oem_mount}" - mount -t auto "/dev/disk/by-label/${oem_label}" "${oem_mount}" - o_mnt=1 - fi - - if [ -d "/sysroot/system/oem" ]; then - ln -s /sysroot/system /system - fi - - mkdir -p "${cos_layout%/*}" - cos-setup rootfs - - [ "${o_mnt}" = 1 ] && umount "${oem_mount}" -} - function readCOSLayoutConfig { local mounts=() - local MERGE="true" - local VOLUMES - local OVERLAY - local DEBUG_RW - - [ ! -f "${cos_layout}" ] && return - - info "Loading ${cos_layout}" - . "${cos_layout}" + : "${MERGE:=true}" if [ "${DEBUG_RW}" = "true" ]; then cos_root_perm="rw" @@ -101,8 +72,8 @@ function readCOSLayoutConfig { fi if [ "${MERGE}" = "true" ]; then - if [ ${#mounts[@]} -gt 0 ]; then - for mount in "${cos_mounts[@]}"; do + if [ -n "${cos_mounts}" ]; then + for mount in ${cos_mounts}; do if ! hasMountpoint "${mount#*:}" "${mounts[@]}"; then mounts+=("${mount}") fi @@ -169,10 +140,10 @@ function mountOverlay { function mountPersistent { local mount=$1 - if [ -e "${mount#*:}" ]; then + if [ -e "${mount#*:}" ] && ! findmnt -rno SOURCE "${mount#*:}" > /dev/null; then mount -t auto "${mount#*:}" "/sysroot${mount%%:*}" else - warn "${mount#*:} not mounted, device not found" + echo "Warning: ${mount#*:} already mounted or device not found" >&2 fi echo "${mount#*:} ${mount%%:*} auto defaults 0 0\n" } @@ -181,36 +152,32 @@ function mountPersistent { # Mount the rootfs layout #-------------------------------------- -type info >/dev/null 2>&1 || . /lib/dracut-lib.sh PATH=/usr/sbin:/usr/bin:/sbin:/bin declare root=${root} -declare cos_mounts=("${cos_mounts[@]}") +declare cos_mounts=${cos_mounts} declare cos_overlay=${cos_overlay} -declare oem_label="COS_OEM" -declare oem_mount="/oem" +declare cos_root_perm=${cos_root_perm} +declare state_label="COS_STATE" declare overlay_base="/run/overlay" declare rw_paths=("/etc" "/root" "/home" "/opt" "/srv" "/usr/local" "/var") declare etc_conf="/sysroot/etc/systemd/system/etc.mount.d" declare cos_layout="/run/cos/cos-layout.env" declare fstab -[ ! "${root%%:*}" = "cos" ] && return 0 - -setupLayout - readCOSLayoutConfig -[ -z "${cos_overlay}" ] && return 0 +[ -z "${root}" ] && exit 0 +[ -z "${cos_overlay}" ] && exit 0 -fstab="${root#cos:} / auto ${cos_root_perm},suid,dev,exec,auto,nouser,async 0 0\n" +fstab="/dev/disk/by-label/${state_label} /run/initramfs/cos-state auto ${cos_root_perm} 0 0\n" +fstab+="${root} / auto ${cos_root_perm} 0 0\n" fstab+=$(mountOverlayBase) mountpoints=($(getCOSMounts)) for mount in "${mountpoints[@]}"; do - info "Mounting ${mount%%:*}" if [ "${mount#*:}" = "overlay" ]; then fstab+=$(mountOverlay "${mount%%:*}") else @@ -228,4 +195,4 @@ if [ ! -f "${etc_conf}/override.conf" ]; then } > "${etc_conf}/override.conf" fi -return 0 +exit 0 diff --git a/packages/immutable-rootfs/30cos-immutable-rootfs/cos-wait-oem.sh b/packages/immutable-rootfs/30cos-immutable-rootfs/cos-wait-oem.sh deleted file mode 100644 index fd61d94ea51..00000000000 --- a/packages/immutable-rootfs/30cos-immutable-rootfs/cos-wait-oem.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -#====================================== -# Functions -#-------------------------------------- - -function waitForOEM { - local timeout="$1" - local timeout_file="/tmp/cos-oem-timestamp" - local current_time - - current_time="$(cat /proc/uptime)" - current_time="${current_time%%.*}" - - if [ ! -f "${timeout_file}" ]; then - echo "$((current_time + $timeout))" > "${timeout_file}" - fi - - if [ ! -e "/dev/disk/by-label/${oem_label}" ] && [ "${current_time}" -lt "$(cat ${timeout_file})" ]; then - info "Waiting for COS_OEM device" - return 1 - fi -} - -type info >/dev/null 2>&1 || . /lib/dracut-lib.sh -PATH=/usr/sbin:/usr/bin:/sbin:/bin - -declare root=${root} -declare cos_oem_timeout=${cos_oem_timeout} -declare oem_label="COS_OEM" - -[ ! "${root%%:*}" = "cos" ] && return 0 - -waitForOEM "${cos_oem_timeout}" || return 1 - -return 0 diff --git a/packages/immutable-rootfs/30cos-immutable-rootfs/module-setup.sh b/packages/immutable-rootfs/30cos-immutable-rootfs/module-setup.sh index 6a0ffa91287..04df60a5aa9 100755 --- a/packages/immutable-rootfs/30cos-immutable-rootfs/module-setup.sh +++ b/packages/immutable-rootfs/30cos-immutable-rootfs/module-setup.sh @@ -20,13 +20,20 @@ installkernel() { install() { declare moddir=${moddir} declare systemdutildir=${systemdutildir} + declare systemdsystemunitdir=${systemdsystemunitdir} + declare initdir="${initdir}" + inst_multiple \ - mount mountpoint yip cos-setup sort rmdir - inst_hook cmdline 30 "${moddir}/parse-cos-overlay.sh" - inst_hook initqueue/finished 30 "${moddir}/cos-wait-oem.sh" - inst_hook pre-pivot 10 "${moddir}/cos-mount-layout.sh" - inst_hook pre-pivot 20 "${moddir}/cos-config-launcher.sh" + mount mountpoint yip cos-setup sort findmnt rmdir + inst_hook cmdline 30 "${moddir}/parse-cos-cmdline.sh" inst_script "${moddir}/cos-generator.sh" \ "${systemdutildir}/system-generators/dracut-cos-generator" + inst_script "${moddir}/cos-mount-layout.sh" "/sbin/cos-mount-layout" + inst_script "${moddir}/cos-loop-img.sh" "/sbin/cos-loop-img" + inst_simple "${moddir}/cos-immutable-rootfs.service" \ + "${systemdsystemunitdir}/cos-immutable-rootfs.service" + mkdir -p "${initdir}/${systemdsystemunitdir}/initrd-fs.target.requires" + ln_r "../cos-immutable-rootfs.service" \ + "${systemdsystemunitdir}/initrd-fs.target.requires/cos-immutable-rootfs.service" dracut_need_initqueue } diff --git a/packages/immutable-rootfs/30cos-immutable-rootfs/parse-cos-cmdline.sh b/packages/immutable-rootfs/30cos-immutable-rootfs/parse-cos-cmdline.sh new file mode 100755 index 00000000000..e0190303cf5 --- /dev/null +++ b/packages/immutable-rootfs/30cos-immutable-rootfs/parse-cos-cmdline.sh @@ -0,0 +1,45 @@ +#!/bin/bash +# immutable root is specified with +# rd.cos.mount=LABEL=: +# rd.cos.mount=UUID=: +# rd.cos.overlay=tmpfs: +# rd.cos.overlay=LABEL= +# rd.cos.overlay=UUID= +# rd.cos.oemtimeout= +# rd.cos.debugrw +# cos-img/filename=/cOS/active.img + +type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh + +cos_img=$(getarg cos-img/filename=) +[ -z "${cos_img}" ] && return 0 +cos_overlay=$(getarg rd.cos.overlay=) +[ -z "${cos_overlay}" ] && cos_overlay="tmpfs:20%" +[ -z "${root}" ] && root=$(getarg root=) + +cos_root_perm="ro" +if getargbool 0 rd.cos.debugrw; then + cos_root_perm="rw" +fi + +case "${root}" in + LABEL=*) \ + root="${root//\//\\x2f}" + root="/dev/disk/by-label/${root#LABEL=}" + rootok=1 ;; + UUID=*) \ + root="/dev/disk/by-uuid/${root#UUID=}" + rootok=1 ;; + /dev/*) \ + root="${root}" + rootok=1 ;; +esac + +[ "${rootok}" != "1" ] && return 0 + +info "root device set to root=${root}" + +wait_for_dev -n "${root}" +/sbin/initqueue --settled --unique /sbin/cos-loop-img "${cos_img}" + +return 0 diff --git a/packages/immutable-rootfs/30cos-immutable-rootfs/parse-cos-overlay.sh b/packages/immutable-rootfs/30cos-immutable-rootfs/parse-cos-overlay.sh deleted file mode 100755 index 11f0c6c0e8c..00000000000 --- a/packages/immutable-rootfs/30cos-immutable-rootfs/parse-cos-overlay.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/bash -# immutable root is specified with -# rd.cos.mount=LABEL=: -# rd.cos.mount=UUID=: -# rd.cos.overlay=tmpfs: -# rd.cos.overlay=LABEL= -# rd.cos.overlay=UUID= -# rd.cos.oemtimeout=4 -# rd.cos.debugrw - -type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh - -[ -z "${cos_overlay}" ] && cos_overlay=$(getarg rd.cos.overlay=) -[ -z "${root}" ] && root=$(getarg root=) -cos_oem_timeout=$(getarg rd.cos.oemtimeout=) -[ -z "$cos_oem_timeout" ] && cos_oem_timeout=4 - -cos_root_perm="ro" -if getargbool 0 rd.cos.debugrw; then - cos_root_perm="rw" -fi - -case "${root}" in - LABEL=*) \ - root="${root//\//\\x2f}" - root="cos:/dev/disk/by-label/${root#LABEL=}" - rootok=1 ;; - UUID=*) \ - root="cos:/dev/disk/by-uuid/${root#UUID=}" - rootok=1 ;; - /dev/*) \ - root="cos:${root}" - rootok=1 ;; -esac - -[ "${rootok}" != "1" ] && return 0 - -info "root device set to ${root}" - -wait_for_dev -n "${root#cos:}" - -case "${cos_overlay}" in - UUID=*) \ - cos_overlay="block:/dev/disk/by-uuid/${cos_overlay#UUID=}" - ;; - LABEL=*) \ - cos_overlay="block:/dev/disk/by-label/${cos_overlay#LABEL=}" - ;; -esac - -info "overlay device set to ${cos_overlay}" - -cos_mounts=() -for mount in $(getargs rd.cos.mount=); do - case "${mount}" in - UUID=*) \ - mount="/dev/disk/by-uuid/${mount#UUID=}" - ;; - LABEL=*) \ - mount="/dev/disk/by-label/${mount#LABEL=}" - ;; - esac - cos_mounts+=("${mount}") -done - -export cos_mounts cos_overlay cos_root_perm root cos_oem_timeout diff --git a/packages/immutable-rootfs/build.yaml b/packages/immutable-rootfs/build.yaml index 9be5709c9fb..e31f8226492 100644 --- a/packages/immutable-rootfs/build.yaml +++ b/packages/immutable-rootfs/build.yaml @@ -28,6 +28,6 @@ steps: - | kernel=$(ls /lib/modules | head -n1) && \ dracut --verbose --no-hostonly --omit multipath --no-hostonly-cmdline --xz \ - -f "/boot/initrd-${kernel}" --add " dmsquash-live cos-immutable-rootfs " \ + -f "/boot/initrd-${kernel}" --add " dmsquash-live cos-immutable-rootfs network " \ "${kernel}" && \ ln -sf "initrd-${kernel}" /boot/initrd diff --git a/packages/immutable-rootfs/definition.yaml b/packages/immutable-rootfs/definition.yaml index c77911db07d..529362af7ad 100644 --- a/packages/immutable-rootfs/definition.yaml +++ b/packages/immutable-rootfs/definition.yaml @@ -1,3 +1,3 @@ name: "immutable-rootfs" category: "system" -version: 0.0.19+16 +version: "0.0.24" diff --git a/packages/installer/reset.sh b/packages/installer/reset.sh index 6f18f0afddc..1e47325a441 100644 --- a/packages/installer/reset.sh +++ b/packages/installer/reset.sh @@ -43,7 +43,7 @@ do_mount() if is_booting_from_squashfs; then RECOVERYDIR=/run/initramfs/live else - RECOVERYDIR=/run/initramfs/isoscan + RECOVERYDIR=/run/initramfs/cos-state fi #mount -o remount,rw ${STATE} ${STATEDIR} @@ -165,4 +165,4 @@ fi copy_active -install_grub \ No newline at end of file +install_grub diff --git a/packages/installer/upgrade.sh b/packages/installer/upgrade.sh index aee24a32e01..ea240f15355 100644 --- a/packages/installer/upgrade.sh +++ b/packages/installer/upgrade.sh @@ -110,7 +110,7 @@ mount_state() { } mount_image() { - STATEDIR=/run/initramfs/isoscan + STATEDIR=/run/initramfs/cos-state TARGET=/tmp/upgrade mkdir -p $TARGET || true From 0134689f6d2bc41878a0cf5fce4560f3c027e77d Mon Sep 17 00:00:00 2001 From: David Cassany Date: Mon, 21 Jun 2021 17:09:42 +0200 Subject: [PATCH 2/4] Move out initrd creation from immutable-rootfs package Signed-off-by: David Cassany --- packages/cos-setup/02-cos-setup-initramfs.conf | 3 +++ packages/cos-setup/02cos-setup-initramfs.conf | 1 - packages/cos-setup/build.yaml | 2 +- packages/cos-setup/definition.yaml | 2 +- packages/cos/50-cos-initrd.conf | 5 +++++ packages/cos/build.yaml | 7 +++++++ packages/cos/collection.yaml | 5 ++--- packages/immutable-rootfs/02-cos-immutable-rootfs.conf | 1 + packages/immutable-rootfs/build.yaml | 7 +------ packages/immutable-rootfs/definition.yaml | 2 +- packages/recovery-img/definition.yaml | 2 +- packages/recovery-img/squash/definition.yaml | 2 +- 12 files changed, 24 insertions(+), 15 deletions(-) create mode 100644 packages/cos-setup/02-cos-setup-initramfs.conf delete mode 100644 packages/cos-setup/02cos-setup-initramfs.conf create mode 100644 packages/cos/50-cos-initrd.conf create mode 100644 packages/immutable-rootfs/02-cos-immutable-rootfs.conf diff --git a/packages/cos-setup/02-cos-setup-initramfs.conf b/packages/cos-setup/02-cos-setup-initramfs.conf new file mode 100644 index 00000000000..4c2c1015844 --- /dev/null +++ b/packages/cos-setup/02-cos-setup-initramfs.conf @@ -0,0 +1,3 @@ +install_items+=" /lib/systemd/system/cos-setup-initramfs.service /etc/systemd/system/initrd.target.requires/cos-setup-initramfs.service " +install_items+=" /lib/systemd/system/cos-setup-rootfs.service /etc/systemd/system/initrd-fs.target.requires/cos-setup-rootfs.service " +add_dracutmodules+=" network " diff --git a/packages/cos-setup/02cos-setup-initramfs.conf b/packages/cos-setup/02cos-setup-initramfs.conf deleted file mode 100644 index 3e47a0ec23b..00000000000 --- a/packages/cos-setup/02cos-setup-initramfs.conf +++ /dev/null @@ -1 +0,0 @@ -install_items=" /lib/systemd/system/cos-setup-initramfs.service /etc/systemd/system/initrd.target.requires/cos-setup-initramfs.service " diff --git a/packages/cos-setup/build.yaml b/packages/cos-setup/build.yaml index 0294463c572..c1ec2fd4ccb 100644 --- a/packages/cos-setup/build.yaml +++ b/packages/cos-setup/build.yaml @@ -5,7 +5,7 @@ requires: steps: - mkdir -p /lib/systemd/system - mkdir -p /etc/dracut.conf.d -- cp 02cos-setup-initramfs.conf /etc/dracut.conf.d +- cp 02-cos-setup-initramfs.conf /etc/dracut.conf.d - cp -rfv *.service /lib/systemd/system - cp -rfv *.timer /lib/systemd/system - cp -rfv cos-setup /usr/bin/ diff --git a/packages/cos-setup/definition.yaml b/packages/cos-setup/definition.yaml index ac12032a9d9..39af94b9b45 100644 --- a/packages/cos-setup/definition.yaml +++ b/packages/cos-setup/definition.yaml @@ -1,6 +1,6 @@ name: cos-setup category: system -version: 0.2.11+3 +version: "0.2.16" requires: - name: "yip" category: "toolchain" diff --git a/packages/cos/50-cos-initrd.conf b/packages/cos/50-cos-initrd.conf new file mode 100644 index 00000000000..dd5bfdc7d6d --- /dev/null +++ b/packages/cos/50-cos-initrd.conf @@ -0,0 +1,5 @@ +hostonly_cmdline="no" +hostonly="no" +compress="xz" +omit_dracutmodules+=" multipath " +add_dracutmodules+=" dmsquash-live " diff --git a/packages/cos/build.yaml b/packages/cos/build.yaml index d57ab41d0f0..ff90b632e41 100644 --- a/packages/cos/build.yaml +++ b/packages/cos/build.yaml @@ -64,6 +64,13 @@ steps: - sed -i 's/:PRETTY_NAME:/{{.Values.brand_name}} v{{.Values.version}}/g' setup.yaml - yip setup.yaml +# Create initrd +- | + cp 50-cos-initrd.conf /etc/dracut.conf.d && \ + kernel=$(ls /lib/modules | head -n1) && \ + dracut -f "/boot/initrd-${kernel}" "${kernel}" && \ + ln -sf "initrd-${kernel}" /boot/initrd + # See https://luet-lab.github.io/docs/docs/concepts/packages/specfile/#package-by-container-content unpack: true diff --git a/packages/cos/collection.yaml b/packages/cos/collection.yaml index 9fc3e94568d..74138109cca 100644 --- a/packages/cos/collection.yaml +++ b/packages/cos/collection.yaml @@ -1,15 +1,14 @@ packages: - name: "cos" category: "system" - version: 0.5.3+3 + version: 0.5.3+5 brand_name: "cOS" labels: autobump.revdeps: "true" autobump.revbump_related: "recovery/cos-img recovery/cos-squash" - name: "cos" category: "recovery" - version: 0.5.3+3 - version: 0.5.3+3 + version: 0.5.3+5 brand_name: "cOS recovery" labels: autobump.revdeps: "true" diff --git a/packages/immutable-rootfs/02-cos-immutable-rootfs.conf b/packages/immutable-rootfs/02-cos-immutable-rootfs.conf new file mode 100644 index 00000000000..67271e31a42 --- /dev/null +++ b/packages/immutable-rootfs/02-cos-immutable-rootfs.conf @@ -0,0 +1 @@ +add_dracutmodules+=" cos-immutable-rootfs " diff --git a/packages/immutable-rootfs/build.yaml b/packages/immutable-rootfs/build.yaml index e31f8226492..04cd3d7469b 100644 --- a/packages/immutable-rootfs/build.yaml +++ b/packages/immutable-rootfs/build.yaml @@ -25,9 +25,4 @@ steps: {{end}} {{end}} - cp -r 30cos-immutable-rootfs /usr/lib/dracut/modules.d -- | - kernel=$(ls /lib/modules | head -n1) && \ - dracut --verbose --no-hostonly --omit multipath --no-hostonly-cmdline --xz \ - -f "/boot/initrd-${kernel}" --add " dmsquash-live cos-immutable-rootfs network " \ - "${kernel}" && \ - ln -sf "initrd-${kernel}" /boot/initrd +- cp 02-cos-immutable-rootfs.conf /etc/dracut.conf.d diff --git a/packages/immutable-rootfs/definition.yaml b/packages/immutable-rootfs/definition.yaml index 529362af7ad..434d0fcb677 100644 --- a/packages/immutable-rootfs/definition.yaml +++ b/packages/immutable-rootfs/definition.yaml @@ -1,3 +1,3 @@ name: "immutable-rootfs" category: "system" -version: "0.0.24" +version: "0.0.30" diff --git a/packages/recovery-img/definition.yaml b/packages/recovery-img/definition.yaml index 98c850b9176..49d8be6c74e 100644 --- a/packages/recovery-img/definition.yaml +++ b/packages/recovery-img/definition.yaml @@ -1,4 +1,4 @@ name: "cos-img" category: "recovery" -version: 0.5.3+3 +version: 0.5.3+5 brand_name: "cOS" diff --git a/packages/recovery-img/squash/definition.yaml b/packages/recovery-img/squash/definition.yaml index 1507fb3b283..9c71e6e33e5 100644 --- a/packages/recovery-img/squash/definition.yaml +++ b/packages/recovery-img/squash/definition.yaml @@ -1,3 +1,3 @@ name: "cos-squash" category: "recovery" -version: "0.5.3+1" +version: "0.5.3+5" From a8b7451e0669fedd87d21d5238ebeb5797681005 Mon Sep 17 00:00:00 2001 From: David Cassany Date: Tue, 22 Jun 2021 00:29:14 +0200 Subject: [PATCH 3/4] Fix fallback test and allow oem mount on squashfs boots Signed-off-by: David Cassany --- .../30cos-immutable-rootfs/cos-generator.sh | 70 +++++++++---------- packages/immutable-rootfs/definition.yaml | 2 +- tests/fallback/fallback_test.go | 10 +-- 3 files changed, 41 insertions(+), 41 deletions(-) diff --git a/packages/immutable-rootfs/30cos-immutable-rootfs/cos-generator.sh b/packages/immutable-rootfs/30cos-immutable-rootfs/cos-generator.sh index 5fca31a6383..a3b7cf34d11 100755 --- a/packages/immutable-rootfs/30cos-immutable-rootfs/cos-generator.sh +++ b/packages/immutable-rootfs/30cos-immutable-rootfs/cos-generator.sh @@ -20,6 +20,41 @@ oem_timeout=$(getarg rd.cos.oemtimeout=) cos_overlay=$(getarg rd.cos.overlay=) [ -z "${cos_overlay}" ] && cos_overlay="tmpfs:20%" +GENERATOR_DIR="$2" +[ -z "$GENERATOR_DIR" ] && exit 1 +[ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR" + +dev=$(dev_unit_name /dev/disk/by-label/COS_OEM) +{ + echo "[Unit]" + echo "DefaultDependencies=no" + echo "Before=cos-setup-rootfs.service" + echo "Conflicts=initrd-switch-root.target" + echo "[Mount]" + echo "Where=/oem" + echo "What=/dev/disk/by-label/COS_OEM" + echo "Options=rw,suid,dev,exec,noauto,nouser,async" +} > "$GENERATOR_DIR"/oem.mount + +if [ ! -e "$GENERATOR_DIR/cos-setup-rootfs.service.wants/oem.mount" ]; then + mkdir -p "$GENERATOR_DIR"/cos-setup-rootfs.service.wants + ln -s "$GENERATOR_DIR"/oem.mount \ + "$GENERATOR_DIR"/cos-setup-rootfs.service.wants/oem.mount +fi + +mkdir -p "$GENERATOR_DIR/$dev.device.d" +{ + echo "[Unit]" + echo "Before=initrd-root-fs.target" + echo "JobRunningTimeoutSec=${oem_timeout}" +} > "$GENERATOR_DIR/$dev.device.d/timeout.conf" + +if [ ! -e "$GENERATOR_DIR/initrd-root-fs.target.wants/$dev.device" ]; then + mkdir -p "$GENERATOR_DIR"/initrd-root-fs.target.wants + ln -s "$GENERATOR_DIR"/"$dev".device \ + "$GENERATOR_DIR"/initrd-root-fs.target.wants/"$dev".device +fi + case "${root}" in LABEL=*) \ root="${root//\//\\x2f}" @@ -34,10 +69,6 @@ esac [ "${rootok}" != "1" ] && exit 0 -GENERATOR_DIR="$2" -[ -z "$GENERATOR_DIR" ] && exit 1 -[ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR" - dev=$(dev_unit_name "${root}") { echo "[Unit]" @@ -62,37 +93,6 @@ mkdir -p "$GENERATOR_DIR/$dev.device.d" echo "JobRunningTimeoutSec=300" } > "$GENERATOR_DIR/$dev.device.d/timeout.conf" -dev=$(dev_unit_name /dev/disk/by-label/COS_OEM) -{ - echo "[Unit]" - echo "DefaultDependencies=no" - echo "Before=cos-setup-rootfs.service" - echo "Conflicts=initrd-switch-root.target" - echo "[Mount]" - echo "Where=/oem" - echo "What=/dev/disk/by-label/COS_OEM" - echo "Options=rw,suid,dev,exec,noauto,nouser,async" -} > "$GENERATOR_DIR"/oem.mount - -if [ ! -e "$GENERATOR_DIR/cos-setup-rootfs.service.wants/oem.mount" ]; then - mkdir -p "$GENERATOR_DIR"/cos-setup-rootfs.service.wants - ln -s "$GENERATOR_DIR"/oem.mount \ - "$GENERATOR_DIR"/cos-setup-rootfs.service.wants/oem.mount -fi - -mkdir -p "$GENERATOR_DIR/$dev.device.d" -{ - echo "[Unit]" - echo "Before=initrd-root-fs.target" - echo "JobRunningTimeoutSec=${oem_timeout}" -} > "$GENERATOR_DIR/$dev.device.d/timeout.conf" - -if [ ! -e "$GENERATOR_DIR/initrd-root-fs.target.wants/$dev.device" ]; then - mkdir -p "$GENERATOR_DIR"/initrd-root-fs.target.wants - ln -s "$GENERATOR_DIR"/"$dev".device \ - "$GENERATOR_DIR"/initrd-root-fs.target.wants/"$dev".device -fi - case "${cos_overlay}" in UUID=*) \ cos_overlay="block:/dev/disk/by-uuid/${cos_overlay#UUID=}" diff --git a/packages/immutable-rootfs/definition.yaml b/packages/immutable-rootfs/definition.yaml index 434d0fcb677..f43946fcdac 100644 --- a/packages/immutable-rootfs/definition.yaml +++ b/packages/immutable-rootfs/definition.yaml @@ -1,3 +1,3 @@ name: "immutable-rootfs" category: "system" -version: "0.0.30" +version: "0.0.31" diff --git a/tests/fallback/fallback_test.go b/tests/fallback/fallback_test.go index 3f45da27f82..4f2801086fc 100644 --- a/tests/fallback/fallback_test.go +++ b/tests/fallback/fallback_test.go @@ -21,9 +21,9 @@ var _ = Describe("cOS booting fallback tests", func() { It("fallbacks by booting into passive", func() { Expect(s.BootFrom()).To(Equal(sut.Active)) - _, err := s.Command("mount -o rw,remount /run/initramfs/isoscan") + _, err := s.Command("mount -o rw,remount /run/initramfs/cos-state") Expect(err).ToNot(HaveOccurred()) - _, err = s.Command("rm -rf /run/initramfs/isoscan/cOS/active.img") + _, err = s.Command("rm -rf /run/initramfs/cos-state/cOS/active.img") Expect(err).ToNot(HaveOccurred()) s.Reboot() @@ -35,11 +35,11 @@ var _ = Describe("cOS booting fallback tests", func() { It("fallbacks by booting into recovery", func() { Expect(s.BootFrom()).To(Equal(sut.Active)) - _, err := s.Command("mount -o rw,remount /run/initramfs/isoscan") + _, err := s.Command("mount -o rw,remount /run/initramfs/cos-state") Expect(err).ToNot(HaveOccurred()) - _, err = s.Command("rm -rf /run/initramfs/isoscan/cOS/active.img") + _, err = s.Command("rm -rf /run/initramfs/cos-state/cOS/active.img") Expect(err).ToNot(HaveOccurred()) - _, err = s.Command("rm -rf /run/initramfs/isoscan/cOS/passive.img") + _, err = s.Command("rm -rf /run/initramfs/cos-state/cOS/passive.img") Expect(err).ToNot(HaveOccurred()) s.Reboot() From 95ce4665ed0e6a84d5bacccdb7b1cde7f0d03b5e Mon Sep 17 00:00:00 2001 From: David Cassany Date: Tue, 22 Jun 2021 13:11:15 +0200 Subject: [PATCH 4/4] Fix upgrade test Signed-off-by: David Cassany --- tests/upgrades-images-signed/upgrade_test.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/upgrades-images-signed/upgrade_test.go b/tests/upgrades-images-signed/upgrade_test.go index 6971ac6bc20..d689d97eeb0 100644 --- a/tests/upgrades-images-signed/upgrade_test.go +++ b/tests/upgrades-images-signed/upgrade_test.go @@ -60,12 +60,8 @@ var _ = Describe("cOS Upgrade tests - Images signed", func() { It("fails if verify is enabled on an unsigned/malformed version", func() { out, err := s.Command("cos-upgrade --docker-image raccos/releases-opensuse:cos-system-0.5.0") Expect(err).To(HaveOccurred()) - Expect(out).Should(ContainSubstring("image-mtree-check")) + Expect(out).Should(ContainSubstring("luet-mtree")) Expect(out).Should(ContainSubstring("error while executing plugin")) - out, err = s.Command("cat /tmp/image-mtree-check.log") - Expect(out).Should(ContainSubstring("Got cos-system-0.5.0, continue...")) - Expect(out).Should(ContainSubstring("Finished all checks with errors")) - }) }) })