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