xref: /openbsd/distrib/macppc/ramdisk/install.md (revision e5dd7070)
1#	$OpenBSD: install.md,v 1.73 2020/06/27 15:35:29 deraadt 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
38md_installboot() {
39	if ! installboot -r /mnt ${1}; then
40		echo "\nFailed to install bootblocks."
41		echo "You will not be able to boot OpenBSD from ${1}."
42		exit
43	fi
44}
45
46md_prep_MBR() {
47	local _disk=$1 _q _d
48
49	if disk_has $_disk hfs; then
50		cat <<__EOT
51
52WARNING: Putting an MBR partition table on $_disk will DESTROY the existing HFS
53         partitions and HFS partition table:
54$(pdisk -l $_disk)
55
56__EOT
57		ask_yn "Are you *sure* you want an MBR partition table on $_disk?"
58		[[ $resp == n ]] && return 1
59	fi
60
61	while :; do
62		_d=whole
63
64		if disk_has $_disk mbr; then
65			fdisk $_disk
66			if disk_has $_disk mbr openbsd; then
67				_q=", use the (O)penBSD area"
68				_d=OpenBSD
69			fi
70		else
71			echo "MBR has invalid signature; not showing it."
72		fi
73		ask "Use (W)hole disk$_q or (E)dit the MBR?" "$_d"
74		case $resp in
75		[wW]*)
76			echo -n "Creating a 1MB DOS partition and an OpenBSD partition for rest of $_disk..."
77			dd if=/dev/zero of=/dev/r${_disk}c bs=1m count=1
78			fdisk -iy $_disk >/dev/null
79			echo "done."
80			break ;;
81		[eE]*)
82			# Manually configure the MBR.
83			cat <<__EOT
84
85You will now create one MBR partition to contain your OpenBSD data
86and one MBR partition to contain the program that Open Firmware uses
87to boot OpenBSD. Neither partition will overlap any other partition.
88
89The OpenBSD MBR partition will have an id of 'A6' and the boot MBR
90partition will have an id of '06' (DOS). The boot partition will be
91at least 1MB and be marked as the *only* active partition.
92
93$(fdisk $_disk)
94__EOT
95			fdisk -e $_disk
96			disk_has $_disk mbr dos ||
97				{ echo "\nNo DOS (id 06) partition!\n"; continue; }
98			disk_has $_disk mbr dos_active ||
99				{ echo "\nNo active DOS partition!\n"; continue; }
100			disk_has $_disk mbr openbsd ||
101				{ echo "\nNo OpenBSD (id A6) partition!\n"; continue; }
102			break ;;
103		[oO]*)
104			[[ $_d == OpenBSD ]] || continue
105			break ;;
106		esac
107	done
108
109	disklabel $_disk 2>/dev/null | grep -q "^  i:" || disklabel -w -d $_disk
110	newfs -t msdos ${_disk}i
111}
112
113md_prep_HFS() {
114	local _disk=$1 _d _q
115
116	while :; do
117		_q=
118		_d=Modify
119		disk_has $_disk hfs openbsd &&
120			{ _q="Use the (O)penBSD partition, "; _d=OpenBSD; }
121		pdisk -l $_disk
122		ask "$_q(M)odify a partition or (A)bort?" "$_d"
123		case $resp in
124		[aA]*)	return 1 ;;
125		[oO]*)	return 0 ;;
126		[mM]*)	pdisk $_disk
127			disk_has $_disk hfs openbsd && break
128			echo "\nNo 'OpenBSD'-type partition named 'OpenBSD'!"
129		esac
130	done
131
132	return 0;
133}
134
135md_prep_disklabel() {
136	local _disk=$1 _f=/tmp/i/fstab.$1
137
138	PARTTABLE=
139	while [[ -z $PARTTABLE ]]; do
140		resp=MBR
141		disk_has $_disk hfs && ask "Use HFS or MBR partition table?" MBR
142		case $resp in
143		[mM]*)	md_prep_MBR $_disk && PARTTABLE=MBR ;;
144		[hH]*)	md_prep_HFS $_disk && PARTTABLE=HFS ;;
145		esac
146	done
147
148	disklabel_autolayout $_disk $_f || return
149	[[ -s $_f ]] && return
150
151	# Edit disklabel manually.
152	# Abandon all hope, ye who enter here.
153	disklabel -F $_f -E $_disk
154}
155
156md_congrats() {
157	cat <<__EOT
158
159INSTALL.$ARCH describes how to configure Open Firmware to boot OpenBSD. The
160command to boot OpenBSD will be something like 'boot hd:,ofwboot /bsd'.
161__EOT
162	if [[ $PARTTABLE == HFS ]]; then
163		cat <<__EOT
164
165NOTE: You must use MacOS to copy 'ofwboot' from the OpenBSD install media to
166the first HFS partition of $ROOTDISK.
167__EOT
168	fi
169
170}
171
172md_consoleinfo() {
173	local _u _d=zstty
174
175	for _u in $(scan_dmesg "/^$_d\([0-9]\) .*/s//\1/p"); do
176		if [[ $_d$_u == $CONSOLE || -z $CONSOLE ]]; then
177			CDEV=$_d$_u
178			: ${CSPEED:=57600}
179			set -- a b c d e f g h i j
180			shift $_u
181			CTTY=tty$1
182			return
183		fi
184	done
185}
186