Skip to content

Commit

Permalink
overlay.d: create symlink to the disk holding root partition
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 4, 2021
1 parent c5b299a commit e1836ca
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
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

Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ 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/

# Remove symlink to disk holding 'root' partition
rm -f /dev/disk/by-label/coreos-root-disk
}

main
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
# creates a stable device path for the boot disk when there's exactly one such disk,
# and create no such symlink in other cases (e.g. rootfs RAID)
# Symlink is not propogated to the real root (removed during coreos-teardown-initramfs)

set -euo pipefail

# force kernel to update info about disks
for dev in $(lsblk -o NAME --noheadings --nodeps --list --paths); do
partx -u ${dev}
done

udevadm trigger
udevadm settle

LINK=/dev/disk/coreos-root-disk
PARTITIONS=()
# skip multipath disks (with same WWN)
mapfile -t PARTITIONS < <(lsblk -o WWN,LABEL,NAME,PKNAME --pairs --paths --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 /dev/disk/
ln -s ${PKNAME} ${LINK}
fi
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ install() {
diff \
lsblk \
sed \
sort \
grep \
partx \
sgdisk

inst_simple "$moddir/coreos-diskful-generator" \
Expand All @@ -30,6 +33,9 @@ install() {
inst_script "$moddir/coreos-gpt-setup.sh" \
"/usr/sbin/coreos-gpt-setup"

inst_script "$moddir/create-root-symlink.sh" \
"/usr/sbin/create-root-symlink"

inst_script "$moddir/coreos-ignition-setup-user.sh" \
"/usr/sbin/coreos-ignition-setup-user"

Expand All @@ -56,4 +62,7 @@ install() {
"ignition-diskful.target"

install_ignition_unit coreos-ignition-setup-user.service

install_ignition_unit coreos-root-symlink.service \
ignition-diskful.target
}

0 comments on commit e1836ca

Please sign in to comment.