1# $OpenBSD: install.md,v 1.29 2020/12/09 15:45:58 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 34md_installboot() { 35 if ! installboot -r /mnt ${1}; then 36 echo "\nFailed to install bootblocks." 37 echo "You will not be able to boot OpenBSD from ${1}." 38 exit 39 fi 40 if [[ $(sysctl -n hw.product) = Gdium ]]; then 41 mount -t ext2fs /dev/${_disk}i /mnt2 42 mkdir -p /mnt2/boot 43 cp /mnt/bsd /mnt2/boot/bsd 44 umount /mnt2 45 fi 46} 47 48md_prep_fdisk() { 49 local _disk=$1 _q _d _s _o 50 51 while :; do 52 _d=whole 53 if disk_has $_disk mbr; then 54 fdisk $_disk 55 if disk_has $_disk mbr openbsd; then 56 _q=", use the (O)penBSD area" 57 _d=OpenBSD 58 fi 59 else 60 echo "MBR has invalid signature; not showing it." 61 fi 62 ask "Use (W)hole disk$_q or (E)dit the MBR?" "$_d" 63 case $resp in 64 [wW]*) 65 case $(sysctl -n hw.product) in 66 Gdium) 67 _s=32 68 _o="-O 1 -b 4096" 69 ;; 70 EBT700) 71 _s=1 72 _o="-O 1" 73 ;; 74 *) 75 _s=1 76 _o="" 77 ;; 78 esac 79 echo -n "Creating a ${_s}MB ext2 partition and an OpenBSD partition for rest of $_disk..." 80 fdisk -e $_disk <<__EOT >/dev/null 81re 82e 0 8383 84 851 86$((_s * 2048)) 87e 3 880 89e 3 90A6 91 92$((_s * 2048 + 1)) 93* 94update 95write 96quit 97__EOT 98 echo "done." 99 disklabel $_disk 2>/dev/null | grep -q "^ i:" || disklabel -w -d $_disk 100 newfs -qt ext2fs $_o ${_disk}i 101 break ;; 102 [eE]*) 103 # Manually configure the MBR. 104 cat <<__EOT 105 106You will now create one MBR partition to contain your OpenBSD data 107and one MBR partition to contain the program that PMON uses 108to boot OpenBSD. Neither partition will overlap any other partition. 109 110The OpenBSD MBR partition will have an id of 'A6' and the boot MBR 111partition will have an id of '83' (Linux files). The boot partition will be 112at least 1MB and be the first 'Linux files' partition on the disk. 113The installer assumes there is already an ext2 or ext3 filesystem on the 114first 'Linux files' partition. 115 116$(fdisk ${_disk}) 117__EOT 118 fdisk -e $_disk 119 disk_has $_disk mbr linux || 120 { echo "\nNo Linux files (id 83) partition!\n"; continue; } 121 disk_has $_disk mbr openbsd || 122 { echo "\nNo OpenBSD (id A6) partition!\n"; continue; } 123 disklabel $_disk 2>/dev/null | grep -q "^ i:" || disklabel -w -d $_disk 124 break ;; 125 [oO]*) 126 [[ $_d == OpenBSD ]] || continue 127 break ;; 128 esac 129 done 130 131} 132 133md_prep_disklabel() { 134 local _disk=$1 _f=/tmp/i/fstab.$1 135 136 md_prep_fdisk $_disk 137 138 disklabel_autolayout $_disk $_f || return 139 [[ -s $_f ]] && return 140 141 # Edit disklabel manually. 142 # Abandon all hope, ye who enter here. 143 disklabel -F $_f -E $_disk 144} 145 146md_congrats() { 147 cat <<__EOT 148 149Once the machine has rebooted use PMON to boot into OpenBSD, as 150described in the INSTALL.$ARCH document. 151To load the OpenBSD bootloader, use 'boot /dev/fs/ext2@wd0/boot/boot', 152where wd0 is the PMON name of the boot disk. 153 154__EOT 155} 156 157md_consoleinfo() { 158} 159