1# $NetBSD: install.md,v 1.35 2022/05/28 21:57:39 andvar Exp $ 2# 3# 4# Copyright (c) 1996,2006 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 FOUNDATION OR CONTRIBUTORS 23# BE 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# 33# machine dependent section of installation/upgrade script. 34# 35 36# Machine-dependent install sets 37MDSETS="kern-GENERIC xbase xcomp xetc xfont xserver" 38 39md_set_term() { 40 if [ ! -z "$TERM" ]; then 41 return 42 fi 43 echo -n "Specify terminal type [vt220]: " 44 getresp "vt220" 45 TERM="$resp" 46 export TERM 47} 48 49md_makerootwritable() { 50 # Mount root rw for convenience of the tester ;-) 51 if ! cp /dev/null /tmp/.root_writable >/dev/null 2>&1; then 52 mi_mount_kernfs 53 mount -t ffs -u /kern/rootdev / > /dev/null 2>&1 54 fi 55} 56 57md_get_diskdevs() { 58 # return available disk devices 59 mi_mount_kernfs 60 mi_filter_msgbuf | sed -ne '/^[sw]d[0-9] /s/ .*//p' 61} 62 63md_get_cddevs() { 64 # return available CDROM devices 65 mi_mount_kernfs 66 mi_filter_msgbuf | sed -ne '/^cd[0-9] /s/ .*//p' 67} 68 69md_get_partition_range() { 70 # return an expression describing the valid partition id's 71 echo '[a-p]' 72} 73 74md_installboot() { 75 if [ -x /mnt/usr/sbin/installboot ]; then 76 echo -n "Should a boot block be installed? [y] " 77 getresp "y" 78 case "$resp" in 79 y*|Y*) 80 echo -n "Boot command? [netbsd -ASn2] " 81 getresp "netbsd -ASn2" 82 echo "Installing boot block..." 83 chroot /mnt /usr/sbin/installboot -o command="$resp" /dev/r${1}a /usr/mdec/bootxx_ffsv1 84 cp -p /mnt/usr/mdec/boot.amiga /mnt/ 85 ;; 86 *) 87 echo "No bootblock installed." 88 ;; 89 esac 90 elif [ "$MODE" = "install" ]; then 91 cat << \__md_installboot_1 92There is no installboot program found on the installed filesystems. No boot 93programs are installed. 94__md_installboot_1 95 else 96 cat << \__md_installboot_2 97There is no installboot program found on the upgraded filesystems. No boot 98programs are installed. 99__md_installboot_2 100 fi 101} 102 103md_native_fstype() { 104 echo "ados" 105} 106 107md_native_fsopts() { 108 echo "ro" 109} 110 111md_prep_disklabel() { 112} 113 114md_view_labels_possible=1 115md_view_labels() { 116 _DKDEVS=$(md_get_diskdevs) 117 echo "If you like, you can now examine the labels of your disks." 118 echo "" 119 echo -n "Available are "${_DKDEVS}". Look at which? [skip this step] " 120 getresp "done" 121 while [ "${resp:-done}" != "done" ]; do 122 echo "" 123 disklabel ${resp} 124 echo "" 125 echo -n "Available are "${_DKDEVS}". Look at which? [done] " 126 getresp "done" 127 done 128 cat << \__prep_disklabel_1 129 130As a reminder: the 'c' partition is assigned to the whole disk and can't 131normally be used for a any file system! 132 133__prep_disklabel_1 134} 135 136md_labeldisk() { 137} 138 139md_welcome_banner() { 140 if [ "$MODE" = "install" ]; then 141 echo "" 142 echo "Welcome to the NetBSD/${MACHINE} ${RELEASE} installation program." 143 cat << \__welcome_banner_1 144 145This program is designed to help you put NetBSD on your disk, 146in a simple and rational way. You'll be asked several questions, 147and it would probably be useful to have your disk's hardware 148manual, the installation notes, and a calculator handy. 149__welcome_banner_1 150 151 else 152 echo "" 153 echo "Welcome to the NetBSD/${MACHINE} ${RELEASE} upgrade program." 154 cat << \__welcome_banner_2 155 156This program is designed to help you upgrade your NetBSD system in a 157simple and rational way. 158 159As a reminder, installing the 'etc' binary set is NOT recommended. 160Once the rest of your system has been upgraded, you should manually 161merge any changes to files in the 'etc' set into those files which 162already exist on your system. 163__welcome_banner_2 164 fi 165 166cat << \__welcome_banner_3 167 168As with anything which modifies your disk's contents, this 169program can cause SIGNIFICANT data loss, and you are advised 170to make sure your data is backed up before beginning the 171installation process. 172 173Default answers are displayed in brackets after the questions. 174You can hit Control-C at any time to quit, but if you do so at a 175prompt, you may have to hit return. Also, quitting in the middle of 176installation may leave your system in an inconsistent state. 177 178__welcome_banner_3 179} 180 181md_not_going_to_install() { 182 cat << \__not_going_to_install_1 183 184OK, then. Enter 'halt' at the prompt to halt the machine. Once the 185machine has halted, power-cycle the system to load new boot code. 186 187Note: If you wish to have another try. Just type '^D' at the prompt. After 188 a moment, the installer will restart itself. 189 190__not_going_to_install_1 191} 192 193md_congrats() { 194 local what; 195 if [ "$MODE" = "install" ]; then 196 what="installed"; 197 else 198 what="upgraded"; 199 fi 200 cat << __congratulations_1 201 202CONGRATULATIONS! You have successfully $what NetBSD! 203To boot the installed system, enter halt at the command prompt. Once the 204system has halted, reset the machine and boot from the disk. 205 206Note: If you wish to have another try. Just type '^D' at the prompt. After 207 a moment, the installer will restart itself. 208 209__congratulations_1 210} 211 212md_copy_kernel() { 213 # This is largely a copy of install_disk and install_from_mounted_fs() 214 # with some special frobbing. 215 216 local _directory 217 local _sets 218 local _filename 219 local _f 220 221 if [ "$MODE" = "install" ]; then 222 echo -n "Adding keymap initialization to rc.local..." 223 echo /usr/sbin/loadkmap ${__keymap__} >> /mnt/etc/rc.local 224 echo "done." 225 fi 226 227 if [ -e /netbsd ]; then 228 if [ -e /mnt/netbsd ]; then 229 echo "On the installation filesystem there is this kernel: " 230 ls -l /netbsd 231 echo "The already installed kernel is: " 232 ls -l /mnt/netbsd 233 echo "Do you want to replace the already installed kernel by the kernel" 234 echo -n "on the installation filesystem? (y/n) [n] " 235 resp="n" 236 getresp "" 237 if [ "${resp}" != "y" ] && [ "${resp}" != "Y" ]; then 238 return 239 fi 240 fi 241 242 echo -n "Copying kernel..." 243 cp -p /netbsd /mnt/netbsd 244 echo "done." 245 return 246 fi 247 248cat << \__md_copy_kernel_1 249Your installation set did not include a netbsd kernel on the installation 250filesystem. You are now given the opportunity install it from either the 251kernel-floppy from the distribution or another location on one of your disks. 252 253The following disk devices are installed on your system; please select 254the disk device containing the partition with the netbsd kernel: 255__md_copy_kernel_1 256 257 _DKDEVS=$(md_get_diskdevs) 258 echo "$_DKDEVS" 259 echo "fd0" 260 echo "" 261 _DKDEVS="$_DKDEVS fd0" # Might be on the kernel floppy! 262 echo -n "Which is the disk with the kernel? [abort] " 263 264 if mount_a_disk ; then 265 return # couldn't mount the disk 266 fi 267 268 # Get the directory where the file lives 269 resp="" # force one iteration 270 while [ -z "${resp}" ]; do 271 echo "Enter the directory relative to the mount point that" 272 echo -n "contains the file. [${_directory}] " 273 getresp "${_directory}" 274 done 275 _directory=$resp 276 277 _sets=$(cd /mnt2/$_directory; ls netbsd* 2> /dev/null) 278 if [ -z "$_sets" ]; then 279 echo "There are no NetBSD kernels available in \"$1\"" 280 umount -f /mnt2 > /dev/null 2>&1 281 return 282 fi 283 while : ; do 284 echo "The following kernels are available:" 285 echo "" 286 287 for _f in $_sets ; do 288 echo " $_f" 289 done 290 echo "" 291 set -- $_sets 292 echo -n "File name [$1]? " 293 getresp "$1" 294 _f=$resp 295 _filename="/mnt2/$_directory/$_f" 296 297 # Ensure file exists 298 if [ ! -f $_filename ]; then 299 echo "File $_filename does not exist. Check to make" 300 echo "sure you entered the information properly." 301 echo -n "Do you want to retry [y]? " 302 getresp "y" 303 if [ "$resp" = "n" ]; then 304 break 305 fi 306 continue 307 fi 308 309 # Copy the kernel 310 cp $_filename /mnt 311 break 312 done 313 umount -f /mnt2 > /dev/null 2>&1 314} 315 316md_lib_is_aout() { 317 local r 318 test -h $1 && return 1 319 test -f $1 || return 1 320 321 [ "$(dd if=$1 bs=1 skip=1 count=3 2> /dev/null)" = "ELF" ] && return 1 322 return 0 323} 324 325 326md_mv_usr_lib() { 327 local root 328 root=$1 329 for f in $root/usr/lib/lib*.so.[0-9]*.[0-9]* ; do 330 md_lib_is_aout $f || continue 331 mv -f $f $root/emul/aout/usr/lib || return 1 332 done 333 return 0 334} 335 336md_x_shlib_set_14=" \ 337 libICE.so.6.3 \ 338 libPEX5.so.6.0 \ 339 libSM.so.6.0 \ 340 libX11.so.6.1 \ 341 libXIE.so.6.0 \ 342 libXaw.so.6.1 \ 343 libXext.so.6.3 \ 344 libXi.so.6.0 \ 345 libXmu.so.6.0 \ 346 libXp.so.6.2 \ 347 libXt.so.6.0 \ 348 libXtst.so.6.1 \ 349 liboldX.so.6.0" 350 351md_mv_x_lib() { 352 local root xlibdir 353 root=$1 354 xlibdir=$2 355 for f in $md_x_shlib_set_14; do 356 md_lib_is_aout $root/$xlibdir/$f || continue 357 mv -f $root/$xlibdir/$f $root/emul/aout/$xlibdir || return 1 358 done 359 return 0 360} 361 362md_mv_aout_libs() 363{ 364 local root xlibdir 365 366 root=/mnt # XXX - should be global 367 368 if [ -d $root/emul/aout/. ]; then 369 echo "Using existing /emul/aout directory" 370 else 371 echo "Creating /emul/aout hierarchy" 372 mkdir -p $root/usr/aout || return 1 373 374 if [ ! -d $root/emul ]; then 375 mkdir $root/emul || return 1 376 fi 377 378 if [ -h $root/emul/aout ]; then 379 echo "Preserving existing symbolic link from /emul/aout" 380 mv -f $root/emul/aout $root/emul/aout.old || return 1 381 fi 382 383 ln -s ../usr/aout $root/emul/aout || return 1 384 fi 385 386 # Create /emul/aout/etc and /emul/aout/usr/lib 387 if [ ! -d $root/emul/aout/etc ]; then 388 mkdir $root/emul/aout/etc || return 1 389 fi 390 if [ ! -d $root/emul/aout/usr/lib ]; then 391 mkdir -p $root/emul/aout/usr/lib || return 1 392 fi 393 394 # Move ld.so.conf 395 if [ -f $root/etc/ld.so.conf ]; then 396 mv -f $root/etc/ld.so.conf $root/emul/aout/etc || return 1 397 fi 398 399 # Finally, move the aout shared libraries from /usr/lib 400 md_mv_usr_lib $root || return 1 401 402 # If X11 is installed, move the those libraries as well 403 xlibdir="/usr/X11R7/lib" 404 if [ -d $root/$xlibdir/. ]; then 405 mkdir -p $root/emul/aout/$xlibdir || return 1 406 md_mv_x_lib $root $xlibdir || return 1 407 fi 408 409 echo "a.out emulation environment setup completed." 410} 411 412md_prepare_upgrade() 413{ 414cat << 'EOF' 415This release uses the ELF binary object format. Existing (a.out) binaries 416can still be used on your system after it has been upgraded, provided 417that the shared libraries needed by those binaries are made available 418in the filesystem hierarchy rooted at /emul/aout. 419 420This upgrade procedure will now establish this hierarchy by moving all 421shared libraries in a.out format found in /usr/lib to /emul/aout/usr/lib. 422It will also move the X11 shared libraries in a.out format from previous 423NetBSD/amiga X11 installation sets, if they are installed. 424 425EOF 426 md_mv_aout_libs || { 427 echo "Failed to setup a.out emulation environment" 428 return 1 429 } 430 return 0 431} 432 433# Flag to notify upgrade.sh of the existence of md_prepare_upgrade() 434md_upgrade_prep_needed=1 435