From 903bacfd25cd16544a3088835207e44ce1c53b88 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Tue, 18 Jan 2022 16:25:14 +0100 Subject: [PATCH] arm: create COS_PERSISTENT instead of COS_OEM (#1023) * arm: create COS_PERSISTENT instead of COS_OEM Add a cloud-init also to automatically expand the COS_PERSISTENT partition on first boot Signed-off-by: Ettore Di Giacinto * ci [dropme] trigger image creation Signed-off-by: Ettore Di Giacinto * Add rd.cos.oemlabel=COS_OEM to arm images bootargs Signed-off-by: Ettore Di Giacinto * arm: Add cloud-config layout.env defaults Signed-off-by: Ettore Di Giacinto --- .../multi-arch-embedded-devices-examples.yaml | 1 + examples/odroid-c2/files/etc/cos/bootargs.cfg | 4 +- .../files/system/oem/01_auto_expand.yaml | 9 +++++ .../odroid-c2/files/system/oem/01_layout.yaml | 38 ++++++++++++++----- examples/rpi/files/etc/cos/bootargs.cfg | 4 +- .../rpi/files/system/oem/01_auto_expand.yaml | 9 +++++ examples/rpi/files/system/oem/01_layout.yaml | 38 ++++++++++++++----- images/arm-img-builder.sh | 26 +++++++------ 8 files changed, 93 insertions(+), 36 deletions(-) create mode 100644 examples/odroid-c2/files/system/oem/01_auto_expand.yaml create mode 100644 examples/rpi/files/system/oem/01_auto_expand.yaml diff --git a/.github/workflows/multi-arch-embedded-devices-examples.yaml b/.github/workflows/multi-arch-embedded-devices-examples.yaml index e641c3a106a..d05c24445fa 100644 --- a/.github/workflows/multi-arch-embedded-devices-examples.yaml +++ b/.github/workflows/multi-arch-embedded-devices-examples.yaml @@ -5,6 +5,7 @@ on: push: branches: - master + - arm_adaptations tags: - '*' diff --git a/examples/odroid-c2/files/etc/cos/bootargs.cfg b/examples/odroid-c2/files/etc/cos/bootargs.cfg index f2801b85cb8..80e5b8903c6 100644 --- a/examples/odroid-c2/files/etc/cos/bootargs.cfg +++ b/examples/odroid-c2/files/etc/cos/bootargs.cfg @@ -1,8 +1,8 @@ set kernel=/boot/vmlinuz if [ -n "$recoverylabel" ]; then - set kernelcmd="console=tty1 console=ttyS0 root=live:LABEL=$recoverylabel rd.live.dir=/ rd.live.squashimg=$img panic=5" + set kernelcmd="console=tty1 console=ttyS0 root=live:LABEL=$recoverylabel rd.live.dir=/ rd.live.squashimg=$img panic=5 rd.cos.oemtimeout=10" else - set kernelcmd="console=tty1 console=ttyS0 root=LABEL=$label cos-img/filename=$img panic=5 security=selinux selinux=1" + set kernelcmd="console=tty1 console=ttyS0 root=LABEL=$label cos-img/filename=$img panic=5 security=selinux selinux=1 rd.cos.oemtimeout=10 rd.cos.oemlabel=COS_OEM" fi set initramfs=/boot/initrd diff --git a/examples/odroid-c2/files/system/oem/01_auto_expand.yaml b/examples/odroid-c2/files/system/oem/01_auto_expand.yaml new file mode 100644 index 00000000000..2e5e8ffbd6e --- /dev/null +++ b/examples/odroid-c2/files/system/oem/01_auto_expand.yaml @@ -0,0 +1,9 @@ +name: "Expand COS_PERSISTENT" +stages: + rootfs: + - name: "Expand persistent partition" + layout: + device: + label: "COS_PERSISTENT" + expand_partition: + size: 0 \ No newline at end of file diff --git a/examples/odroid-c2/files/system/oem/01_layout.yaml b/examples/odroid-c2/files/system/oem/01_layout.yaml index f5b47e93187..98fb295015d 100644 --- a/examples/odroid-c2/files/system/oem/01_layout.yaml +++ b/examples/odroid-c2/files/system/oem/01_layout.yaml @@ -1,16 +1,34 @@ -name: "Immutable Layout" +# The only difference with main cOS is that we don't require the OEM partition here +name: "Rootfs Layout Settings" stages: + rootfs.before: + - name: "Pull data from provider" + datasource: + providers: ["cdrom"] + path: "/oem" rootfs: - # As the image creation script doesn't set up any COS_PERSISTENT partition - # or we either partition one on boot, or the user has to provide it. - # With this setting we don't require COS_PERSISTENT to be mounted, - # that means that the system will boot only in ephemeral mode with no persistency except - # OEM files. - # To override this behavior, simply overwrite this file OR specify - # a cloud init which is executed after this one in the /oem partition (e.g. 02_custom_layout.yaml ). - if: '[ ! -f "/run/cos/recovery_mode" ]' - name: "Don't require COS_PERSISTENT" + name: "Layout configuration" environment_file: /run/cos/cos-layout.env environment: - VOLUMES: "LABEL=COS_OEM:/oem" + VOLUMES: "LABEL=COS_PERSISTENT:/usr/local" OVERLAY: "tmpfs:25%" + - if: '[ -f "/run/cos/recovery_mode" ]' + # omit the persistent partition on recovery mode + name: "Layout configuration" + environment_file: /run/cos/cos-layout.env + environment: + VOLUMES: "" + OVERLAY: "tmpfs:25%" + initramfs: + - if: '[ ! -f "/run/cos/recovery_mode" ]' + name: "Persist /etc/machine-id" + commands: + - | + # persist machine-id + if [ -s /usr/local/etc/machine-id ]; then + cat /usr/local/etc/machine-id > /etc/machine-id + else + mkdir -p /usr/local/etc + cp /etc/machine-id /usr/local/etc + fi diff --git a/examples/rpi/files/etc/cos/bootargs.cfg b/examples/rpi/files/etc/cos/bootargs.cfg index b3a1a0a2331..9ac100375a0 100644 --- a/examples/rpi/files/etc/cos/bootargs.cfg +++ b/examples/rpi/files/etc/cos/bootargs.cfg @@ -11,9 +11,9 @@ set kernel=/boot/vmlinuz # https://bugzilla.opensuse.org/show_bug.cgi?id=1181683 and https://github.com/raspberrypi/linux/issues/4020 if [ -n "$recoverylabel" ]; then - set kernelcmd="console=tty1 console=ttyS0,115200 root=live:LABEL=$recoverylabel rd.live.dir=/ rd.live.squashimg=$img panic=5 modprobe.blacklist=vc4" + set kernelcmd="console=tty1 console=ttyS0,115200 root=live:LABEL=$recoverylabel rd.live.dir=/ rd.live.squashimg=$img panic=5 modprobe.blacklist=vc4 rd.cos.oemtimeout=10" else - set kernelcmd="console=tty1 console=ttyS0,115200 root=LABEL=$label cos-img/filename=$img panic=5 security=selinux selinux=1 modprobe.blacklist=vc4" + set kernelcmd="console=tty1 console=ttyS0,115200 root=LABEL=$label cos-img/filename=$img panic=5 security=selinux selinux=1 modprobe.blacklist=vc4 rd.cos.oemtimeout=10 rd.cos.oemlabel=COS_OEM" fi set initramfs=/boot/initrd diff --git a/examples/rpi/files/system/oem/01_auto_expand.yaml b/examples/rpi/files/system/oem/01_auto_expand.yaml new file mode 100644 index 00000000000..2e5e8ffbd6e --- /dev/null +++ b/examples/rpi/files/system/oem/01_auto_expand.yaml @@ -0,0 +1,9 @@ +name: "Expand COS_PERSISTENT" +stages: + rootfs: + - name: "Expand persistent partition" + layout: + device: + label: "COS_PERSISTENT" + expand_partition: + size: 0 \ No newline at end of file diff --git a/examples/rpi/files/system/oem/01_layout.yaml b/examples/rpi/files/system/oem/01_layout.yaml index f5b47e93187..98fb295015d 100644 --- a/examples/rpi/files/system/oem/01_layout.yaml +++ b/examples/rpi/files/system/oem/01_layout.yaml @@ -1,16 +1,34 @@ -name: "Immutable Layout" +# The only difference with main cOS is that we don't require the OEM partition here +name: "Rootfs Layout Settings" stages: + rootfs.before: + - name: "Pull data from provider" + datasource: + providers: ["cdrom"] + path: "/oem" rootfs: - # As the image creation script doesn't set up any COS_PERSISTENT partition - # or we either partition one on boot, or the user has to provide it. - # With this setting we don't require COS_PERSISTENT to be mounted, - # that means that the system will boot only in ephemeral mode with no persistency except - # OEM files. - # To override this behavior, simply overwrite this file OR specify - # a cloud init which is executed after this one in the /oem partition (e.g. 02_custom_layout.yaml ). - if: '[ ! -f "/run/cos/recovery_mode" ]' - name: "Don't require COS_PERSISTENT" + name: "Layout configuration" environment_file: /run/cos/cos-layout.env environment: - VOLUMES: "LABEL=COS_OEM:/oem" + VOLUMES: "LABEL=COS_PERSISTENT:/usr/local" OVERLAY: "tmpfs:25%" + - if: '[ -f "/run/cos/recovery_mode" ]' + # omit the persistent partition on recovery mode + name: "Layout configuration" + environment_file: /run/cos/cos-layout.env + environment: + VOLUMES: "" + OVERLAY: "tmpfs:25%" + initramfs: + - if: '[ ! -f "/run/cos/recovery_mode" ]' + name: "Persist /etc/machine-id" + commands: + - | + # persist machine-id + if [ -s /usr/local/etc/machine-id ]; then + cat /usr/local/etc/machine-id > /etc/machine-id + else + mkdir -p /usr/local/etc + cp /etc/machine-id /usr/local/etc + fi diff --git a/images/arm-img-builder.sh b/images/arm-img-builder.sh index f7b1f5a78ed..8e33b27397d 100755 --- a/images/arm-img-builder.sh +++ b/images/arm-img-builder.sh @@ -25,6 +25,7 @@ load_vars() { : "${RECOVERY_LABEL:=COS_RECOVERY}" : "${ACTIVE_LABEL:=COS_ACTIVE}" : "${PASSIVE_LABEL:=COS_PASSIVE}" + : "${PERSISTENT_LABEL:=COS_PERSISTENT}" : "${SYSTEM_LABEL:=COS_SYSTEM}" : "${STATE_LABEL:=COS_STATE}" } @@ -374,9 +375,9 @@ if [ "$model" == "rpi64" ]; then else sgdisk -n 1:8192:+16M -c 1:EFI -t 1:0700 ${output_image} fi -sgdisk -n 2:0:+64M -c 2:oem -t 2:8300 ${output_image} -sgdisk -n 3:0:+${state_size}M -c 3:state -t 3:8300 ${output_image} -sgdisk -n 4:0:+${recovery_size}M -c 4:recovery -t 4:8300 ${output_image} +sgdisk -n 2:0:+${state_size}M -c 2:state -t 2:8300 ${output_image} +sgdisk -n 3:0:+${recovery_size}M -c 3:recovery -t 3:8300 ${output_image} +sgdisk -n 4:0:+64M -c 4:persistent -t 4:8300 ${output_image} sgdisk -m 1:2:3:4 ${output_image} @@ -407,17 +408,17 @@ kpartx -va $DRIVE echo ">> Populating partitions" efi=${device}p1 -oem=${device}p2 -state=${device}p3 -recovery=${device}p4 +state=${device}p2 +recovery=${device}p3 +persistent=${device}p4 -# Create partitions (RECOVERY, STATE, OEM) +# Create partitions (RECOVERY, STATE, COS_PERSISTENT) mkfs.vfat -F 32 ${efi} fatlabel ${efi} EFI mkfs.ext4 -F -L ${RECOVERY_LABEL} $recovery mkfs.ext4 -F -L ${STATE_LABEL} $state -mkfs.ext4 -F -L ${OEM_LABEL} $oem +mkfs.ext4 -F -L ${PERSISTENT_LABEL} $persistent mkdir $WORKDIR/state mkdir $WORKDIR/recovery @@ -430,10 +431,11 @@ mount $efi $WORKDIR/efi # Set a OEM config file if specified if [ -n "$config" ]; then echo ">> Copying $config OEM config file" - mkdir $WORKDIR/oem - mount $oem $WORKDIR/oem - get_url $config $WORKDIR/oem/99_custom.yaml - umount $WORKDIR/oem + mkdir $WORKDIR/persistent + mount $persistent $WORKDIR/persistent + mkdir $WORKDIR/persistent/cloud-config + get_url $config $WORKDIR/persistent/cloud-config/99_custom.yaml + umount $WORKDIR/persistent fi # Copy over content