1# $OpenBSD: install.md,v 1.57 2015/05/04 19:55:26 rpe 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 35MDXAPERTURE=2 36NCPU=$(sysctl -n hw.ncpufound) 37 38((NCPU > 1)) && { DEFAULTSETS="bsd bsd.rd bsd.mp"; SANESETS="bsd bsd.mp"; } 39 40md_installboot() { 41 local _disk=$1 42 43 # If there is an MSDOS partition on the boot disk, copy ofwboot 44 # into it. 45 if fdisk $_disk | grep -q 'Signature: 0xAA55'; then 46 if fdisk $_disk | grep -q '^..: 06 '; then 47 if mount /dev/${_disk}i /mnt2 >/dev/null 2>&1; then 48 # Use cat to avoid holes created by cp(1) 49 cat /mnt/usr/mdec/ofwboot > /mnt2/ofwboot 50 umount /mnt2 51 fi 52 fi 53 fi 54} 55 56md_has_hfs () { 57 pdisk -l /dev/$1c 2>&1 | grep -q "^Partition map " 58} 59 60md_has_hfs_openbsd () { 61 pdisk -l /dev/$1c 2>&1 | grep -q " OpenBSD OpenBSD " 62} 63 64md_prep_MBR() { 65 local _disk=$1 _q _d 66 67 if md_has_hfs $_disk; then 68 cat <<__EOT 69 70WARNING: putting an MBR partition table on $_disk will DESTROY the existing HFS 71 partitions and HFS partition table: 72$(pdisk -l /dev/${_disk}c) 73 74__EOT 75 ask_yn "Are you *sure* you want an MBR partition table on $_disk?" 76 [[ $resp == n ]] && return 1 77 fi 78 79 while :; do 80 _d=whole 81 if fdisk $_disk | grep -q 'Signature: 0xAA55'; then 82 fdisk $_disk 83 if fdisk $_disk | grep -q '^..: A6 '; then 84 _q=", use the (O)penBSD area," 85 _d=OpenBSD 86 fi 87 else 88 echo "MBR has invalid signature; not showing it." 89 fi 90 ask "Use (W)hole disk$_q or (E)dit the MBR?" "$_d" 91 case $resp in 92 w*|W*) 93 echo -n "Creating a 1MB DOS partition and an OpenBSD partition for rest of $_disk..." 94 dd if=/dev/zero of=/dev/r${_disk}c bs=1m count=1 95 fdisk -e $_disk <<__EOT >/dev/null 96reinit 97update 98write 99quit 100__EOT 101 echo "done." 102 break ;; 103 e*|E*) 104 # Manually configure the MBR. 105 cat <<__EOT 106 107You will now create one MBR partition to contain your OpenBSD data 108and one MBR partition to contain the program that Open Firmware uses 109to boot OpenBSD. Neither partition will overlap any other partition. 110 111The OpenBSD MBR partition will have an id of 'A6' and the boot MBR 112partition will have an id of '06' (DOS). The boot partition will be 113at least 1MB and be marked as the *only* active partition. 114 115$(fdisk $_disk) 116__EOT 117 fdisk -e $_disk 118 fdisk $_disk | grep -q '^..: 06 ' || \ 119 { echo "\nNo DOS (id 06) partition!\n"; continue; } 120 fdisk $_disk | grep -q '^\*.: 06 ' || \ 121 { echo "\nNo active DOS partition!\n"; continue; } 122 fdisk $_disk | grep -q "^..: A6 " || \ 123 { echo "\nNo OpenBSD (id A6) partition!\n"; continue; } 124 break ;; 125 o*|O*) break ;; 126 esac 127 done 128 129 disklabel $_disk 2>/dev/null | grep -q "^ i:" || disklabel -w -d $_disk 130 newfs -t msdos ${_disk}i 131} 132 133md_prep_HFS() { 134 local _disk=$1 _d _q 135 136 while :; do 137 _q= 138 _d=Modify 139 md_has_hfs_openbsd $_disk && \ 140 { _q="Use the (O)penBSD partition, "; _d=OpenBSD; } 141 pdisk -l /dev/${_disk}c 142 ask "$_q(M)odify a partition or (A)bort?" "$_d" 143 case $resp in 144 a*|A*) return 1 ;; 145 o*|O*) return 0 ;; 146 m*|M*) pdisk /dev/${_disk}c 147 md_has_hfs_openbsd $_disk && break 148 echo "\nNo 'OpenBSD'-type partition named 'OpenBSD'!" 149 esac 150 done 151 152 return 0; 153} 154 155md_prep_disklabel() { 156 local _disk=$1 _f _op 157 158 PARTTABLE= 159 while [[ -z $PARTTABLE ]]; do 160 resp=MBR 161 md_has_hfs $_disk && ask "Use HFS or MBR partition table?" HFS 162 case $resp in 163 m|mbr|M|MBR) 164 md_prep_MBR $_disk || continue 165 PARTTABLE=MBR 166 ;; 167 h|hfs|H|HFS) 168 md_prep_HFS $_disk || continue 169 PARTTABLE=HFS 170 ;; 171 esac 172 done 173 174 _f=/tmp/fstab.$_disk 175 if [[ $_disk == $ROOTDISK ]]; then 176 if $AUTO && get_disklabel_template; then 177 disklabel -T /disklabel.auto $FSTABFLAG $_f -w -A $_disk && return 178 echo "Autopartitioning failed" 179 exit 1 180 fi 181 while :; do 182 echo "The auto-allocated layout for $_disk is:" 183 disklabel -h -A $_disk | egrep "^# |^ [a-p]:" 184 ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a 185 case $resp in 186 a*|A*) _op=-w ;; 187 e*|E*) _op=-E ;; 188 c*|C*) break ;; 189 *) continue ;; 190 esac 191 disklabel $FSTABFLAG $_f $_op -A $_disk 192 return 193 done 194 fi 195 196 cat <<__EOT 197 198You will now create an OpenBSD disklabel inside the OpenBSD $PARTTABLE 199partition. The disklabel defines how OpenBSD splits up the $PARTTABLE partition 200into OpenBSD partitions in which filesystems and swap space are created. 201You must provide each filesystem's mountpoint in this program. 202 203The offsets used in the disklabel are ABSOLUTE, i.e. relative to the 204start of the disk, NOT the start of the OpenBSD $PARTTABLE partition. 205 206__EOT 207 208 disklabel $FSTABFLAG $_f -E $_disk 209} 210 211md_congrats() { 212 cat <<__EOT 213 214INSTALL.$ARCH describes how to configure Open Firmware to boot OpenBSD. The 215command to boot OpenBSD will be something like 'boot hd:,ofwboot /bsd'. 216__EOT 217 if [[ $PARTTABLE == HFS ]]; then 218 cat <<__EOT 219 220NOTE: You must use MacOS to copy 'ofwboot' from the OpenBSD install media to 221the first HFS partition of $ROOTDISK. 222__EOT 223 fi 224 225} 226 227md_consoleinfo() { 228 local _u _d=zstty 229 230 for _u in $(scan_dmesg "/^$_d\([0-9]\) .*/s//\1/p"); do 231 if [[ $_d$_u == $CONSOLE || -z $CONSOLE ]]; then 232 CDEV=$_d$_u 233 : ${CSPEED:=57600} 234 set -- a b c d e f g h i j 235 shift $_u 236 CTTY=tty$1 237 return 238 fi 239 done 240} 241