1# $OpenBSD: install.md,v 1.10 2023/10/11 17:53:52 kn Exp $ 2# 3# 4# Copyright (c) 1996 The NetBSD Foundation, Inc. 5# All rights reserved. 6# 7# This code is derived from software contributed to The NetBSD Foundation 8# by Jason R. Thorpe. 9# 10# Redistribution and use in source and binary forms, with or without 11# modification, are permitted provided that the following conditions 12# are met: 13# 1. Redistributions of source code must retain the above copyright 14# notice, this list of conditions and the following disclaimer. 15# 2. Redistributions in binary form must reproduce the above copyright 16# notice, this list of conditions and the following disclaimer in the 17# documentation and/or other materials provided with the distribution. 18# 19# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 23# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29# POSSIBILITY OF SUCH DAMAGE. 30# 31# 32# machine dependent section of installation/upgrade script. 33# 34 35MDBOOTSR=y 36NCPU=$(sysctl -n hw.ncpufound) 37 38md_installboot() { 39 if ! installboot -r /mnt ${1}; then 40 echo "\nFailed to install bootblocks." 41 echo "You will not be able to boot OpenBSD from ${1}." 42 exit 43 fi 44} 45 46md_prep_fdisk() { 47 local _disk=$1 _d _type=MBR 48 49 local bootpart= 50 local bootparttype="C" 51 local bootsectorstart="32768" 52 local bootsectorsize="32768" 53 local bootfstype="msdos" 54 55 while :; do 56 _d=whole 57 if disk_has $_disk gpt; then 58 # Is this a boot disk? 59 [[ $_disk == $ROOTDISK ]] && bootpart="-b ${bootsectorsize}" 60 _type=GPT 61 fdisk $_disk 62 elif disk_has $_disk mbr; then 63 fdisk $_disk 64 else 65 echo "MBR has invalid signature; not showing it." 66 fi 67 ask "Use (W)hole disk or (E)dit the ${_type}?" "$_d" 68 case $resp in 69 [wW]*) 70 echo -n "Creating a ${bootfstype} partition and an OpenBSD partition for rest of $_disk..." 71 if disk_has $_disk gpt biosboot; then 72 # Preserve BIOS boot partition as it might 73 # contain a PolarFire SoC HSS payload. 74 fdisk -Ay ${bootpart} ${_disk} >/dev/null 75 elif disk_has $_disk gpt; then 76 fdisk -gy ${bootpart} ${_disk} >/dev/null 77 else 78 fdisk -iy -b "${bootsectorsize}@${bootsectorstart}:${bootparttype}" ${_disk} >/dev/null 79 fi 80 echo "done." 81 installboot -p $_disk 82 return ;; 83 [eE]*) 84 if disk_has $_disk gpt; then 85 # Manually configure the GPT. 86 cat <<__EOT 87 88You will now create two GPT partitions. The first must have an id 89of 'EF' and be large enough to contain the OpenBSD boot programs, 90at least 32768 blocks. The second must have an id of 'A6' and will 91contain your OpenBSD data. Neither may overlap other partitions. 92Inside the fdisk command, the 'manual' command describes the fdisk 93commands in detail. 94 95$(fdisk $_disk) 96__EOT 97 fdisk -e $_disk 98 99 if ! disk_has $_disk gpt openbsd; then 100 echo -n "No OpenBSD partition in GPT," 101 elif ! disk_has $_disk gpt efisys; then 102 echo -n "No EFI Sys partition in GPT," 103 else 104 return 105 fi 106 else 107 # Manually configure the MBR. 108 cat <<__EOT 109 110You will now create one MBR partition to contain your OpenBSD data 111and one MBR partition on which the OpenBSD boot program is located. 112Neither partition will overlap any other partition. 113 114The OpenBSD MBR partition will have an id of 'A6' and the boot MBR 115partition will have an id of '${bootparttype}' (${bootfstype}). 116The boot partition will be at least 16MB and be the first 'MSDOS' 117partition on the disk. 118 119$(fdisk ${_disk}) 120__EOT 121 fdisk -e ${_disk} 122 disk_has $_disk mbr openbsd && return 123 echo -n "No OpenBSD partition in MBR," 124 fi 125 echo " try again." ;; 126 esac 127 done 128} 129 130md_prep_disklabel() { 131 local _disk=$1 _f=/tmp/i/fstab.$1 132 133 md_prep_fdisk $_disk 134 135 disklabel_autolayout $_disk $_f || return 136 [[ -s $_f ]] && return 137 138 # Edit disklabel manually. 139 # Abandon all hope, ye who enter here. 140 disklabel -F $_f -E $_disk 141} 142 143md_congrats() { 144} 145 146md_consoleinfo() { 147 CTTY=console 148 DEFCONS=y 149 case $CSPEED in 150 9600|19200|38400|57600|115200|1500000) 151 ;; 152 *) 153 CSPEED=115200;; 154 esac 155} 156