1# $OpenBSD: install.md,v 1.55 2017/07/28 18:15:44 rpe 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 34MDXAPERTURE=2 35MDXDM=y 36NCPU=$(sysctl -n hw.ncpufound) 37 38if dmesg | grep -q 'efifb0 at mainbus0'; then 39 MDEFI=y 40fi 41 42md_installboot() { 43 if ! installboot -r /mnt ${1}; then 44 echo "\nFailed to install bootblocks." 45 echo "You will not be able to boot OpenBSD from ${1}." 46 exit 47 fi 48} 49 50md_prep_fdisk() { 51 local _disk=$1 _q _d 52 53 while :; do 54 _d=whole 55 _q="Use (W)hole disk MBR, whole disk (G)PT" 56 57 [[ $MDEFI == y ]] && _d=gpt 58 59 if disk_has $_disk mbr || disk_has $_disk gpt; then 60 fdisk $_disk 61 if disk_has $_disk mbr openbsd || 62 disk_has $_disk gpt openbsd; then 63 _q="$_q, (O)penBSD area" 64 _d=OpenBSD 65 fi 66 else 67 echo "No valid MBR or GPT." 68 fi 69 70 ask "$_q or (E)dit?" "$_d" 71 case $resp in 72 [wW]*) 73 echo -n "Setting OpenBSD MBR partition to whole $_disk..." 74 fdisk -iy $_disk >/dev/null 75 echo "done." 76 return ;; 77 [gG]*) 78 if [[ $MDEFI != y ]]; then 79 ask_yn "An EFI/GPT disk may not boot. Proceed?" 80 [[ $resp == n ]] && continue 81 fi 82 83 echo -n "Setting OpenBSD GPT partition to whole $_disk..." 84 fdisk -iy -g -b 960 $_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 960 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 if [[ $_disk == $ROOTDISK ]] && disk_has $_disk gpt && 129 ! disk_has $_disk gpt efisys; then 130 echo "No EFI Sys partition in GPT, try again." 131 $AUTO && exit 1 132 continue 133 fi 134 return ;; 135 esac 136 done 137} 138 139md_prep_disklabel() { 140 local _disk=$1 _f=/tmp/i/fstab.$1 141 142 md_prep_fdisk $_disk 143 144 disklabel_autolayout $_disk $_f || return 145 [[ -s $_f ]] && return 146 147 # Edit disklabel manually. 148 # Abandon all hope, ye who enter here. 149 disklabel -F $_f -E $_disk 150} 151 152md_congrats() { 153} 154 155md_consoleinfo() { 156 local _u _d=com 157 158 for _u in $(scan_dmesg "/^$_d\([0-9]\) .*/s//\1/p"); do 159 if [[ $_d$_u == $CONSOLE || -z $CONSOLE ]]; then 160 CDEV=$_d$_u 161 CPROM=com$_u 162 CTTY=tty0$_u 163 return 164 fi 165 done 166} 167