On Fri, Mar 02, 2018 at 03:21:00PM -0700, Aaron Bieber wrote:
> On Fri, Mar 02, 2018 at 07:32:04AM -0700, Aaron Bieber wrote:
> > Hi,
> >
> > Currently disks can only be entered in the [sw]d[0-9][0-9] format at the
> > "Which disk is the root disk?" prompt. This is great for humans, but
> > things get tricky when doing an autoinstall upgrade on systems where
> > connected disks change frequently.
> >
> > This diff lets you put the DUID in the response file.
> >
> > If anyone has a better way to determine the disk from the duid, I am all
> > ears :D
> >
> > Cheers,
> > Aaron
> >
>
> New version uses hw.disknames vs the ghetto diskutil | grep check.
>
> Thanks to Philipp Buehler for proper cluesticking :D
>

Few more tweaks (thanks to phy1729 on #metabug):
 - don't loop over the info passed to bsort
 - stop looping if we find our duid -> disk mapping

Index: distrib/miniroot/install.sub
===================================================================
RCS file: /cvs/src/distrib/miniroot/install.sub,v
retrieving revision 1.1065
diff -u -p -r1.1065 install.sub
--- distrib/miniroot/install.sub        21 Feb 2018 20:02:37 -0000      1.1065
+++ distrib/miniroot/install.sub        2 Mar 2018 23:48:23 -0000
@@ -306,6 +306,13 @@ scan_disknames() {
        bsort $(for _n in $_disks; do echo "${_n%%:*} "; done | sed -n "$1")
 }

+# Return disk devices along with their uids.
+scan_disks() {
+       local IFS=, _disks=$(sysctl -n hw.disknames)
+
+       bsort $_disks
+}
+
 # Return disk devices found in hw.disknames.
 get_dkdevs() {
        echo $(scan_disknames "${MDDKDEVS:-/^[sw]d[0-9][0-9]* /s/ .*//p}")
@@ -2201,6 +2208,23 @@ set_timezone() {
        done
 }

+# Determine the disk name from supplied disk uid.
+duid_to_disk() {
+       local _in=$1 _disk
+       local _disks=$(scan_disks)
+
+       for _d in ${_disks}; do
+               local _a=${_d##*:}
+               local _b=${_d%%:*}
+               if [[ $_in == ${_a} ]]; then
+                       echo $_b
+                       return
+               fi
+       done
+
+       echo $_in
+}
+
 # Determine if the supplied disk is a potential root disk, by:
 # - Check the disklabel if there is an 'a' partition of type 4.2BSD
 # - Mount the partition (read-only) and look for typical root filesystem layout
@@ -2231,7 +2255,8 @@ get_rootinfo() {
                case $resp in
                "?")    diskinfo $(get_dkdevs);;
                '')     ;;
-               *)      if isin "$resp" $(get_dkdevs); then
+               *)      resp=$(duid_to_disk "$resp")
+                       if isin "$resp" $(get_dkdevs); then
                                [[ $MODE == install ]] && break
                                is_rootdisk "$resp" && break
                                echo "$resp is not a valid root disk."

--
PGP: 0x1F81112D62A9ADCE / 3586 3350 BFEA C101 DB1A  4AF0 1F81 112D 62A9 ADCE

Reply via email to