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