Skip to content

Commit

Permalink
installer: Handle NVMe symlink aliases.
Browse files Browse the repository at this point in the history
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 <[email protected]>

OXT-1654

(cherry picked from commit 558b76d)
Signed-off-by: Eric Chanudet <[email protected]>
  • Loading branch information
Eric Chanudet committed Jul 25, 2019
1 parent 6c56607 commit 027f5cb
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions common/stages/Functions/library
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 027f5cb

Please sign in to comment.