From 027f5cb477322161a5497e3fbfba823e0a73dd41 Mon Sep 17 00:00:00 2001 From: Eric Chanudet Date: Tue, 23 Jul 2019 16:12:15 -0400 Subject: [PATCH 1/2] installer: Handle NVMe symlink aliases. udev may create a symlink alias to the block device in /dev for some NVMe drives. get_devnode_{disk,partition} assumes they are passed the block device path, but some utility tools (e.g, lvm-utils) can return the symlink alias instead. Add a sanitizing function to handle that. Signed-off-by: Eric Chanudet OXT-1654 (cherry picked from commit 558b76db93b4fbe56327f385367e934d58554cac) Signed-off-by: Eric Chanudet --- common/stages/Functions/library | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/common/stages/Functions/library b/common/stages/Functions/library index 4953a0f..b7a54ea 100644 --- a/common/stages/Functions/library +++ b/common/stages/Functions/library @@ -396,11 +396,27 @@ reread_partition_table() udevadm settle >&2 } +#----------------------------------------------------------- +# Usage: sanitize_devnode /dev/device +# Should /dev/device be a symlink alias, follow the link and print the block +# device path on stdout. +sanitize_devnode() { + local dev="$1" + + if [ -h "${dev}" ]; then + # NVMe may have entries in /dev that are symblink aliases to their + # block device (e.g, /dev/512GB_68PS115OT8JQ-part1 -> nvme0n1p1) + readlink -f "${dev}" + else + echo "${dev}" + fi +} + #----------------------------------------------------------- # Usage: get_devnode_disk /dev/(sd[a-z]\+[0-9]\+|/dev/nvme[0-9]\+n[0-9]\+p[0-9]\+) # Prints the disk component of the argument devnode on stdout. get_devnode_disk() { - local devnode="$1" + local devnode=$(sanitize_devnode "$1") local disk case "${devnode}" in @@ -414,7 +430,7 @@ get_devnode_disk() { # Usage: get_devnode_partition /dev/(sd[a-z]\+[0-9]\+|/dev/nvme[0-9]\+n[0-9]\+p[0-9]\+) # Prints the partition component of the argument devnode on stdout. get_devnode_partition() { - local devnode="$1" + local devnode=$(sanitize_devnode "$1") local part case "${devnode}" in From fb009ec5200bc6b55c335440c7b91c754f5fb2e0 Mon Sep 17 00:00:00 2001 From: Eric Chanudet Date: Tue, 23 Jul 2019 16:22:25 -0400 Subject: [PATCH 2/2] part2: Use common for devnode sanitation. sanitize_devnode will follow the symlink alias and print the block device full path on stdout. Use the interface instead of local snippets. Signed-off-by: Eric Chanudet OXT-1654 (cherry picked from commit bb0483f5bee451b822ef945bbf2c8d85dbfb190c) Signed-off-by: Eric Chanudet --- part2/stages/Remove-partitions | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/part2/stages/Remove-partitions b/part2/stages/Remove-partitions index 7996960..356b002 100755 --- a/part2/stages/Remove-partitions +++ b/part2/stages/Remove-partitions @@ -24,24 +24,13 @@ # Remove every VG assigned to that disk. vgs=$(vgs --noheading -o vg_name) -if [ -L ${TARGET_DISK} ]; then - dev="/dev/$(readlink ${TARGET_DISK})" -else - dev="${TARGET_DISK}" -fi for vg in ${vgs}; do # List all PV backing current VG. pvs="$(vgs --noheading -o pv_name ${vg})" pvs_on_target="" pvs_others="" for p in ${pvs}; do - if [ -L "${p}" ]; then - # NVMe will sometimes appear as symlinks to the actual device in - # the devfs (e.g: /dev/512GB_ -> nvme0n1p1). - dev="/dev/$(readlink ${p})" - else - dev="${p##/dev}" - fi + dev=$(sanitize_devnode "${p}") if [ "${dev##${TARGET_DISK}}" != "${dev}" ]; then pvs_on_target="${pvs_of_vg} ${dev}" else