Skip to content

Commit

Permalink
overlay.d: add udev rule for stable-root disk
Browse files Browse the repository at this point in the history
Issue: coreos/fedora-coreos-tracker#759

Signed-off-by: Nikita Dubrovskii <nikita@linux.ibm.com>
  • Loading branch information
nikita-dubrovskii committed Nov 26, 2021
1 parent 548312e commit 1ae196e
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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[@]}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ install() {
diff \
lsblk \
sed \
sort \
grep \
sgdisk

inst_simple "$moddir/coreos-diskful-generator" \
Expand All @@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 10 additions & 0 deletions tests/kola/ignition/stable-root/config.bu
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions tests/kola/ignition/stable-root/test.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 1ae196e

Please sign in to comment.