xref: /openbsd/distrib/amd64/common/install.md (revision fc61954a)
1#	$OpenBSD: install.md,v 1.53 2016/09/04 09:52:03 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
36MDXDM=y
37NCPU=$(sysctl -n hw.ncpufound)
38
39if dmesg | grep -q 'efifb0 at mainbus0'; then
40	MDEFI=y
41fi
42
43((NCPU > 1)) && { DEFAULTSETS="bsd bsd.rd bsd.mp"; SANESETS="bsd bsd.mp"; }
44
45md_installboot() {
46	if ! installboot -r /mnt ${1}; then
47		echo "\nFailed to install bootblocks."
48		echo "You will not be able to boot OpenBSD from ${1}."
49		exit
50	fi
51}
52
53md_prep_fdisk() {
54	local _disk=$1 _q _d
55
56	while :; do
57		_d=whole
58		_q="Use (W)hole disk MBR, whole disk (G)PT"
59
60		[[ $MDEFI == y ]] && _d=gpt
61
62		if disk_has $_disk mbr || disk_has $_disk gpt; then
63			fdisk $_disk
64			if disk_has $_disk mbr openbsd ||
65				disk_has $_disk gpt openbsd; then
66				_q="$_q, (O)penBSD area"
67				_d=OpenBSD
68			fi
69		else
70			echo "No valid MBR or GPT."
71		fi
72
73		ask "$_q or (E)dit?" "$_d"
74		case $resp in
75		[wW]*)
76			echo -n "Setting OpenBSD MBR partition to whole $_disk..."
77			fdisk -iy $_disk >/dev/null
78			echo "done."
79			return ;;
80		[gG]*)
81			if [[ $MDEFI != y ]]; then
82				ask_yn "An EFI/GPT disk may not boot. Proceed?"
83				[[ $resp == n ]] && continue
84			fi
85
86			echo -n "Setting OpenBSD GPT partition to whole $_disk..."
87			fdisk -iy -g -b 960 $_disk >/dev/null
88			echo "done."
89			return ;;
90		[eE]*)
91			if disk_has $_disk gpt; then
92				# Manually configure the GPT.
93				cat <<__EOT
94
95You will now create two GPT partitions. The first must have an id
96of 'EF' and be large enough to contain the OpenBSD boot programs,
97at least 960 blocks. The second must have an id of 'A6' and will
98contain your OpenBSD data. Neither may overlap other partitions.
99Inside the fdisk command, the 'manual' command describes the fdisk
100commands in detail.
101
102$(fdisk $_disk)
103__EOT
104				fdisk -e $_disk
105
106				if ! disk_has $_disk gpt openbsd; then
107					echo -n "No OpenBSD partition in GPT,"
108				elif ! disk_has $_disk gpt efisys; then
109					echo -n "No EFI Sys partition in GPT,"
110				else
111					return
112				fi
113			else
114				# Manually configure the MBR.
115				cat <<__EOT
116
117You will now create a single MBR partition to contain your OpenBSD data. This
118partition must have an id of 'A6'; must *NOT* overlap other partitions; and
119must be marked as the only active partition.  Inside the fdisk command, the
120'manual' command describes all the fdisk commands in detail.
121
122$(fdisk $_disk)
123__EOT
124				fdisk -e $_disk
125				disk_has $_disk mbr openbsd && return
126				echo -n "No OpenBSD partition in MBR,"
127			fi
128			echo "try again." ;;
129		[oO]*)
130			[[ $_d == OpenBSD ]] || continue
131			if [[ $_disk == $ROOTDISK ]] && disk_has $_disk gpt &&
132				! disk_has $_disk gpt efisys; then
133				echo "No EFI Sys partition in GPT, try again."
134				$AUTO && exit 1
135				continue
136			fi
137			return ;;
138		esac
139	done
140}
141
142md_prep_disklabel() {
143	local _disk=$1 _f=/tmp/i/fstab.$1
144
145	md_prep_fdisk $_disk
146
147	disklabel_autolayout $_disk $_f || return
148	[[ -s $_f ]] && return
149
150	# Edit disklabel manually.
151	# Abandon all hope, ye who enter here.
152	disklabel -F $_f -E $_disk
153}
154
155md_congrats() {
156}
157
158md_consoleinfo() {
159	local _u _d=com
160
161	for _u in $(scan_dmesg "/^$_d\([0-9]\) .*/s//\1/p"); do
162		if [[ $_d$_u == $CONSOLE || -z $CONSOLE ]]; then
163			CDEV=$_d$_u
164			CPROM=com$_u
165			CTTY=tty0$_u
166			return
167		fi
168	done
169}
170