1# $OpenBSD: install.md,v 1.3 2001/10/08 17:40:40 drahn Exp $ 2# 3# 4# Copyright rc) 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# 3. All advertising materials mentioning features or use of this software 19# must display the following acknowledgement: 20# This product includes software developed by the NetBSD 21# Foundation, Inc. and its contributors. 22# 4. Neither the name of The NetBSD Foundation nor the names of its 23# contributors may be used to endorse or promote products derived 24# from this software without specific prior written permission. 25# 26# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE 30# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36# POSSIBILITY OF SUCH DAMAGE. 37# 38 39# 40# machine dependent section of installation/upgrade script. 41# 42 43# Machine-dependent install sets 44MDSETS="kernel" 45ARCH=ARCH 46 47md_set_term() { 48 test -n "$TERM" && return 49 echo -n "Specify terminal type [vt220]: " 50 getresp vt220 51 TERM=$resp 52 export TERM 53} 54 55md_get_diskdevs() { 56 # return available disk devices 57 bsort `dmesg | egrep -a "^[sw]d[0-9]+ " | cutword 1` 58} 59 60md_get_cddevs() { 61 # return available CDROM devices 62 bsort `dmesg | egrep -a "^cd[0-9]+ " | cutword 1` 63} 64 65md_get_partition_range() { 66 # return range of valid partition letters 67 echo [a-p] 68} 69 70md_questions() { 71 : 72} 73 74md_installboot() { 75 if [[ $disklabeltype = "HFS" ]] 76 then 77 echo "the 'ofwboot' program needs to be copied to the first HFS partition" 78 echo "of the disk to allow booting of OpenBSD" 79 elif [[ $disklabeltype = "MBR" ]] 80 then 81 echo "Installing boot in the msdos partition /dev/${1}i" 82 if mount -t msdos /dev/${1}i /mnt2 ; then 83 cp /usr/mdec/ofwboot /mnt2 84 umount /mnt2 85 else 86 echo "Failed, you will not be able to boot from /dev/${1}." 87 fi 88 fi 89} 90 91md_native_fstype() { 92 echo "msdos" 93} 94 95md_native_fsopts() { 96 echo "ro" 97} 98 99md_init_mbr() { 100 # $1 is the disk to init 101 echo 102 echo "You will now be asked if you want to initialize the disk with a 1MB" 103 echo "MSDOS partition. This is the recomended setup and will allow you to" 104 echo "store the boot and other interesting things here." 105 echo 106 echo "If you want to have a different setup, exit 'install' now and do" 107 echo "the MBR initialization by hand using the 'fdisk' program." 108 echo 109 echo "If you choose to manually setup the MSDOS partition, " 110 echo "consult your PowerPC OpenFirmware manual -and- the" 111 echo "PowerPC OpenBSD Installation Guide for doing setup this way." 112 echo 113 echo -n "Do you want to init the MBR and the MSDOS partition? [y] " 114 getresp "y" 115 case "$resp" in 116 n*|N*) 117 exit 0;; 118 *) 119 echo 120 echo "An MBR record with an OpenBSD usable partition table will now be copied" 121 echo "to your disk. Unless you have special requirements you will not need" 122 echo "to edit this MBR. After the MBR is copied an empty 1MB MSDOS partition" 123 echo "will be created on the disk. You *MUST* setup the OpenBSD disklabel" 124 echo "to have a partition include this MSDOS partition." 125 echo "You will have an opportunity to do this shortly." 126 echo 127 echo "You will probably see a few '...: no disk label' messages" 128 echo "It's completely normal. The disk has no label yet." 129 echo "This will take a minute or two..." 130 sleep 2 131 echo -n "Creating Master Boot Record (MBR)..." 132 fdisk -i -f /usr/mdec/mbr $1 133 echo "..done." 134 echo -n "Copying 1MB MSDOS partition to disk..." 135 gunzip < /usr/mdec/msdos1mb.gz | dd of=/dev/r$1c bs=512 seek=1 >/dev/null 2>&1 136 echo "..done." 137 ;; 138 esac 139} 140 141md_init_hfs() { 142 pdisk /dev/${1}c 143} 144md_checkfordisklabel() { 145 # $1 is the disk to check 146 local rval 147 148 echo 149 echo "Apple systems have two methods to label/partition a boot disk." 150 echo "Either the disk can be partitioned with Apple HFS partition" 151 echo "tools to contain an \"Unused\" partition, or without any" 152 echo "MacOS tools, the disk can be labled using an MBR partition table" 153 echo "If the HFS (DPME) partition table is used, after the disk is" 154 echo "partitioned with the Apple software, the \"Unused\" section" 155 echo "must be changed to type \"OpenBSD\" name \"OpenBSD\" using the" 156 echo "pdisk tool contained on this ramdisk. The disklabel can" 157 echo "then be edited normally" 158 echo "WARNING: the MBR partitioning code will HAPPILY overwrite/destroy" 159 echo "any HFS partitions on the disk, including the partition table." 160 echo "Choose the MBR option carefully, knowing this fact." 161 162 echo -n "Do you want to choose (H)FS labeling or (M)BR labeling [H] " 163 getresp "h" 164 case "$resp" in 165 m*|M*) 166 export disklabeltype=MBR 167 md_checkforMBRdisklabel $1 168 rval=$? 169 ;; 170 *) 171 export disklabeltype=HFS 172 md_init_hfs $1 173 rval=$? 174 ;; 175 esac 176 return $rval 177} 178md_checkforMBRdisklabel() { 179 180 echo "You have chosen to put a MBR disklabel on the disk." 181 echo -n "Is this correct? [n] " 182 getresp "n" 183 case "$resp" in 184 n*|N*) 185 echo "aborting install" 186 exit 0;; 187 *) 188 ;; 189 esac 190 191 echo -n "Have you initialized an MSDOS partition using OpenFirmware? [n] " 192 getresp "n" 193 case "$resp" in 194 n*|N*) 195 md_init_mbr $1;; 196 *) 197 echo 198 echo "You may keep your current setup if you want to be able to use any" 199 echo "already loaded OS. However you will be asked to prepare an empty" 200 echo "partition for OpenBSD later. There must also be at least ~0.5MB free space" 201 echo "in the boot partition to hold the OpenBSD bootloader." 202 echo 203 echo "Also note that the boot partition must be included as partition" 204 echo "'i' in the OpenBSD disklabel." 205 echo 206 echo -n "Do you want to keep the current MSDOS partition setup? [y]" 207 getresp "y" 208 case "$resp" in 209 n*|N*) 210 md_init_mbr $1;; 211 *) 212 ;; 213 esac 214 ;; 215 esac 216 217 disklabel -r $1 > /dev/null 2> /tmp/checkfordisklabel 218 if grep "no disk label" /tmp/checkfordisklabel; then 219 rval=1 220 elif grep "disk label corrupted" /tmp/checkfordisklabel; then 221 rval=2 222 else 223 rval=0 224 fi 225 226 rm -f /tmp/checkfordisklabel 227 return $rval 228} 229 230md_prep_fdisk() 231{ 232 local _disk 233 local _done 234 235 _disk=$1 236 echo 237 echo "This disk has not previously been used with OpenBSD. You may share" 238 echo "this disk with other operating systems. However, to be able to boot" 239 echo "the system you will need a small DOS partition in the beginning of" 240 echo "the disk to hold the kernel boot. OpenFirmware understands" 241 echo "how to read an MSDOS style format from the disk." 242 echo 243 echo "This DOS style partitioning has been taken care of if" 244 echo "you chose to do that initialization earlier in the install." 245 echo 246 echo "WARNING: Wrong information in the BIOS partition table might" 247 echo "render the disk unusable." 248 249 echo -n "Press [Enter] to continue " 250 getresp "" 251 252 echo 253 echo "Current partition information is:" 254 fdisk ${_disk} 255 echo -n "Press [Enter] to continue " 256 getresp "" 257 258 _done=0 259 while [ $_done = 0 ]; do 260 echo 261 cat << \__md_prep_fdisk_1 262 263An OpenBSD partition should have type (i.d.) of 166 (A6), and should be the 264only partition marked as active. Also make sure that the size of the partition 265to be used by OpenBSD is correct, otherwise OpenBSD disklabel installation 266will fail. Furthermore, the partitions must NOT overlap each others. 267 268The fdisk utility will be started update mode (interactive.) 269You will be able to add / modify this information as needed. 270If you make a mistake, simply exit fdisk without storing the new 271information, and you will be allowed to start over. 272__md_prep_fdisk_1 273 echo 274 echo -n "Press [Enter] to continue " 275 getresp "" 276 277 fdisk -e ${_disk} 278 279 echo 280 echo "The new partition information is:" 281 fdisk ${_disk} 282 283 echo 284 echo "(You will be permitted to edit this information again.)" 285 echo "-------------------------------------------------------" 286 echo -n "Is the above information correct? [n] " 287 getresp "n" 288 289 case "$resp" in 290 n*|N*) ;; 291 *) _done=1 ;; 292 esac 293 done 294 295 echo 296 echo "Please take note of the offset and size of the OpenBSD partition" 297 echo "*AND* the MSDOS partitions you may want to access from OpenBSD." 298 echo "At least the MSDOS partition used for booting must be accessible" 299 echo "by OpenBSD as partition 'i'. You may need this information to " 300 echo "fill in the OpenBSD disk label later." 301 echo -n "Press [Enter] to continue " 302 getresp "" 303} 304 305md_prep_disklabel() 306{ 307 local _disk 308 309 _disk=$1 310 md_checkfordisklabel $_disk 311 case $? in 312 0) 313 echo -n "Do you wish to edit the disklabel on $_disk? [y] " 314 ;; 315 1) 316 md_prep_fdisk ${_disk} 317 echo "WARNING: Disk $_disk has no label" 318 echo -n "Do you want to create one with the disklabel editor? [y] " 319 ;; 320 2) 321 echo "WARNING: Label on disk $_disk is corrupted" 322 echo -n "Do you want to try and repair the damage using the disklabel editor? [y] " 323 ;; 324 325 esac 326 327 getresp "y" 328 case "$resp" in 329 y*|Y*) ;; 330 *) return ;; 331 esac 332 333 # display example 334 cat << \__md_prep_disklabel_1 335 336Disk partition sizes and offsets are in sector (most likely 512 bytes) units. 337You may set these size/offset pairs on cylinder boundaries 338 (the number of sector per cylinder is given in ) 339 (the `sectors/cylinder' entry, which is not shown here) 340Also, you *must* make sure that the 'i' partition points at the MSDOS 341partition that will be used for booting. The 'c' partition shall start 342at offset 0 and include the entire disk. This is most likely correct when 343you see the default label in the editor. 344 345Do not change any parameters except the partition layout and the label name. 346 347 [Here is an example of what the partition information may look like.] 34810 partitions: 349# size offset fstype [fsize bsize cpg] 350 a: 120832 10240 4.2BSD 1024 8192 16 # (Cyl. 11*- 142*) 351 b: 131072 131072 swap # (Cyl. 142*- 284*) 352 c: 6265200 0 unused 1024 8192 # (Cyl. 0 - 6809) 353 e: 781250 262144 4.2BSD 1024 8192 16 # (Cyl. 284*- 1134*) 354 f: 1205000 1043394 4.2BSD 1024 8192 16 # (Cyl. 1134*- 2443*) 355 g: 2008403 2248394 4.2BSD 1024 8192 16 # (Cyl. 2443*- 4626*) 356 h: 2008403 4256797 4.2BSD 1024 8192 16 # (Cyl. 4626*- 6809*) 357 i: 10208 32 MSDOS # (Cyl. 0*- 11*) 358[End of example] 359__md_prep_disklabel_1 360 echo -n "Press [Enter] to continue " 361 getresp "" 362 if [[ $disklabeltype = "HFS" ]] 363 then 364 disklabel -c -f /tmp/fstab.${_disk} -E ${_disk} 365 elif [[ $disklabeltype = "MBR" ]] 366 then 367 disklabel -W ${_disk} 368 disklabel ${_disk} >/tmp/label.$$ 369 disklabel -r -R ${_disk} /tmp/label.$$ 370 rm -f /tmp/label.$$ 371 disklabel -f /tmp/fstab.${_disk} -E ${_disk} 372 else 373 echo "unknown disk label type" 374 fi 375} 376 377md_welcome_banner() { 378{ 379 if [ "$MODE" = install ]; then 380 cat << __EOT 381Welcome to the OpenBSD/macppc ${VERSION_MAJOR}.${VERSION_MINOR} installation program. 382 383This program is designed to help you put OpenBSD on your disk in a simple and 384rational way. 385__EOT 386 387 else 388 cat << __EOT 389Welcome to the OpenBSD/macppc ${VERSION_MAJOR}.${VERSION_MINOR} upgrade program. 390 391This program is designed to help you upgrade your OpenBSD system in a simple 392and rational way. As a reminder, installing the 'etc' binary set is NOT 393recommended. Once the rest of your system has been upgraded, you should 394manually merge any changes to files in the 'etc' set into those files which 395already exist on your system. 396 397__EOT 398 fi 399 400cat << __EOT 401 402As with anything which modifies your disk's contents, this program can cause 403SIGNIFICANT data loss, and you are advised to make sure your data is backed 404up before beginning the installation process. 405 406Default answers are displayed in brackets after the questions. You can hit 407Control-C at any time to quit, but if you do so at a prompt, you may have 408to hit return. Also, quitting in the middle of installation may leave your 409system in an inconsistent state. If you hit Control-C and restart the 410install, the install program will remember many of your old answers. 411 412__EOT 413} | more 414} 415 416md_not_going_to_install() { 417 cat << __EOT 418 419OK, then. Enter 'reboot' at the prompt to reset the machine. Once the machine 420has rebooted, use Open Firmware to load the new boot code. 421 422__EOT 423} 424 425md_congrats() { 426 local what; 427 if [ "$MODE" = install ]; then 428 what=installed 429 else 430 what=upgraded 431 fi 432 cat << __EOT 433 434CONGRATULATIONS! You have successfully $what OpenBSD! To boot the 435installed system, enter reboot at the command prompt. Once the machine 436has rebooted, use Open Firmware to boot into OpenBSD. 437 438__EOT 439} 440