1#!/bin/sh 2# 3# setup 4.1 - install a MINIX distribution 4# 5# Changes: 6# Aug 2005 robustness checks and beautifications (Jorrit N. Herder) 7# Jul 2005 extended with autopart and networking (Ben Gras) 8# Dec 20, 1994 created (Kees J. Bot) 9# 10 11ROOTMB=128 12ROOTSECTS="`expr $ROOTMB '*' 1024 '*' 2`" 13BOOTXXSECTS=32 14#LSC: Slight over shoot, as files for / are taken into account, although 15# metadata is not, all in all should be pretty accurate. 16USRKB=$(cat /i386/binary/sets/*.size | awk '{s+=$1} END{print (s/1024)}') 17TOTALMB="`expr 3 + $USRKB / 1024 + $ROOTMB`" 18TOTALFILES="`find -x / | wc -l`" 19 20# /usr/install isn't copied onto the new system; compensate 21INSTALLDIR=/usr/install 22if [ -d $INSTALLDIR ] 23then USRFILES=$(($USRFILES - `find -x $INSTALLDIR | wc -l`)) 24 USRKB=$(($USRKB - `du -sxk $INSTALLDIR | awk '{ print $1 }'`)) 25fi 26 27if [ -z "$FSTYPE" ] 28then FSTYPE=mfs 29fi 30 31PATH=/bin:/sbin:/usr/bin:/usr/sbin 32export PATH 33 34 35usage() 36{ 37 cat >&2 <<'EOF' 38Usage: setup # Install a skeleton system on the hard disk. 39 setup /usr # Install the rest of the system (binaries or sources). 40 41 # To install from other things then floppies: 42 43 fetch -q -o - http://... | setup /usr # Read from a web site. 44 fetch -q -o - ftp://... | setup /usr # Read from an FTP site. 45 mtools copy c0d0p0:... - | setup /usr # Read from the C: drive. 46 dosread c0d0p0 ... | setup /usr # Likewise if no mtools. 47EOF 48 exit 1 49} 50 51warn() 52{ 53 echo -e "\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b ! $1" 54} 55 56check_mbr() 57{ 58 # check for potential problems with old mbr. 59 disk=`echo -n "/dev/$primary" | sed 's/p[0-3]//'` 60 minix_primaries=`echo -n "" | fdisk "$disk" | grep "MINIX" | wc -l` 61 if [ "$minix_primaries" -gt 1 ] 62 then 63 # old mbr + bootxx will not work with several partitions of 64 # the same type. 65 dd if=/usr/mdec/mbr of=temp_mbr_netbsd bs=1 count=440 2>/dev/null 66 dd if="$disk" bs=1 count=440 2>/dev/null | cmp - temp_mbr_netbsd >/dev/null 67 if [ "$?" -ne 0 ] 68 then 69 echo "" 70 echo "Warning: you have MBR which doesn't support multiple MINIX 3 partitions!" 71 echo "You will be able to boot from the first one only!" 72 echo -n "Do you want to install new MBR into $disk? [Y] " 73 read ok 74 if [ "$ok" = Y -o "$ok" = y -o "$ok" = "" ] 75 then 76 installboot_nbsd -m "$disk" /usr/mdec/mbr >/dev/null 77 fi 78 fi 79 rm temp_mbr_netbsd 80 fi 81 82} 83 84# No options. 85while getopts '' opt; do usage; done 86shift `expr $OPTIND - 1` 87 88if [ "$USER" != root ] 89then echo "Please run setup as root." 90 exit 1 91fi 92 93# Find out what we are running from. 94exec 9<&0 </etc/mtab # Mounted file table. 95read thisroot rest # Current root (/dev/ram or /dev/fd?) 96read fdusr rest # USR (/dev/fd? or /dev/fd?p2) 97exec 0<&9 9<&- 98 99# What do we know about ROOT? 100case $thisroot:$fdusr in 101/dev/ram:/dev/fd0p2) fdroot=/dev/fd0 # Combined ROOT+USR in drive 0 102 ;; 103/dev/ram:/dev/fd1p2) fdroot=/dev/fd1 # Combined ROOT+USR in drive 1 104 ;; 105/dev/ram:/dev/fd*) fdroot=unknown # ROOT is some other floppy 106 ;; 107/dev/fd*:/dev/fd*) fdroot=$thisroot # ROOT is mounted directly 108 ;; 109*) fdroot=$thisroot # ? 110esac 111 112echo -n " 113Welcome to the MINIX 3 setup script. This script will guide you in setting up 114MINIX on your machine. Please consult the manual for detailed instructions. 115 116Note 1: If the screen blanks, hit CTRL+F3 to select \"software scrolling\". 117Note 2: If things go wrong then hit CTRL+C to abort and start over. 118Note 3: Default answers, like [y], can simply be chosen by hitting ENTER. 119Note 4: If you see a colon (:) then you should hit ENTER to continue. 120:" 121read ret 122 123# begin Step 1 124echo "" 125echo " --- Step 1: Select keyboard type --------------------------------------" 126echo "" 127 128 echo "What type of keyboard do you have? You can choose one of:" 129 echo "" 130 ls -C /usr/lib/keymaps | sed -e 's/\.map//g' -e 's/^/ /' 131 echo "" 132step1="" 133while [ "$step1" != ok ] 134do 135 echo -n "Keyboard type? [us-std] "; read keymap 136 test -n "$keymap" || keymap=us-std 137 if loadkeys "/usr/lib/keymaps/$keymap.map" 2>/dev/null 138 then step1=ok 139 else warn "invalid keyboard" 140 fi 141done 142# end Step 1 143 144# begin Step 2 145#step2="" 146#while [ "$step2" != ok ] 147#do 148# echo "" 149# echo " --- Step 2: Select minimal or full distribution -----------------------" 150# echo "" 151# echo "You can install MINIX as (M)inimal or (F)ull. (M)inimal" 152# echo "includes only the binary system and basic system sources." 153# echo "(F)ull also includes commands sources." 154# echo "" 155# echo "Please select:" 156# echo " (M)inimal install (only basic sources) ($NOSRCMB MB required)" 157# echo " (F)ull install (full install) ($TOTALMB MB required)" 158# echo " " 159# echo -n "Basic (M)inimal or (F)ull install? [F] " 160# read conf 161# case "$conf" in 162# "") step2="ok"; nobigsource="" ;; 163# [Ff]*) step2="ok"; nobigsource="" ;; 164# [Mm]*) step2="ok"; nobigsource="1"; TOTALMB=$NOSRCMB; USRFILES=$NOSRCUSRFILES ;; 165# esac 166#done 167# end Step 2 168 169echo "" 170echo " --- Step 2: Selecting full distribution -------------------------------" 171echo "" 172nobigsource="" 173 174# begin Step 3 175step3="" 176while [ "$step3" != ok ] 177do 178 echo "" 179 echo " --- Step 3: Create or select a partition for MINIX 3 -------------------" 180 echo "" 181 182 echo "Now you need to create a MINIX 3 partition on your hard disk." 183 echo "You can also select one that's already there." 184 echo " " 185 echo "If you have an existing installation, reinstalling will let you" 186 echo "keep your current partitioning and subpartitioning, and overwrite" 187 echo "everything except your s1 subpartition (/home). If you want to" 188 echo "reinstall, select your existing minix partition." 189 echo " " 190 echo "Unless you are an expert, you are advised to use the automated" 191 echo "step-by-step help in setting up." 192 echo "" 193 ok="" 194 while [ "$ok" = "" ] 195 do 196 echo -n "Press ENTER for automatic mode, or type 'expert': " 197 read mode 198 if [ -z "$mode" ]; then auto="1"; ok="yes"; fi 199 if [ "$mode" = expert ]; then auto=""; ok="yes"; fi 200 if [ "$ok" != yes ]; then warn "try again"; fi 201 done 202 203 primary= 204 205 if [ -z "$auto" ] 206 then 207 # Expert mode 208 echo -n " 209MINIX needs one primary partition of $TOTALMB MB for a full install, 210plus what you want for /home. 211 212If there is no free space on your disk then you have to choose an option: 213 (1) Delete one or more partitions 214 (2) Allocate an existing partition to MINIX 3 215 (3) Exit setup and shrink a partition using a different OS 216 217To make this partition you will be put in the editor \"part\". Follow the 218advice under the '!' key to make a new partition of type MINIX. Do not 219touch an existing partition unless you know precisely what you are doing! 220Please note the name of the partition (e.g. c0d0p1, c0d1p3, c1d1p0) you 221make. (See the devices section in usage(8) on MINIX device names.) 222:" 223 read ret 224 225 while [ -z "$primary" ] 226 do 227 part || exit 228 229 echo -n " 230Please finish the name of the primary partition you have created: 231(Just type ENTER if you want to rerun \"part\") /dev/" 232 read primary 233 done 234 echo "" 235 echo "This is the point of no return. You have selected to install MINIX" 236 echo "on partition /dev/$primary. Please confirm that you want to use this" 237 echo "selection to install MINIX." 238 echo "" 239 confirmation="" 240 241 if [ ! -b "/dev/$primary" ] 242 then echo "/dev/$primary is not a block device." 243 fi 244 245 while [ -z "$confirmation" -o "$confirmation" != yes -a "$confirmation" != no ] 246 do 247 echo -n "Are you sure you want to continue? Please enter 'yes' or 'no': " 248 read confirmation 249 if [ "$confirmation" = yes ]; then step3=ok; fi 250 done 251 biosdrivename="Actual BIOS device name unknown, due to expert mode." 252 else 253 if [ "$auto" = "1" ] 254 then 255 # Automatic mode 256 PF="/tmp/pf" 257 if autopart -m$TOTALMB -f$PF 258 then if [ -s "$PF" ] 259 then 260 set `cat $PF` 261 bd="$1" 262 bdn="$2" 263 biosdrivename="Probably, the right command is \"boot $bdn\"." 264 if [ -b "/dev/$bd" ] 265 then primary="$bd" 266 else echo "Funny device $bd from autopart." 267 fi 268 else 269 echo "Didn't find output from autopart." 270 fi 271 else echo "Autopart tool failed. Trying again." 272 fi 273 274 # Reset at retries and timeouts in case autopart left 275 # them messy. 276 atnormalize 277 278 if [ -n "$primary" ]; then step3=ok; fi 279 fi 280 fi 281 282 if [ ! -b "/dev/$primary" ] 283 then echo Doing step 3 again. 284 step3="" 285 else 286 devsize="`devsize /dev/$primary`" 287 288 if [ "$devsize" -lt 1 ] 289 then echo "/dev/$primary is a 0-sized device." 290 step3="" 291 fi 292 fi 293done # while step3 != ok 294# end Step 3 295 296root=${primary}s0 297home=${primary}s1 298usr=${primary}s2 299umount /dev/$home 2>/dev/null && echo "Unmounted $home for you." 300umount /dev/$usr 2>/dev/null && echo "Unmounted $usr for you." 301umount /dev/$root 2>/dev/null && echo "Unmounted $root for you." 302 303devsizemb="`expr $devsize / 1024 / 2`" 304maxhome="`expr $devsizemb - $TOTALMB - 1`" 305 306if [ "$devsizemb" -lt "$TOTALMB" ] 307then echo "The selected partition ($devsizemb MB) is too small." 308 echo "You'll need $TOTALMB MB at least." 309 exit 1 310fi 311 312if [ "$maxhome" -lt 1 ] 313then echo "Note: you can't have /home with that size partition." 314 maxhome=0 315fi 316 317TMPMP=/mnt 318mkdir $TMPMP >/dev/null 2>&1 319 320confirm="" 321 322while [ "$confirm" = "" ] 323do 324 auto="" 325 echo "" 326echo " --- Step 4: Reinstall choice ------------------------------------------" 327 if mount -r /dev/$home $TMPMP >/dev/null 2>&1 328 then umount /dev/$home >/dev/null 2>&1 329 echo "" 330 echo "You have selected an existing MINIX 3 partition." 331 echo "Type F for full installation (to overwrite entire partition)" 332 echo "Type R for a reinstallation (existing /home will not be affected)" 333 echo "" 334 echo -n "(F)ull or (R)einstall? [R] " 335 read conf 336 case "$conf" in 337 "") confirm="ok"; auto="r"; ;; 338 [Rr]*) confirm="ok"; auto="r"; ;; 339 [Ff]*) confirm="ok"; auto="" ;; 340 esac 341 342 else echo "" 343 echo "No old /home found. Doing full install." 344 echo "" 345 confirm="ok"; 346 fi 347 348done 349 350rmdir $TMPMP 351 352nohome="0" 353 354homesize="" 355if [ ! "$auto" = r ] 356then 357echo "" 358echo " --- Step 5: Select the size of /home ----------------------------------" 359 while [ -z "$homesize" ] 360 do 361 362 # 20% of what is left over after / and /usr 363 # are taken. 364 defmb="`expr $maxhome / 5`" 365 if [ "$defmb" -gt "$maxhome" ] 366 then 367 defmb=$maxhome 368 fi 369 370 echo "" 371 echo "MINIX will take up $TOTALMB MB, without /home." 372 echo -n "How big do you want your /home to be in MB (0-$maxhome) ? [$defmb] " 373 read homesize 374 if [ "$homesize" = "" ] ; then homesize=$defmb; fi 375 if [ "$homesize" -lt 1 ] 376 then nohome=1 377 echo "Ok, not making a /home." 378 homesize=0 379 else 380 if [ "$homesize" -gt "$maxhome" ] 381 then echo "That won't fit!" 382 homesize="" 383 else 384 echo "" 385 echo -n "$homesize MB Ok? [Y] " 386 read ok 387 [ "$ok" = Y -o "$ok" = y -o "$ok" = "" ] || homesize="" 388 fi 389 fi 390 echo "" 391 done 392 # Homesize in sectors 393 homemb="$homesize MB" 394 homesize="`expr $homesize '*' 1024 '*' 2`" 395else 396 # Root size same as our default? If not, warn and keep old root size 397 ROOTSECTSDEFAULT=$ROOTSECTS 398 ROOTSECTS="`devsize /dev/$root`" 399 ROOTMB="`expr $ROOTSECTS / 2048`" 400 if [ $ROOTSECTS -ne $ROOTSECTSDEFAULT ] 401 then 402 # Check if we 403 echo "Root partition size `expr $ROOTSECTS / 2`kb differs from default `expr $ROOTSECTSDEFAULT / 2`kb." 404 echo "This is not a problem, but you may want to do a fresh install at some point to" 405 echo "be able to benefit from the new default." 406 fi 407 408 # Check if enough space for new boot (even if old used) 409 bootspace=$((`devsize /dev/$primary`-`devsize /dev/$root`-`devsize /dev/$home`-`devsize /dev/$usr`)) >/dev/null 410 if [ $bootspace -lt $BOOTXXSECTS ] 411 then 412 echo "Root partition size will be reduced by up to 16Kb to fit new bootloader." 413 echo "This is not a problem." 414 ROOTSECTS=`expr $ROOTSECTS - $BOOTXXSECTS + $bootspace` 415 fi 416 417 # Recompute totals based on root size 418 TOTALMB="`expr 3 + $USRKB / 1024 + $ROOTMB`" 419 maxhome="`expr $devsizemb - $TOTALMB - 1`" 420 421 homepart="`devsize /dev/$home`" 422 homesize="`expr $homepart / 2 / 1024`" 423 if [ "$homesize" -gt "$maxhome" ] 424 then 425 echo "Sorry, but your /home is too big ($homesize MB) to leave enough" 426 echo "space on the rest of the partition ($devsizemb MB) for your" 427 echo "selected installation size ($TOTALMB MB)." 428 exit 1 429 fi 430 # Homesize unchanged (reinstall) 431 homesize=exist 432 homemb="current size" 433fi 434 435minblocksize=1 436maxblocksize=64 437blockdefault=4 438 439if [ ! "$auto" = "r" ] 440then 441 echo "" 442echo " --- Step 6: Select a block size ---------------------------------------" 443 echo "" 444 445 echo "The default file system block size is $blockdefault kB." 446 echo "" 447 448 while [ -z "$blocksize" ] 449 do 450 echo -n "Block size in kilobytes? [$blockdefault] "; read blocksize 451 test -z "$blocksize" && blocksize=$blockdefault 452 if [ "$blocksize" -lt $minblocksize -o "$blocksize" -gt $maxblocksize ] 453 then 454 warn "At least $minblocksize kB and at most $maxblocksize kB please." 455 blocksize="" 456 fi 457 done 458else 459 blocksize=$blockdefault 460fi 461 462blocksizebytes="`expr $blocksize '*' 1024`" 463 464bootsectors=$BOOTXXSECTS 465 466check_mbr 467 468echo " 469You have selected to (re)install MINIX 3 in the partition /dev/$primary. 470The following subpartitions are now being created on /dev/$primary: 471 472 Root subpartition: /dev/$root $ROOTMB MB 473 /home subpartition: /dev/$home $homemb 474 /usr subpartition: /dev/$usr rest of $primary 475" 476 # Secondary master bootstrap. 477# New boot doesn't require mbr on pN (bootxx will be there) 478# When necessarily mbr is installed on dN by partition. 479 # Partition the primary. 480partition /dev/$primary $bootsectors 81:${ROOTSECTS}* 81:$homesize 81:0+ > /dev/null || exit 481 482echo "Creating /dev/$root for / .." 483mkfs.mfs /dev/$root || exit 484 485if [ "$nohome" = 0 ] 486then 487 if [ ! "$auto" = r ] 488 then echo "Creating /dev/$home for /home .." 489 mkfs.$FSTYPE -B $blocksizebytes /dev/$home || exit 490 fi 491else echo "Skipping /home" 492fi 493 494echo "Creating /dev/$usr for /usr .." 495mkfs.$FSTYPE -B $blocksizebytes /dev/$usr || exit 496 497if [ "$nohome" = 0 ] 498then 499 fshome="/dev/$home /home $FSTYPE rw 0 2" 500else fshome="" 501fi 502 503echo "" 504echo " --- Step 7: Wait for files to be copied -------------------------------" 505echo "" 506echo "All files will now be copied to your hard disk. This may take a while." 507echo "" 508 509mount /dev/$root /mnt >/dev/null || exit 510mkdir -p /mnt/usr 511mount /dev/$usr /mnt/usr >/dev/null || exit # Mount the intended /usr. 512if [ "$nohome" = 0 ]; then 513 mkdir -p /mnt/home 514 mount /dev/$home /mnt/home >/dev/null || exit # Mount the intended /home 515fi 516 517# Running from the installation CD. 518for set in /i386/binary/sets/*.tgz; do 519 echo "Extracting $(basename "$set")..." 520 COUNT_FILES=$(cat $(echo "$set" | sed -e "s/\.tgz/\.count/")) 521 (cd /mnt; pax -rz -f $set -v -pe 2>&1 | progressbar "$COUNT_FILES" || exit) 522done; 523 524echo "Creating device nodes..." 525(cd /mnt/dev; MAKEDEV -s all) 526 527# Fix permissions 528chmod $(stat -f %Lp /usr) /mnt/usr 529chown $(stat -f %u /usr) /mnt/usr 530chgrp $(stat -f %g /usr) /mnt/usr 531if [ "$nohome" = 0 ]; then 532 chmod $(stat -f %Lp /home) /mnt/home 533 chown $(stat -f %u /home) /mnt/home 534 chgrp $(stat -f %g /home) /mnt/home 535fi 536 537# CD remnants that aren't for the installed system 538rm /mnt/etc/issue /mnt/CD /mnt/.* 2>/dev/null 539echo >/mnt/etc/fstab "/dev/$root / mfs rw 0 1 540/dev/$usr /usr $FSTYPE rw 0 2 541$fshome 542none /sys devman rw,rslabel=devman 0 0 543none /dev/pts ptyfs rw,rslabel=ptyfs 0 0" 544 545 # National keyboard map. 546test -n "$keymap" && cp -p "/usr/lib/keymaps/$keymap.map" /mnt/etc/keymap 547 548# XXX we have to use "-f" here, because installboot worries about BPB, which 549# we don't have... 550installboot_nbsd -f /dev/$primary /usr/mdec/bootxx_minixfs3 >/dev/null || exit 551# give the install the boot loader 552cp /usr/mdec/boot_monitor /mnt/ 553minixdir=/mnt/boot/minix_default 554if [ ! -f $minixdir/kernel ] 555then rm -rf $minixdir 556 cp -r /mnt/boot/minix/.temp $minixdir 557fi 558if [ ! -e /mnt/boot/minix_latest ] 559then ln -sf minix_default /mnt/boot/minix_latest 560fi 561chroot /mnt update_bootcfg 562 563bios="`echo $primary | sed -e 's/d./dX/g' -e 's/c.//g'`" 564 565echo "Saving random data.." 566dd if=/dev/random of=/mnt/usr/adm/random.dat bs=1024 count=1 567 568# Networking. 569echo "" 570echo " --- Step 8: Select your Ethernet chip ---------------------------------" 571echo "" 572 573/bin/netconf -p /mnt || echo FAILED TO CONFIGURE NETWORK 574 575PACKAGES_DIR="/packages/$(uname -v | cut -f2 -d' ')/$(uname -p)/All" 576if [ -e "$PACKAGES_DIR" ] 577then 578 echo "Installing pkgin..." 579 sh -c "cp $PACKAGES_DIR/pkgin-* $PACKAGES_DIR/pkg_install-* $PACKAGES_DIR/libarchive-* /mnt/tmp && 580 chroot /mnt pkg_add /tmp/pkgin-*" 581 rm -f /mnt/tmp/* 582 583 # Save name of CD drive 584 cddrive=$(mount | grep ' on / ' | cut -f1 -d' ') 585 echo "cddrive=$cddrive" >>/mnt/usr/etc/rc.package 586else 587 echo "Package dir not found, skipping pkgin installation..." 588fi 589 590if [ "$nohome" = 0 ]; then 591 umount /dev/$home && echo Unmounted $home 592fi 593umount /dev/$usr && echo Unmounted $usr 594umount /dev/$root && echo Unmounted $root 595 596echo " 597Please type 'shutdown -r now' to exit MINIX 3 and reboot. To boot into 598your new system, you might have to remove the installation media. 599 600This ends the MINIX 3 setup script. You may want to take care of post 601installation steps, such as local testing and configuration. 602 603Please consult the user manual for more information. 604 605" 606 607