On Sun, 2 Apr 2023 at 1:52 PM, Klemens Nanni <k...@openbsd.org> wrote:

> For install, the root disk defaults to the first available [sw]d* disk.
>
> The new encryption question creates a softraid volume for you, which is
> obviously to be used as root disk.
>
> But on systems with multiple disks, the next one available may be another.
>
>         Available disks are: sd0 sd1.
>         Encrypt the root disk? (disk, 'no' or '?' for details) [no] sd0
>         ...
>         Available disks are: sd1 sd2.
>         Which disk is the root disk? ('?' for details) [sd1] ?
>         sd0: VirtIO, Block Device  (5.0G)
>         sd1: VirtIO, Block Device  (5.0G)
>         sd2: OPENBSD, SR CRYPTO, 006  (5.0G)
>         Available disks are: sd1 sd2.
>         Which disk is the root disk? ('?' for details) [sd1] sd1
>
> 'Encrypt the root disk?' is asked if and only if no softraid volume is
> assembled at that time, which means whatever volume exists afterwards is
> the intended root disk.
>
> Save and use it as default for the root question if set.
>
> This is nicely contained and has no behaviour change except for interactive
> crypto installs which now nail the default regardless of disk setup:
>
>         Available disks are: sd1 sd2.
>         Which disk is the root disk? ('?' for details) [sd2]
>
> OK?
>
> Index: install.sub
> ===================================================================
> RCS file: /cvs/src/distrib/miniroot/install.sub,v
> retrieving revision 1.1239
> diff -u -p -r1.1239 install.sub
> --- install.sub 2 Apr 2023 00:58:07 -0000       1.1239
> +++ install.sub 2 Apr 2023 01:20:18 -0000
> @@ -310,6 +310,11 @@ get_softraid_chunks() {
>         bioctl $_device 2>/dev/null | sed -n 's/.*<\(.*\).>$/\1/p'
>  }
>
> +# Return list of softraid volumes.
> +get_softraid_volumes() {
> +       bioctl softraid0 | sed -n 's/^softraid0.*\(sd[0-9]*\).*/\1/p'
> +}
> +
>  # Return disk devices found in hw.disknames.
>  get_dkdevs() {
>         scan_disknames "${MDDKDEVS:-/^[sw]d[0-9][0-9]* /s/ .*//p}"
> @@ -2398,7 +2403,7 @@ is_rootdisk() {
>
>  # Get global root information. ie. ROOTDISK, ROOTDEV and SWAPDEV.
>  get_rootinfo() {
> -       local _default=$(get_dkdevs_root) _dkdev
> +       local _default=${CRYPTOVOLUME:-$(get_dkdevs_root)} _dkdev ml
>         local _q="Which disk is the root disk? ('?' for details)"
>
>         while :; do
> @@ -3078,7 +3083,7 @@ encrypt_root() {
>
>         # Do not even try if softraid is in use already,
>         # e.g. auto-assembled at boot or done in (S)hell.
> -       [[ -z $(get_softraid_chunks) ]] || return
> +       [[ -z $(get_softraid_volumes) ]] || return
>
>         while :; do
>                 echo "Available disks are: $(get_dkdevs | sed
> 's/^$/none/')."
> @@ -3109,6 +3114,9 @@ __EOT
>         done
>
>          CRYPTOCHUNK=$_chunk
> +       # No volumes existed before asking, but we just created one.
> +       # Save it for later as sane root disk default.
> +       CRYPTOVOLUME=$(get_softraid_volumes)
>  }
>
>  do_install() {
> @@ -3581,6 +3589,7 @@ NIFS=0
>  export PS1="$MODE# "
>  PUB_KEY=/etc/signify/openbsd-${VERSION}-base.pub
>  CRYPTOCHUNK=
> +CRYPTOVOLUME=
>  ROOTDEV=
>  ROOTDISK=
>  SETDIR="$VNAME/$ARCH"
>
>

Reply via email to