From: Klemens Nanni Subject: installer: default root disk: prefer those bigger than 1G To: OpenBSD tech Date: Thu, 1 May 2025 15:41:25 +0000 Now we show all valid root disks and pick the first one, i.e. the alphanumerically lowest value, as default: Available disks are: sd0 sd1. Which disk is the root disk? ('?' for details) [sd0] ? sd0: VirtIO, Block Device (0.8G) sd1: VirtIO, Block Device (3.0G) Available disks are: sd0 sd1. Which disk is the root disk? ('?' for details) [sd0] Finding the "best" disk as default is hard, but I reckon we can prefer some disks more than others; the example above is from a common test routine of mine: # vmctl start -d install77.img -d disk.img ... But whenever install media, small USB sticks or softraid(4) keydisks attach before you actual disk, defaulting to sd0 is most certainly not what you want. An easy rule of thumb that works great for me is to reshuffle the list of valid root disks such that small ones come last. This is easy to code and cannot break anything, so now you get: Which disk is the root disk? ('?' for details) [sd1] Do this only on install so upgrade behaviour for tiny root disks with big data disks remains unchanged. NB: _default is an odd name as the variable holds a list of devices. _ask() gets them, takes its first and second argument as question as default answer, respectively, and ignores the rest. But further the variable is treated as list, exactly the same way I do upfront now, so better call it _rootdisks. Feedback? OK? Index: install.sub =================================================================== RCS file: /cvs/src/distrib/miniroot/install.sub,v diff -u -p -r1.1269 install.sub --- install.sub 6 Apr 2025 11:54:36 -0000 1.1269 +++ install.sub 1 May 2025 15:37:04 -0000 @@ -262,7 +262,7 @@ dmesgtail() { # Device related functions # ------------------------------------------------------------------------------ -# Show device name, info, NAA and size for the provided list of disk devices. +# Show device name, info, NAA and size in gigabytes for the provided disks. # Create device nodes as needed and cleanup afterwards. diskinfo() { local _d _i _n _s @@ -2429,12 +2429,22 @@ is_rootdisk() { # Get global root information. ie. ROOTDISK, ROOTDEV and SWAPDEV. get_rootinfo() { - local _default=$(get_dkdevs_root) _dkdev + local _rootdisks=$(get_dkdevs_root) _dkdev local _q="Which disk is the root disk? ('?' for details)" + + if [[ $MODE == install ]]; then + # Prefer disks bigger than 1G as small ones tend to be install + # media, softraid(4) key disks or tiny USB sticks or SD cards. + for _dkdev in $_rootdisks; do + diskinfo $_dkdev | grep -q '(0\..*G)$' && + _rootdisks="$(rmel "$_dkdev" $_rootdisks) $_dkdev" + done + fi + while :; do echo "Available disks are: $(get_dkdevs_root | sed 's/^$/none/')." - _ask "$_q" $_default || continue + _ask "$_q" $_rootdisks || continue case $resp in "?") diskinfo $(get_dkdevs);; '') ;;