diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-teardown-initramfs.sh b/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-teardown-initramfs.sh index 7f8135ace7..d8538ada88 100755 --- a/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-teardown-initramfs.sh +++ b/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-teardown-initramfs.sh @@ -211,6 +211,8 @@ main() { # clean it up so that no information from outside of the # real root is passed on to NetworkManager in the real root rm -rf /run/NetworkManager/ + + rm -rf /dev/disk/by-id/coreos-root-disk } main diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/count-fs.sh b/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/count-fs.sh new file mode 100755 index 0000000000..b1e13d9011 --- /dev/null +++ b/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/count-fs.sh @@ -0,0 +1,25 @@ +#!/bin/bash +# Returns amount of filesystems labeled `label` + +label=$1 +uids=() + +for path in /sys/block/*; do + disk=$(basename $path) + for pt in /sys/block/$disk/*; do + name=$(basename $pt) + if [[ "$name" =~ "$disk" ]]; then + eval $(udevadm info --query=property -n /dev/$name | grep -e PARTNAME -e ID_FS_UUID_ENC) + if [[ "$PARTNAME" == "$label" ]]; then + uid=$ID_FS_UUID_ENC + if [[ -z $uid ]]; then + uid=$(/usr/lib/udev/scsi-id -ugd /dev/$name || echo $pt) + fi + uids+=("$uid") + fi + fi + done +done + +uids=($(echo "${uids[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')) +echo ${#uids[@]} diff --git a/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/module-setup.sh b/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/module-setup.sh index a42bcc3724..dfad4dbe95 100755 --- a/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/module-setup.sh +++ b/overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/module-setup.sh @@ -22,6 +22,8 @@ install() { diff \ lsblk \ sed \ + sort \ + grep \ sgdisk inst_simple "$moddir/coreos-diskful-generator" \ @@ -30,6 +32,11 @@ install() { inst_script "$moddir/coreos-gpt-setup.sh" \ "/usr/sbin/coreos-gpt-setup" + inst_simple "/usr/lib/udev/rules.d/99-zz-coreos-stable-root.rules" + + inst_script "$moddir/count-fs.sh" \ + "/usr/bin/count-fs" + inst_script "$moddir/coreos-ignition-setup-user.sh" \ "/usr/sbin/coreos-ignition-setup-user" diff --git a/overlay.d/05core/usr/lib/udev/rules.d/99-zz-coreos-stable-root.rules b/overlay.d/05core/usr/lib/udev/rules.d/99-zz-coreos-stable-root.rules new file mode 100644 index 0000000000..0db3ef5fa6 --- /dev/null +++ b/overlay.d/05core/usr/lib/udev/rules.d/99-zz-coreos-stable-root.rules @@ -0,0 +1,19 @@ +# CoreOS-specific symlink for disk holdind filesystem labeled `root` + +ACTION!="add|change", GOTO="stable_root_end" +SUBSYSTEM!="block", GOTO="stable_root_end" +TEST!="/usr/bin/count-fs", GOTO="stable_root_end" + +# First run on disks and check how many filesystems labeled `root` we have +ENV{DEVTYPE}=="disk" \ + , PROGRAM=="/usr/bin/count-fs root", RESULT=="1" \ + , SYMLINK+="disk/by-id/coreos-root-disk" + +# During processing of disks there are no UUIDs available, so double check +# how many filesystems labeled `root` we have, and if it's not unique - remove +# the symlink +ENV{DEVTYPE}=="partition", ENV(ID_FS_LABEL_ENC)=="root" \ + , PROGRAM=="/usr/bin/count-fs root", RESULT!="1" \ + , RUN{program}+="/bin/rm -f /dev/disk/by-id/coreos-root-disk" + +LABEL="stable_root_end" diff --git a/tests/kola/ignition/stable-root/config.bu b/tests/kola/ignition/stable-root/config.bu new file mode 100644 index 0000000000..073be8fc98 --- /dev/null +++ b/tests/kola/ignition/stable-root/config.bu @@ -0,0 +1,10 @@ +variant: fcos +version: 1.3.0 +storage: + disks: + - device: /dev/disk/by-id/coreos-root-disk + wipe_table: false + partitions: + - number: 5 + size_mib: 1024 + label: toor diff --git a/tests/kola/ignition/stable-root/test.sh b/tests/kola/ignition/stable-root/test.sh new file mode 100755 index 0000000000..a004b19fd4 --- /dev/null +++ b/tests/kola/ignition/stable-root/test.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -xeuo pipefail + +# This test makes sure that ignition is able to use symlink to the disk with `root` fs + +# We don't need to test this on every platform. If it passes in +# one place it will pass everywhere. +# kola: { "platforms": "qemu-unpriv" } + +ok() { + echo "ok" "$@" +} + +fatal() { + echo "$@" >&2 + exit 1 +} + +link="/dev/disk/by-id/coreos-root-disk" +if [[ -h "${link}" ]]; then + fatal "${link} still exists" +fi + +ok "${link} doesn't exist"