From de705f06dbf86b67b4dcaeb12cc5d6f6653de40a Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Fri, 28 Aug 2020 11:13:15 -0400 Subject: [PATCH 1/4] Support OS install on nvme disk --- .../share/xcat/install/scripts/getinstdisk | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/xCAT-server/share/xcat/install/scripts/getinstdisk b/xCAT-server/share/xcat/install/scripts/getinstdisk index 8752f7663..a5cabb2b1 100644 --- a/xCAT-server/share/xcat/install/scripts/getinstdisk +++ b/xCAT-server/share/xcat/install/scripts/getinstdisk @@ -13,7 +13,7 @@ # type, select the first one. # 3. Select the default one: /dev/sda. # -# Output: /tmp/xcat.install_disk +# Output: Install disk name written to /tmp/xcat.install_disk # #----------------------------------------------------------- @@ -31,7 +31,7 @@ tmpfile="$tmpdir/getinstalldisk_" if [ -z "$install_disk" ]; then - echo "[get_install_disk]Information from /proc/partitions:" + echo "[get_install_disk]Contents of /proc/partitions:" cat /proc/partitions echo "" @@ -67,6 +67,7 @@ if [ -z "$install_disk" ]; then mkdir -p $mount_dir; disk_array="" + umount_rc=0 for partition in $partitions; do echo "[get_install_disk]Check the partition $partition." @@ -107,7 +108,13 @@ if [ -z "$install_disk" ]; then # It seems the kernel file in ubuntu and sles are named like vmlinux, but in RH it is called vmlinuz # To check both vmlinux and vmlinuz, use regular expression "vmlinu*" to match them for i in $ker_dir/vmlinu*; do - disk_part=${partition%%[0-9]*} + if [[ $partition = nvme* ]]; then + # Expected nvme partition format example: nvme0n1p1 + disk_part=${partition%%p*} + else + # Expected sd partition format example: sda1 + disk_part=${partition%%[0-9]*} + fi touch "$tmpfile$disk_part" disk_array=$disk_array"$disk_part " echo "[get_install_disk] The partition $partition has kernel file." @@ -115,6 +122,10 @@ if [ -z "$install_disk" ]; then done umount -l $mount_dir || echo "[get_install_disk] $partition umount failed." + if [ $? -ne 0 ]; then + # Preserve a umount failure RC + umount_rc=$? + fi else echo "[get_install_disk] Partition $partition mount failed or the partition is swap." fi @@ -128,7 +139,13 @@ if [ -z "$install_disk" ]; then echo "" fi - rmdir $mount_dir; + if [ $umount_rc -eq 0 ]; then + rmdir $mount_dir; + else + # Do not remove $mount_dir if there was a umount failure, as it might wipe out + # the contents of a still mounted disk + echo "[get_install_disk]There was a umount failure earlier, not removing $mount_dir" + fi for file in $tmpfile*; do rm $file; @@ -215,7 +232,7 @@ rm -rf $tmpdir; # Cannot find proper disk for OS install, select the default one "/dev/sda" if [ -z "$install_disk" ]; then install_disk="/dev/sda" - echo "[get_install_disk]The default install_disk is $install_disk." + echo "[get_install_disk]Choosing default install_disk is $install_disk." fi # Output the result to $install_disk_file From d0f486ce1057de484b5624c4c82f1415426744f0 Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Wed, 2 Sep 2020 17:00:50 -0400 Subject: [PATCH 2/4] Use case instead of if which does not work on Ubuntu --- .../share/xcat/install/scripts/getinstdisk | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/xCAT-server/share/xcat/install/scripts/getinstdisk b/xCAT-server/share/xcat/install/scripts/getinstdisk index a5cabb2b1..43325a4d4 100644 --- a/xCAT-server/share/xcat/install/scripts/getinstdisk +++ b/xCAT-server/share/xcat/install/scripts/getinstdisk @@ -108,13 +108,16 @@ if [ -z "$install_disk" ]; then # It seems the kernel file in ubuntu and sles are named like vmlinux, but in RH it is called vmlinuz # To check both vmlinux and vmlinuz, use regular expression "vmlinu*" to match them for i in $ker_dir/vmlinu*; do - if [[ $partition = nvme* ]]; then - # Expected nvme partition format example: nvme0n1p1 - disk_part=${partition%%p*} - else - # Expected sd partition format example: sda1 - disk_part=${partition%%[0-9]*} - fi + case $partition in + nvme*) + # Expected nvme partition format example: nvme0n1p1 + disk_part=${partition%%p*} + ;; + *) + # Expected sd partition format example: sda1 + disk_part=${partition%%[0-9]*} + ;; + esac touch "$tmpfile$disk_part" disk_array=$disk_array"$disk_part " echo "[get_install_disk] The partition $partition has kernel file." From 01780a010e8eb3f7397abc0e5d113e704c06d0e3 Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Fri, 26 Feb 2021 13:00:33 -0500 Subject: [PATCH 3/4] Improve debug messages and comments --- .../share/xcat/install/scripts/getinstdisk | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/xCAT-server/share/xcat/install/scripts/getinstdisk b/xCAT-server/share/xcat/install/scripts/getinstdisk index 43325a4d4..e4d5f395f 100644 --- a/xCAT-server/share/xcat/install/scripts/getinstdisk +++ b/xCAT-server/share/xcat/install/scripts/getinstdisk @@ -4,14 +4,15 @@ # # Get proper disk to install OS # -# 1. Check all partitions list in /proc/partitions, whether -# there is disk had OS installed. If there is, add it to +# 1. Check all partitions listed in /proc/partitions, whether +# there is a disk that had OS installed. If there is, add it to # the disk array. -# 2. If there is disk had OS installed, check disks list -# generated in Step 1. Else, check all disks get from -# /proc/partitions file. Sort them by WWN/PATH and driver -# type, select the first one. -# 3. Select the default one: /dev/sda. +# 2. If there is no disk that had OS installed found +# in Step 1, then check all disks in +# /proc/partitions file. Sort them by driver type, then by WWN/PATH +# select the first one. +# 3. If no disks selected in Steps 1 or 2, then +# select the default disk: /dev/sda. # # Output: Install disk name written to /tmp/xcat.install_disk # @@ -182,7 +183,7 @@ if [ -z "$install_disk" ]; then disk_data=$disk_wwn elif [ $has_wwn -eq 1 ]; then echo "[get_install_disk] The disk $disk has no wwn info." - echo "[get_install_disk] There is other disk has wwn info, so don't record this disk." + echo "[get_install_disk] There is another disk with wwn info, so don't record this disk." continue; elif [ "$disk_path" ]; then has_path=1 @@ -190,7 +191,7 @@ if [ -z "$install_disk" ]; then disk_data=$disk_path elif [ $has_path -eq 1 ]; then echo "[get_install_disk] The disk $disk has no wwn or path info." - echo "[get_install_disk] There is other disk has path info, so don't record this disk." + echo "[get_install_disk] There is another disk with path info, so don't record this disk." continue; else file_pre="other" @@ -235,7 +236,7 @@ rm -rf $tmpdir; # Cannot find proper disk for OS install, select the default one "/dev/sda" if [ -z "$install_disk" ]; then install_disk="/dev/sda" - echo "[get_install_disk]Choosing default install_disk is $install_disk." + echo "[get_install_disk]Choosing default install_disk $install_disk." fi # Output the result to $install_disk_file From ef814440be3ce2169a5a23539c2ce66234b1a8de Mon Sep 17 00:00:00 2001 From: Mark Gurevich Date: Wed, 3 Mar 2021 13:51:27 -0500 Subject: [PATCH 4/4] Extract correct size of the nvme disk partition --- xCAT-server/share/xcat/install/scripts/getinstdisk | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xCAT-server/share/xcat/install/scripts/getinstdisk b/xCAT-server/share/xcat/install/scripts/getinstdisk index e4d5f395f..5aff3589f 100644 --- a/xCAT-server/share/xcat/install/scripts/getinstdisk +++ b/xCAT-server/share/xcat/install/scripts/getinstdisk @@ -45,9 +45,10 @@ if [ -z "$install_disk" ]; then # Classify entries by DEVTYPE for entry in $entries; do - DEVSIZE=$(udevadm info --attribute-walk --name=$entry|grep size| sed -e 's/[^"]*"//' -e 's/"//'|tail -n 1) + DEVSIZE=$(udevadm info --attribute-walk --name=$entry|grep \{size\}| sed -e 's/[^"]*"//' -e 's/"//'|tail -n 1) if [ -z "$DEVSIZE" -o $DEVSIZE -lt 262144 ]; then # ignore small devices, that are likely remote media or similar + echo "[get_install_disk] Skipping partition $entry. Size too small: $DEVSIZE" continue fi