From 027f5cb477322161a5497e3fbfba823e0a73dd41 Mon Sep 17 00:00:00 2001 From: Eric Chanudet Date: Tue, 23 Jul 2019 16:12:15 -0400 Subject: [PATCH] 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