Skip to content

Commit

Permalink
Forwards compatibility for immutable-rootfs feat
Browse files Browse the repository at this point in the history
This commit makes the immutable-rootfs module forwards compatible with
the other changes in mount, elemental-sysroot and elemental-setup.

It uses the new elemental.image and elemental.oemlabel cmdline paramters
if found, otherwise falls back to the old parameters and also sets the
/run/elemental/active|passive|recovery_mode files.

Signed-off-by: Fredrik Lönnegren <fredrik.lonnegren@suse.com>
  • Loading branch information
frelon committed Dec 12, 2023
1 parent c55c8d1 commit 314938d
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/tumbleweed/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ RUN cd /usr/lib/dracut && \
rm /*.patch

# Generate initrd with required elemental services
RUN elemental init -f elemental-rootfs,elemental-sysroot,elemental-setup,grub-config,grub-default-bootargs,dracut-config,cloud-config-defaults,cloud-config-essentials && \
RUN elemental init -f && \
kernel=$(ls /boot/Image-* 2>/dev/null | head -n1) && \
if [ -e "$kernel" ]; then ln -sf "${kernel#/boot/}" /boot/vmlinuz; fi && \
rm -rf /var/log/update* && \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ stages:
datasource:
providers: ["aws", "gcp", "openstack", "cdrom"]
path: "/oem"
rootfs:
- if: '[ ! -f "/run/cos/recovery_mode" ]'
name: "Layout configuration"
environment_file: /run/cos/cos-layout.env
environment:
OVERLAY: "tmpfs:25%"
initramfs:
- if: '[ ! -f "/run/elemental/recovery_mode" ]'
name: "Persist /etc/machine-id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ DefaultDependencies=no
After=initrd-fs.target
Requires=initrd-fs.target
Before=initrd.target
Wants=oem.mount
After=oem.mount

[Service]
RootDirectory=/sysroot
BindPaths=/proc /sys /dev /run /tmp
BindPaths=/proc /sys /dev /run /tmp /oem
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/elemental run-stage initramfs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# TODO we could sanity check $partlabel is set here so we can error out before even attempting to boot
set kernel=/boot/vmlinuz
if [ "${mode}" == "recovery" ]; then
set kernelcmd="console=tty1 console=ttyS0 root=LABEL=$recovery_label elemental.image=$mode elemental.oemlabel=COS_OEM security=selinux selinux=0 rd.neednet=1"
set kernelcmd="console=tty1 console=ttyS0 root=LABEL=$recovery_label elemental.image=$mode elemental.oemlabel=COS_OEM rd.cos.mount=LABEL=$oem_label:/oem security=selinux selinux=0 rd.neednet=1"
else
set kernelcmd="console=tty1 console=ttyS0 root=LABEL=$state_label elemental.image=$mode elemental.oemlabel=COS_OEM panic=5 security=selinux selinux=0 rd.neednet=1 fsck.mode=force fsck.repair=yes"
set kernelcmd="console=tty1 console=ttyS0 root=LABEL=$state_label elemental.image=$mode elemental.oemlabel=COS_OEM panic=5 security=selinux selinux=0 rd.neednet=1 rd.cos.mount=LABEL=$oem_label:/oem fsck.mode=force fsck.repair=yes"
fi
set initramfs=/boot/initrd
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh

cos_unit="elemental-immutable-rootfs.service"
cos_layout="/run/cos/cos-layout.env"
root_part_mnt="/run/initramfs/cos-state" # TODO change to something under /run/cos
root_part_mnt="/run/initramfs/elemental-state" # TODO change to something under /run/cos

# Omit any immutable roofs module logic if disabled
if getargbool 0 rd.cos.disable; then
exit 0
fi

if getargbool 0 elemental.disable; then
exit 0
fi

# Omit any immutable rootfs module logic if no image path provided
cos_img=$(getarg cos-img/filename=)
[ -z "${cos_img}" ] && exit 0
elemental_img=$(getarg elemental.image=)
[ -z "${cos_img}" && -z "${elemental_img}" ] && exit 0
[ -z "${cos_img}" ] && cos_img="/cOS/${elemental_img}.img"

[ -z "${root}" ] && root=$(getarg root=)

Expand All @@ -23,7 +29,10 @@ if getargbool 0 rd.cos.debugrw; then
fi

oem_timeout=$(getargnum 120 1 1800 rd.cos.oemtimeout=)

oem_label=$(getarg rd.cos.oemlabel=)
[ -z "${oem_label}" ] && oem_label=$(getarg elemental.oemlabel=)

cos_overlay=$(getarg rd.cos.overlay=)
[ -z "${cos_overlay}" ] && cos_overlay="tmpfs:20%"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,30 @@
# rd.cos.overlay=UUID=<vol_uuid>
# rd.cos.oemtimeout=<seconds>
# rd.cos.oemlabel=<vol_label>
# elemental.oemlabel=<vol_label>
# rd.cos.debugrw
# rd.cos.disable
# elemental.disable
# cos-img/filename=/cOS/active.img
# elemental.image=active

type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh

if getargbool 0 rd.cos.disable; then
return 0
fi

if getargbool 0 elemental.disable; then
return 0
fi

cos_img=$(getarg cos-img/filename=)
[ -z "${cos_img}" ] && return 0
elemental_img=$(getarg elemental.image=)
[ -z "${cos_img}" && -z "${elemental_img}" ] && return 0
[ -z "${root}" ] && root=$(getarg root=)

[ -n "${elemental_img}" ] && cos_img="/cOS/${elemental_img}.img"

cos_root_perm="ro"
if getargbool 0 rd.cos.debugrw; then
cos_root_perm="rw"
Expand All @@ -42,6 +52,7 @@ esac
[ "${rootok}" != "1" ] && return 0

info "root device set to root=${root}"
info "image set to=${cos_img}"

wait_for_dev -n "${root#block:}"

Expand All @@ -62,4 +73,14 @@ case "${cos_img}" in
echo -n 1 > /run/cos/passive_mode ;;
esac

mkdir -p /run/elemental
case "${cos_img}" in
*recovery*)
echo -n 1 > /run/elemental/recovery_mode ;;
*active*)
echo -n 1 > /run/elemental/active_mode ;;
*passive*)
echo -n 1 > /run/elemental/passive_mode ;;
esac

return 0
3 changes: 1 addition & 2 deletions scripts/run_vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ function start {
[ "kvm" == "${ELMNTL_ACCEL}" ] && cpu_arg="-cpu host" && kvm_arg="-enable-kvm"

if [ "${ELMNTL_DEBUG}" == "yes" ]; then
local pass_arg="-smbios type=11,value=io.systemd.credential:passwd.hashed-password.root=$(mkpasswd cos) "
qemu-system-${ELMNTL_TARGETARCH} ${kvm_arg} ${disk_arg} ${cdrom_arg} ${firmware_arg} ${usrnet_arg} \
${kvm_arg} ${memory_arg} ${graphics_arg} -serial stdio ${pidfile_arg} \
${display_arg} ${machine_arg} ${accel_arg} ${cpu_arg} ${pass_arg}
${display_arg} ${machine_arg} ${accel_arg} ${cpu_arg}
else
qemu-system-${ELMNTL_TARGETARCH} ${kvm_arg} ${disk_arg} ${cdrom_arg} ${firmware_arg} ${usrnet_arg} \
${kvm_arg} ${memory_arg} ${graphics_arg} ${serial_arg} ${pidfile_arg} \
Expand Down

0 comments on commit 314938d

Please sign in to comment.