From f27f51c6c80312fb6be43d28b67c5c1c1f31b3e5 Mon Sep 17 00:00:00 2001
From: Michael Prokop <mprokop@sipwise.com>
Date: Mon, 28 Feb 2022 16:27:16 +0100
Subject: [PATCH] TT#165600 Add support for NVMe disks

The logic to detect disks via /proc/partitions didn't cover NVMe disks,
as the regex '[a-z]$' fails for the "nvme0n1" pattern:

| % cat /proc/partitions
| major minor  #blocks  name
|
|  259        0  500107608 nvme0n1
|  259        1     524288 nvme0n1p1
|  259        2  499582279 nvme0n1p2
|  [...]
|    8        0  384638976 sda
|    8        1  384606208 sda1

Instead, let's use lsblk to detect present disks, which works
fine for all kinds of disks, incl. NVMe devices.

Change-Id: I586877da8b4fadf3d05b4e6c8e88bfdeae6d7f15
---
 templates/scripts/includes/disk_selection.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/templates/scripts/includes/disk_selection.sh b/templates/scripts/includes/disk_selection.sh
index 4c14e53..368ca6a 100755
--- a/templates/scripts/includes/disk_selection.sh
+++ b/templates/scripts/includes/disk_selection.sh
@@ -71,7 +71,8 @@ get_disk_info() {
 rm -f /tmp/disk_options
 
 declare -a AVAILABLE_DISKS
-AVAILABLE_DISKS=( $(awk '/[a-z]$/ {print $4}' /proc/partitions | grep -v '^name$' | sort -u) )
+AVAILABLE_DISKS=( $(lsblk --list -o NAME,TYPE | awk '$2 == "disk" {print $1}' | sort -u) )
+
 if [[ -z "${AVAILABLE_DISKS[*]}" ]] ; then
   dialog --title "Disk selection" \
     --msgbox "Sorry, no disks found. Please make sure to have a hard disk attached to your system/VM." 0 0