-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
overlay.d: add udev rule for creating stable symlink to boot disk
Creates '/dev/disk/coreos-boot-disk' symlink to boot disk for use by Ignition config, therefore 'storage.disks' section could be defined without hardcoding /dev/sda, /dev/vda, etc. Issue: coreos/fedora-coreos-tracker#759 Signed-off-by: Nikita Dubrovskii <nikita@linux.ibm.com>
- Loading branch information
1 parent
7a488a4
commit 6d7b9ad
Showing
6 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-disk-contains-fs.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
# checks whether `disk` contains filesystem labeled `label` | ||
set -euo pipefail | ||
|
||
disk=$1 | ||
label=$2 | ||
|
||
# during execution of udev rules on disks 'lsblk' returns empty fields | ||
for pt in /sys/block/$disk/*; do | ||
name=$(basename $pt) | ||
if [[ "$name" =~ ${disk}p?[[:digit:]] ]] && [[ -e "/sys/block/$disk/$name/start" ]]; | ||
then | ||
eval $(udevadm info --query=property -n /dev/$name | grep -e ID_FS_LABEL -e PARTNAME) | ||
if [[ "${ID_FS_LABEL:-}" == "$label" ]] || [[ "${PARTNAME:-}" == "$label" ]]; then | ||
exit 0 | ||
fi | ||
fi | ||
done | ||
|
||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
overlay.d/05core/usr/lib/udev/rules.d/80-coreos-boot-disk.rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# CoreOS-specific symlink for boot disk | ||
|
||
ACTION!="add|change", GOTO="stable_boot_end" | ||
SUBSYSTEM!="block", GOTO="stable_boot_end" | ||
|
||
ENV{DEVTYPE}=="disk" \ | ||
, PROGRAM=="coreos-disk-contains-fs $name boot" \ | ||
, SYMLINK+="disk/by-id/coreos-boot-disk" | ||
|
||
LABEL="stable_boot_end" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
variant: fcos | ||
version: 1.3.0 | ||
storage: | ||
disks: | ||
- device: /dev/disk/by-id/coreos-boot-disk | ||
wipe_table: false | ||
partitions: | ||
- number: 5 | ||
size_mib: 1024 | ||
label: toor | ||
filesystems: | ||
- path: /var/lib/toor | ||
device: /dev/disk/by-partlabel/toor | ||
format: ext4 | ||
with_mount_unit: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/bin/bash | ||
set -xeuo pipefail | ||
|
||
# This test makes sure that ignition is able to use `coreos-boot-disk` symlink | ||
|
||
# We don't need to test this on every platform. If it passes in | ||
# one place it will pass everywhere. | ||
# kola: { "platforms": "qemu-unpriv" } | ||
|
||
fatal() { | ||
echo "$@" >&2 | ||
exit 1 | ||
} | ||
|
||
# symlink shouldn't be propogated to real-root | ||
link="/dev/disk/by-id/coreos-boot-disk" | ||
if [[ -h "${link}" ]]; then | ||
fatal "${link} still exists" | ||
fi | ||
|
||
# sanity-check that the root disk has all required partitions | ||
findmnt -nvr -o SOURCE /boot | ||
findmnt -nvr -o SOURCE /sysroot | ||
toor=$(findmnt -nvr -o SOURCE /var/lib/toor) | ||
if [[ ! "$toor" =~ ^/dev/[a-z0-9]+p?5$ ]]; then | ||
fatal "${toor} is not 5th partition" | ||
fi |