re-establish kernel assert()s.
[minix.git] / commands / scripts / setup.sh
bloba68af44462be408ee637dd75383d5623ca2dc1d5
1 #!/bin/sh
3 # setup 4.1 - install a MINIX distribution
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 #
11 LOCALRC=/usr/etc/rc.local
12 MYLOCALRC=/mnt/etc/rc.local
13 ROOTMB=16
14 ROOTSECTS="`expr $ROOTMB '*' 1024 '*' 2`"
15 USRKBFILE=/.usrkb
16 if [ ! -f "$USRKBFILE" ]
17 then echo "Are you really running from CD?"
18 echo "No $USRKBFILE file."
19 exit 1
21 USRKB="`cat /.usrkb`"
22 TOTALMB="`expr 3 + $USRKB / 1024 + $ROOTMB`"
23 ROOTFILES="`cat /.rootfiles`"
24 USRFILES="`cat /.usrfiles`"
26 if [ "$TOTALMB" -lt 1 ]
27 then
28 echo "Are you really running from CD?"
29 echo "Something wrong with size estimate on CD."
30 exit 1
33 if [ "$ROOTFILES" -lt 1 ]
34 then
35 echo "Are you really running from CD?"
36 echo "Something wrong with root files count on CD."
37 exit 1
40 if [ "$USRFILES" -lt 1 ]
41 then
42 echo "Are you really running from CD?"
43 echo "Something wrong with usr files count on CD."
44 exit 1
47 PATH=/bin:/usr/bin
48 export PATH
51 usage()
53 cat >&2 <<'EOF'
54 Usage: setup # Install a skeleton system on the hard disk.
55 setup /usr # Install the rest of the system (binaries or sources).
57 # To install from other things then floppies:
59 urlget http://... | setup /usr # Read from a web site.
60 urlget ftp://... | setup /usr # Read from an FTP site.
61 mtools copy c0d0p0:... - | setup /usr # Read from the C: drive.
62 dosread c0d0p0 ... | setup /usr # Likewise if no mtools.
63 EOF
64 exit 1
67 warn()
69 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"
72 # No options.
73 while getopts '' opt; do usage; done
74 shift `expr $OPTIND - 1`
76 if [ "$USER" != root ]
77 then echo "Please run setup as root."
78 exit 1
81 # Find out what we are running from.
82 exec 9<&0 </etc/mtab # Mounted file table.
83 read thisroot rest # Current root (/dev/ram or /dev/fd?)
84 read fdusr rest # USR (/dev/fd? or /dev/fd?p2)
85 exec 0<&9 9<&-
87 # What do we know about ROOT?
88 case $thisroot:$fdusr in
89 /dev/ram:/dev/fd0p2) fdroot=/dev/fd0 # Combined ROOT+USR in drive 0
91 /dev/ram:/dev/fd1p2) fdroot=/dev/fd1 # Combined ROOT+USR in drive 1
93 /dev/ram:/dev/fd*) fdroot=unknown # ROOT is some other floppy
95 /dev/fd*:/dev/fd*) fdroot=$thisroot # ROOT is mounted directly
97 *) fdroot=$thisroot # ?
98 esac
100 echo -n "
101 Welcome to the MINIX 3 setup script. This script will guide you in setting up
102 MINIX on your machine. Please consult the manual for detailed instructions.
104 Note 1: If the screen blanks, hit CTRL+F3 to select \"software scrolling\".
105 Note 2: If things go wrong then hit CTRL+C to abort and start over.
106 Note 3: Default answers, like [y], can simply be chosen by hitting ENTER.
107 Note 4: If you see a colon (:) then you should hit ENTER to continue.
109 read ret
111 # begin Step 1
112 echo ""
113 echo " --- Step 1: Select keyboard type --------------------------------------"
114 echo ""
116 echo "What type of keyboard do you have? You can choose one of:"
117 echo ""
118 ls -C /usr/lib/keymaps | sed -e 's/\.map//g' -e 's/^/ /'
119 echo ""
120 step1=""
121 while [ "$step1" != ok ]
123 echo -n "Keyboard type? [us-std] "; read keymap
124 test -n "$keymap" || keymap=us-std
125 if loadkeys "/usr/lib/keymaps/$keymap.map" 2>/dev/null
126 then step1=ok
127 else warn "invalid keyboard"
129 done
130 # end Step 1
132 # begin Step 2
133 #step2=""
134 #while [ "$step2" != ok ]
136 # echo ""
137 # echo " --- Step 2: Select minimal or full distribution -----------------------"
138 # echo ""
139 # echo "You can install MINIX as (M)inimal or (F)ull. (M)inimal"
140 # echo "includes only the binary system and basic system sources."
141 # echo "(F)ull also includes commands sources."
142 # echo ""
143 # echo "Please select:"
144 # echo " (M)inimal install (only basic sources) ($NOSRCMB MB required)"
145 # echo " (F)ull install (full install) ($TOTALMB MB required)"
146 # echo " "
147 # echo -n "Basic (M)inimal or (F)ull install? [F] "
148 # read conf
149 # case "$conf" in
150 # "") step2="ok"; nobigsource="" ;;
151 # [Ff]*) step2="ok"; nobigsource="" ;;
152 # [Mm]*) step2="ok"; nobigsource="1"; TOTALMB=$NOSRCMB; USRFILES=$NOSRCUSRFILES ;;
153 # esac
154 #done
155 # end Step 2
157 echo ""
158 echo " --- Step 2: Selecting full distribution -------------------------------"
159 echo ""
160 nobigsource=""
162 # begin Step 3
163 step3=""
164 while [ "$step3" != ok ]
166 echo ""
167 echo " --- Step 3: Create or select a partition for MINIX 3 -------------------"
168 echo ""
170 echo "Now you need to create a MINIX 3 partition on your hard disk."
171 echo "You can also select one that's already there."
172 echo " "
173 echo "If you have an existing installation, reinstalling will let you"
174 echo "keep your current partitioning and subpartitioning, and overwrite"
175 echo "everything except your s1 subpartition (/home). If you want to"
176 echo "reinstall, select your existing minix partition."
177 echo " "
178 echo "Unless you are an expert, you are advised to use the automated"
179 echo "step-by-step help in setting up."
180 echo ""
181 ok=""
182 while [ "$ok" = "" ]
184 echo -n "Press ENTER for automatic mode, or type 'expert': "
185 read mode
186 if [ -z "$mode" ]; then auto="1"; ok="yes"; fi
187 if [ "$mode" = expert ]; then auto=""; ok="yes"; fi
188 if [ "$ok" != yes ]; then warn "try again"; fi
189 done
191 primary=
193 if [ -z "$auto" ]
194 then
195 # Expert mode
196 echo -n "
197 MINIX needs one primary partition of $TOTALMB MB for a full install,
198 plus what you want for /home.
200 If there is no free space on your disk then you have to choose an option:
201 (1) Delete one or more partitions
202 (2) Allocate an existing partition to MINIX 3
203 (3) Exit setup and shrink a partition using a different OS
205 To make this partition you will be put in the editor \"part\". Follow the
206 advice under the '!' key to make a new partition of type MINIX. Do not
207 touch an existing partition unless you know precisely what you are doing!
208 Please note the name of the partition (e.g. c0d0p1, c0d1p3, c1d1p0) you
209 make. (See the devices section in usage(8) on MINIX device names.)
211 read ret
213 while [ -z "$primary" ]
215 part || exit
217 echo -n "
218 Please finish the name of the primary partition you have created:
219 (Just type ENTER if you want to rerun \"part\") /dev/"
220 read primary
221 done
222 echo ""
223 echo "This is the point of no return. You have selected to install MINIX"
224 echo "on partition /dev/$primary. Please confirm that you want to use this"
225 echo "selection to install MINIX."
226 echo ""
227 confirmation=""
229 if [ ! -b "/dev/$primary" ]
230 then echo "/dev/$primary is not a block device."
233 while [ -z "$confirmation" -o "$confirmation" != yes -a "$confirmation" != no ]
235 echo -n "Are you sure you want to continue? Please enter 'yes' or 'no': "
236 read confirmation
237 if [ "$confirmation" = yes ]; then step3=ok; fi
238 done
239 biosdrivename="Actual BIOS device name unknown, due to expert mode."
240 else
241 if [ "$auto" = "1" ]
242 then
243 # Automatic mode
244 PF="/tmp/pf"
245 if autopart -m$TOTALMB -f$PF
246 then if [ -s "$PF" ]
247 then
248 set `cat $PF`
249 bd="$1"
250 bdn="$2"
251 biosdrivename="Probably, the right command is \"boot $bdn\"."
252 if [ -b "/dev/$bd" ]
253 then primary="$bd"
254 else echo "Funny device $bd from autopart."
256 else
257 echo "Didn't find output from autopart."
259 else echo "Autopart tool failed. Trying again."
262 # Reset at retries and timeouts in case autopart left
263 # them messy.
264 atnormalize
266 if [ -n "$primary" ]; then step3=ok; fi
270 if [ ! -b "/dev/$primary" ]
271 then echo Doing step 3 again.
272 step3=""
273 else
274 devsize="`devsize /dev/$primary`"
276 if [ "$devsize" -lt 1 ]
277 then echo "/dev/$primary is a 0-sized device."
278 step3=""
281 done # while step3 != ok
282 # end Step 3
284 root=${primary}s0
285 home=${primary}s1
286 usr=${primary}s2
287 umount /dev/$root 2>/dev/null && echo "Unmounted $root for you."
288 umount /dev/$home 2>/dev/null && echo "Unmounted $home for you."
289 umount /dev/$usr 2>/dev/null && echo "Unmounted $usr for you."
291 devsizemb="`expr $devsize / 1024 / 2`"
292 maxhome="`expr $devsizemb - $TOTALMB - 1`"
294 if [ "$devsizemb" -lt "$TOTALMB" ]
295 then echo "The selected partition ($devsizemb MB) is too small."
296 echo "You'll need $TOTALMB MB at least."
297 exit 1
300 if [ "$maxhome" -lt 1 ]
301 then echo "Note: you can't have /home with that size partition."
302 maxhome=0
305 TMPMP=/m
306 mkdir $TMPMP >/dev/null 2>&1
308 confirm=""
310 while [ "$confirm" = "" ]
312 auto=""
313 echo ""
314 echo " --- Step 4: Reinstall choice ------------------------------------------"
315 if mount -r /dev/$home $TMPMP >/dev/null 2>&1
316 then umount /dev/$home >/dev/null 2>&1
317 echo ""
318 echo "You have selected an existing MINIX 3 partition."
319 echo "Type F for full installation (to overwrite entire partition)"
320 echo "Type R for a reinstallation (existing /home will not be affected)"
321 echo ""
322 echo -n "(F)ull or (R)einstall? [R] "
323 read conf
324 case "$conf" in
325 "") confirm="ok"; auto="r"; ;;
326 [Rr]*) confirm="ok"; auto="r"; ;;
327 [Ff]*) confirm="ok"; auto="" ;;
328 esac
330 else echo ""
331 echo "No old /home found. Doing full install."
332 echo ""
333 confirm="ok";
336 done
338 rmdir $TMPMP
340 nohome="0"
342 homesize=""
343 if [ ! "$auto" = r ]
344 then
345 echo ""
346 echo " --- Step 5: Select the size of /home ----------------------------------"
347 while [ -z "$homesize" ]
350 # 20% of what is left over after / and /usr
351 # are taken.
352 defmb="`expr $maxhome / 5`"
353 if [ "$defmb" -gt "$maxhome" ]
354 then
355 defmb=$maxhome
358 echo ""
359 echo "MINIX will take up $TOTALMB MB, without /home."
360 echo -n "How big do you want your /home to be in MB (0-$maxhome) ? [$defmb] "
361 read homesize
362 if [ "$homesize" = "" ] ; then homesize=$defmb; fi
363 if [ "$homesize" -lt 1 ]
364 then nohome=1
365 echo "Ok, not making a /home."
366 homesize=0
367 else
368 if [ "$homesize" -gt "$maxhome" ]
369 then echo "That won't fit!"
370 homesize=""
371 else
372 echo ""
373 echo -n "$homesize MB Ok? [Y] "
374 read ok
375 [ "$ok" = Y -o "$ok" = y -o "$ok" = "" ] || homesize=""
378 echo ""
379 done
380 # Homesize in sectors
381 homemb="$homesize MB"
382 homesize="`expr $homesize '*' 1024 '*' 2`"
383 else
384 homepart="`devsize /dev/$home`"
385 homesize="`expr $homepart / 2 / 1024`"
386 if [ "$homesize" -gt "$maxhome" ]
387 then
388 echo "Sorry, but your /home is too big ($homesize MB) to leave enough"
389 echo "space on the rest of the partition ($devsizemb MB) for your"
390 echo "selected installation size ($TOTALMB MB)."
391 exit 1
393 # Homesize unchanged (reinstall)
394 homesize=exist
395 homemb="current size"
398 minblocksize=1
399 maxblocksize=64
400 blockdefault=4
402 if [ ! "$auto" = "r" ]
403 then
404 echo ""
405 echo " --- Step 6: Select a block size ---------------------------------------"
406 echo ""
408 echo "The default file system block size is $blockdefault kB."
409 echo ""
411 while [ -z "$blocksize" ]
413 echo -n "Block size in kilobytes? [$blockdefault] "; read blocksize
414 test -z "$blocksize" && blocksize=$blockdefault
415 if [ "$blocksize" -lt $minblocksize -o "$blocksize" -gt $maxblocksize ]
416 then
417 warn "At least $minblocksize kB and at most $maxblocksize kB please."
418 blocksize=""
420 done
421 else
422 blocksize=$blockdefault
425 blocksizebytes="`expr $blocksize '*' 1024`"
427 echo "
428 You have selected to (re)install MINIX 3 in the partition /dev/$primary.
429 The following subpartitions are now being created on /dev/$primary:
431 Root subpartition: /dev/$root $ROOTMB MB
432 /home subpartition: /dev/$home $homemb
433 /usr subpartition: /dev/$usr rest of $primary
435 # Secondary master bootstrap.
436 installboot -m /dev/$primary /usr/mdec/masterboot >/dev/null || exit
437 # Partition the primary.
438 partition /dev/$primary 1 81:${ROOTSECTS}* 81:$homesize 81:0+ > /dev/null || exit
440 echo "Creating /dev/$root for / .."
441 mkfs /dev/$root || exit
443 if [ "$nohome" = 0 ]
444 then
445 if [ ! "$auto" = r ]
446 then echo "Creating /dev/$home for /home .."
447 mkfs -B $blocksizebytes /dev/$home || exit
449 else echo "Skipping /home"
452 echo "Creating /dev/$usr for /usr .."
453 mkfs -B $blocksizebytes /dev/$usr || exit
455 if [ "$nohome" = 0 ]
456 then
457 fshome="home=/dev/$home"
458 else fshome=""
461 echo ""
462 echo " --- Step 7: Wait for files to be copied -------------------------------"
463 echo ""
464 echo "All files will now be copied to your hard disk. This may take a while."
465 echo ""
467 mount /dev/$usr /mnt >/dev/null || exit # Mount the intended /usr.
469 (cd /usr || exit 1
470 list="`ls | fgrep -v install`"
471 for d in $list
473 cpdir -v $d /mnt/$d
474 done
475 ) | progressbar "$USRFILES" || exit # Copy the usr floppy.
477 umount /dev/$usr >/dev/null || exit # Unmount the intended /usr.
478 mount /dev/$root /mnt >/dev/null || exit
480 # Running from the installation CD.
481 cpdir -vx / /mnt | progressbar "$ROOTFILES" || exit
482 cp /mnt/etc/motd.install /mnt/etc/motd
484 # Fix /var/log
485 rm /mnt/var/log
486 ln -s /usr/log /mnt/var/log
488 # CD remnants that aren't for the installed system
489 rm /mnt/etc/issue /mnt/CD /mnt/.* 2>/dev/null
490 echo >/mnt/etc/fstab "\
491 # Poor man's File System Table.
493 root=/dev/$root
494 usr=/dev/$usr
495 $fshome"
497 # National keyboard map.
498 test -n "$keymap" && cp -p "/usr/lib/keymaps/$keymap.map" /mnt/etc/keymap
500 umount /dev/$root >/dev/null || exit # Unmount the new root.
501 mount /dev/$usr /mnt >/dev/null || exit
503 # Make bootable.
504 installboot -d /dev/$root /usr/mdec/bootblock /boot/boot >/dev/null || exit
506 edparams /dev/$root "rootdev=$root; ramimagedev=$root; minix(1,Start MINIX 3) { image=/boot/image_big; boot; }; newminix(2,Start Custom MINIX 3) { unset image; boot }; main() { echo By default, MINIX 3 will automatically load in 3 seconds.; echo Press ESC to enter the monitor for special configuration.; trap 3000 boot; menu; }; save" || exit
507 pfile="/mnt/src/tools/fdbootparams"
508 echo "rootdev=$root; ramimagedev=$root; save" >$pfile
509 # Save name of CD drive
510 cddrive="`mount | grep usr | awk '{ print $1 }' | sed 's/p.*//'`"
511 echo "cddrive=$cddrive" >>/mnt/etc/rc.package
513 bios="`echo $primary | sed -e 's/d./dX/g' -e 's/c.//g'`"
515 if [ ! "$auto" = "r" ]
516 then if mount /dev/$home /home 2>/dev/null
517 then for u in bin ast
518 do h=`eval echo "~$u"`
519 if mkdir $h
520 then echo " * Creating home directory for $u in $h"
521 cpdir /usr/ast $h
522 chown -R $u:operator $h
523 else echo " * Couldn't create $h"
525 done
526 umount /dev/$home
530 echo "Saving random data.."
531 dd if=/dev/random of=/mnt/adm/random.dat bs=1024 count=1
533 umount /dev/$usr >/dev/null || exit
535 # Networking.
536 echo ""
537 echo " --- Step 8: Select your Ethernet chip ---------------------------------"
538 echo ""
540 mount /dev/$root /mnt >/dev/null || exit
541 mount /dev/$usr /mnt/usr >/dev/null || exit
543 /bin/netconf -p /mnt || echo FAILED TO CONFIGURE NETWORK
545 umount /dev/$usr && echo Unmounted $usr
546 umount /dev/$root && echo Unmounted $root
548 echo "
549 Please type 'shutdown' to exit MINIX 3 and enter the boot monitor. At
550 the boot monitor prompt, type 'boot $bios', where X is the bios drive
551 number of the drive you installed on, to try your new MINIX system.
552 $biosdrivename
554 This ends the MINIX 3 setup script. After booting your newly set up system,
555 you can run the test suites as indicated in the setup manual. You also
556 may want to take care of local configuration, such as securing your system
557 with a password. Please consult the usage manual for more information.