forked from coreos/fedora-coreos-config
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
overlay.d: create udev rule for
stable-root
disk
Issue: coreos/fedora-coreos-tracker#759 Signed-off-by: Nikita Dubrovskii <nikita@linux.ibm.com>
- Loading branch information
1 parent
548312e
commit 68f6439
Showing
6 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/coreos-root-symlink.service
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,23 @@ | ||
[Unit] | ||
Description=Create symlink to boot disk | ||
ConditionPathExists=/etc/initrd-release | ||
DefaultDependencies=no | ||
Wants=systemd-udevd.service | ||
After=systemd-udevd.service | ||
|
||
Requires=dev-disk-by\x2dlabel-root.device | ||
After=dev-disk-by\x2dlabel-root.device | ||
# And since the boot device may be on multipath; optionally wait for it to | ||
# appear via the dynamic target. | ||
After=coreos-multipath-wait.target | ||
After=coreos-gpt-setup.service | ||
Before=ignition-disks.service | ||
|
||
OnFailure=emergency.target | ||
OnFailureJobMode=isolate | ||
|
||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=yes | ||
ExecStart=/usr/sbin/create-root-symlink | ||
|
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
35 changes: 35 additions & 0 deletions
35
overlay.d/05core/usr/lib/dracut/modules.d/35coreos-ignition/create-root-symlink.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,35 @@ | ||
#!/bin/bash | ||
# Creates a stable device path for the `boot` disk when there's exactly one such | ||
# disk, and creates nothing in other cases (e.g. rootfs RAID). Symlink is not | ||
# propogated to the real root and gets removed in `coreos-teardown-initramfs` | ||
|
||
set -euo pipefail | ||
|
||
udev_trigger() { | ||
udevadm trigger "$1" | ||
udevadm settle | ||
} | ||
|
||
# We should treat all paths (which have same WWN) to multipath disk as a single | ||
# disk, but `WWN` could be empty in `lsblk` output, so we call `partx` to force | ||
# kernel updating info about disks. Originally this issue was observed on s390x | ||
for dev in $(lsblk -o NAME --noheadings --nodeps --list --paths); do | ||
partx -u ${dev} || true | ||
done | ||
udev_trigger --subsystem-match=block | ||
|
||
LINK=disk/by-id/coreos-root-disk | ||
PARTITIONS=() | ||
|
||
# Unique sorting all disks labeled `root` keeping one path to each mpath disk | ||
mapfile -t PARTITIONS < <(lsblk -o WWN,LABEL,NAME,PKNAME --pairs --noheadings | grep 'LABEL="root"' | sed 's/WWN=\"\" //' | sort -u -k1,2) | ||
|
||
LENGTH=${#PARTITIONS[@]} | ||
if [[ ${LENGTH} -eq 1 ]]; then | ||
eval ${PARTITIONS[0]} | ||
echo "Creating symlink '${LINK}' to '${PKNAME}' (contains 'root' partition '${NAME}')" | ||
mkdir -p /run/udev/rules.d/ | ||
echo "KERNEL==\"${PKNAME}\", SUBSYSTEM==\"block\", SYMLINK+=\"${LINK}\"" > /run/udev/rules.d/99-stable-root.rules | ||
udevadm control --reload-rules | ||
udev_trigger /dev/${PKNAME} | ||
fi |
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
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 |
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,31 @@ | ||
#!/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 | ||
} | ||
|
||
unit="coreos-root-symlink.service" | ||
link="/dev/disk/by-id/coreos-root-disk" | ||
|
||
eval $(journalctl -o export MESSAGE_ID=39f53479d3a045ac8e11786248231fbf -u ${unit} | grep JOB_RESULT) | ||
if [[ "${JOB_RESULT}" != "done" ]]; then | ||
fatal "${unit} failed" | ||
fi | ||
|
||
if [[ -h ${link} ]]; then | ||
fatal "${unit} failed: ${link} still exists" | ||
fi | ||
|
||
ok "${unit} is ok" |