install.md revision 1.2
1#	$OpenBSD: install.md,v 1.2 2021/06/18 20:58:16 deraadt 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
35NEWFSARGS_msdos="-F 16 -L boot"
36MOUNT_ARGS_msdos="-o-l"
37
38md_installboot() {
39	local _disk=/dev/$1
40
41	mount ${MOUNT_ARGS_msdos} ${_disk}i /mnt/mnt
42	mkdir -p /mnt/mnt/efi/boot
43	cp /mnt/usr/mdec/BOOTRISCV64.EFI /mnt/mnt/efi/boot/bootriscv64.efi
44	echo bootriscv64.efi > /mnt/mnt/efi/boot/startup.nsh
45}
46
47md_prep_fdisk() {
48	local _disk=$1 _d
49
50	local bootparttype="C"
51	local bootsectorstart="32768"
52	local bootsectorsize="32768"
53	local bootsectorend=$(($bootsectorstart + $bootsectorsize))
54	local bootfstype="msdos"
55	local newfs_args=${NEWFSARGS_msdos}
56
57	while :; do
58		_d=whole
59		if disk_has $_disk mbr; then
60			fdisk $_disk
61		else
62			echo "MBR has invalid signature; not showing it."
63		fi
64		ask "Use (W)hole disk or (E)dit the MBR?" "$_d"
65		case $resp in
66		[wW]*)
67			echo -n "Creating a ${bootfstype} partition and an OpenBSD partition for rest of $_disk..."
68			fdisk -e ${_disk} <<__EOT >/dev/null
69reinit
70e 0
71${bootparttype}
72n
73${bootsectorstart}
74${bootsectorsize}
75f 0
76e 3
77A6
78n
79${bootsectorend}
80
81write
82quit
83__EOT
84			echo "done."
85			disklabel $_disk 2>/dev/null | grep -q "^  i:" || disklabel -w -d $_disk
86			newfs -t ${bootfstype} ${newfs_args} ${_disk}i
87			return ;;
88		[eE]*)
89			# Manually configure the MBR.
90			cat <<__EOT
91
92You will now create one MBR partition to contain your OpenBSD data
93and one MBR partition on which the OpenBSD boot program is located.
94Neither partition will overlap any other partition.
95
96The OpenBSD MBR partition will have an id of 'A6' and the boot MBR
97partition will have an id of '${bootparttype}' (${bootfstype}).
98The boot partition will be at least 16MB and be the first 'MSDOS'
99partition on the disk.
100
101$(fdisk ${_disk})
102__EOT
103			fdisk -e ${_disk}
104			disk_has $_disk mbr openbsd && return
105			echo No OpenBSD partition in MBR, try again. ;;
106		esac
107	done
108}
109
110md_prep_disklabel() {
111	local _disk=$1 _f=/tmp/i/fstab.$1
112
113	md_prep_fdisk $_disk
114
115	disklabel_autolayout $_disk $_f || return
116	[[ -s $_f ]] && return
117
118	# Edit disklabel manually.
119	# Abandon all hope, ye who enter here.
120	disklabel -F $_f -E $_disk
121}
122
123md_congrats() {
124}
125
126md_consoleinfo() {
127	CTTY=console
128	DEFCONS=y
129	case $CSPEED in
130	9600|19200|38400|57600|115200|1500000)
131		;;
132	*)
133		CSPEED=115200;;
134	esac
135}
136