xref: /openbsd/distrib/i386/common/install.md (revision 8529ddd3)
1#	$OpenBSD: install.md,v 1.61 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
36MDXDM=y
37NCPU=$(sysctl -n hw.ncpufound)
38
39((NCPU > 1)) && { DEFAULTSETS="bsd bsd.rd bsd.mp"; SANESETS="bsd bsd.mp"; }
40
41md_installboot() {
42	if ! installboot -r /mnt ${1}; then
43		echo "\nFailed to install bootblocks."
44		echo "You will not be able to boot OpenBSD from ${1}."
45		exit
46	fi
47}
48
49md_prep_fdisk() {
50	local _disk=$1 _q _d
51
52	while :; do
53		_d=whole
54		if [[ -n $(fdisk $_disk | grep 'Signature: 0xAA55') ]]; then
55			fdisk $_disk
56			if [[ -n $(fdisk $_disk | grep '^..: A6 ') ]]; then
57				_q=", use the (O)penBSD area,"
58				_d=OpenBSD
59			fi
60		else
61			echo "MBR has invalid signature; not showing it."
62		fi
63		ask "Use (W)hole disk$_q or (E)dit the MBR?" "$_d"
64		case $resp in
65		w*|W*)
66			echo -n "Setting OpenBSD MBR partition to whole $_disk..."
67			fdisk -e ${_disk} <<__EOT >/dev/null
68reinit
69update
70write
71quit
72__EOT
73			echo "done."
74			return ;;
75		e*|E*)
76			# Manually configure the MBR.
77			cat <<__EOT
78
79You will now create a single MBR partition to contain your OpenBSD data. This
80partition must have an id of 'A6'; must *NOT* overlap other partitions; and
81must be marked as the only active partition.  Inside the fdisk command, the
82'manual' command describes all the fdisk commands in detail.
83
84$(fdisk ${_disk})
85__EOT
86			fdisk -e ${_disk}
87			[[ -n $(fdisk $_disk | grep ' A6 ') ]] && return
88			echo No OpenBSD partition in MBR, try again. ;;
89		o*|O*)	return ;;
90		esac
91	done
92}
93
94md_prep_disklabel() {
95	local _disk=$1 _f _op
96
97	md_prep_fdisk $_disk
98
99	_f=/tmp/fstab.$_disk
100	if [[ $_disk == $ROOTDISK ]]; then
101		if $AUTO && get_disklabel_template; then
102			disklabel -T /disklabel.auto $FSTABFLAG $_f -w -A $_disk && return
103			echo "Autopartitioning failed"
104			exit 1
105		fi
106		while :; do
107			echo "The auto-allocated layout for $_disk is:"
108			disklabel -h -A $_disk | egrep "^#  |^  [a-p]:"
109			ask "Use (A)uto layout, (E)dit auto layout, or create (C)ustom layout?" a
110			case $resp in
111			a*|A*)	_op=-w ;;
112			e*|E*)	_op=-E ;;
113			c*|C*)	break ;;
114			*)	continue ;;
115			esac
116			disklabel $FSTABFLAG $_f $_op -A $_disk
117			return
118		done
119	fi
120
121	cat <<__EOT
122
123You will now create an OpenBSD disklabel inside the OpenBSD MBR
124partition. The disklabel defines how OpenBSD splits up the MBR partition
125into OpenBSD partitions in which filesystems and swap space are created.
126You must provide each filesystem's mountpoint in this program.
127
128The offsets used in the disklabel are ABSOLUTE, i.e. relative to the
129start of the disk, NOT the start of the OpenBSD MBR partition.
130
131__EOT
132
133	disklabel $FSTABFLAG $_f -E $_disk
134}
135
136md_congrats() {
137}
138
139md_consoleinfo() {
140	local _u _d=com
141
142	for _u in $(scan_dmesg "/^$_d\([0-9]\) .*/s//\1/p"); do
143		if [[ $_d$_u == $CONSOLE || -z $CONSOLE ]]; then
144			CDEV=$_d$_u
145			CPROM=com$_u
146			CTTY=tty0$_u
147			return
148		fi
149	done
150}
151