Parcourir la source

UEFI boot is coming, so platform-upgrade needs to handle GPT-partitioned devices. (#28)

* Detect removables by looking at the removable flag.

Improve the mechanism that detects the removable SmartOS boot device
such that it directly inspects the "Removable" flag in the diskinfo
output, rather than assuming anything about the transport bus that it
is attached on, since that doesn't seem stable.

* UEFI boot is coming, so handle GPT-labelled boot devices.

For more details, see https://github.com/joyent/rfd/tree/master/rfd/0156
Geoff Adams il y a 6 ans
Parent
commit
494fe0a8c8
1 fichiers modifiés avec 28 ajouts et 10 suppressions
  1. 28 10
      platform-upgrade

+ 28 - 10
platform-upgrade

@@ -170,19 +170,37 @@ fi
 
 echo -n "Checking current boot device..."
 if [[ -z $1 ]] ; then
-        removables=($(diskinfo -pH | awk '/^USB/ { print $2 }'))
+        removables=($(diskinfo -cH | \
+                      awk 'BEGIN { FS="\t" } $7~/\?\?R./ { print $2 }'))
+        echo -n " detected ${removables[@]}"
         if [[ ${#removables[@]} -eq 0 ]]; then
-                 removables=($(diskinfo -pH | awk '/^USB|^SCSI.*[0-9]+[ \s\t]+yes/ { print $2 }'))
+                echo
+                echo "Error: Unable to detect removable device."
+                diskinfo
+                echo "Specify correct device on the command line."
+                exit -1
+        elif [[ ${#removables[@]} -gt 1 ]]; then
+                echo
+                echo "Error: more than one removable device detected."
+                diskinfo -cH | awk 'BEGIN { FS="\t" } $7~/\?\?R./ { print }'
+                echo "Specify correct device on the command line."
+                exit -1
         fi
-        echo -n " detected ${removables[@]}"
-        if [[ ${#removables[@]} -gt 1 ]]; then
-                  echo
-                  echo "Error: more than one removable device detected."
-                  diskinfo | awk 'NR == 1 || /^USB/ { print }'
-                  echo "Specify correct device on the command line."
-                  exit -1
+        # Look for a GPT/EFI VTOC; if there isn't one, then this is almost
+        # certainly an MBR-partitioned device. If it's a GPT label, then we
+        # want the slice that's of type 2 (ROOT).
+        if [[ -e "/dev/dsk/${removables[0]}" ]]; then
+                partition=$(/usr/sbin/prtvtoc -h "/dev/dsk/${removables[0]}" | \
+                            awk ' $2 == 2 { print $1 }')
+                if [[ $? -eq 0 && -n "$partition" ]]; then
+                        echo -n ", GPT label"
+                        usb="/dev/dsk/${removables[0]}s${partition}"
+                fi
+        fi
+        if [[ -z "$usb" ]]; then
+                echo -n ", MBR label"
+                usb="/dev/dsk/${removables[0]}p1"
         fi
-        usb="/dev/dsk/${removables[0]}p1"
 else
         usb="$1"
         echo -n " using $usb"