Skip to content

Commit

Permalink
arm: create COS_PERSISTENT instead of COS_OEM (#1023)
Browse files Browse the repository at this point in the history
* 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 <edigiacinto@suse.com>

* ci [dropme] trigger image creation

Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>

* Add rd.cos.oemlabel=COS_OEM to arm images bootargs

Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>

* arm: Add cloud-config layout.env defaults

Signed-off-by: Ettore Di Giacinto <edigiacinto@suse.com>
  • Loading branch information
mudler authored Jan 18, 2022
1 parent bc293e3 commit 903bacf
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
push:
branches:
- master
- arm_adaptations
tags:
- '*'

Expand Down
4 changes: 2 additions & 2 deletions examples/odroid-c2/files/etc/cos/bootargs.cfg
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions examples/odroid-c2/files/system/oem/01_auto_expand.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: "Expand COS_PERSISTENT"
stages:
rootfs:
- name: "Expand persistent partition"
layout:
device:
label: "COS_PERSISTENT"
expand_partition:
size: 0
38 changes: 28 additions & 10 deletions examples/odroid-c2/files/system/oem/01_layout.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions examples/rpi/files/etc/cos/bootargs.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions examples/rpi/files/system/oem/01_auto_expand.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: "Expand COS_PERSISTENT"
stages:
rootfs:
- name: "Expand persistent partition"
layout:
device:
label: "COS_PERSISTENT"
expand_partition:
size: 0
38 changes: 28 additions & 10 deletions examples/rpi/files/system/oem/01_layout.yaml
Original file line number Diff line number Diff line change
@@ -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
26 changes: 14 additions & 12 deletions images/arm-img-builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
}
Expand Down Expand Up @@ -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}

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 903bacf

Please sign in to comment.