source: trunk/minix/commands/scripts/setup.sh@ 21

Last change on this file since 21 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 17.8 KB
Line 
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
11LOCALRC=/usr/etc/rc.local
12MYLOCALRC=/mnt/etc/rc.local
13ROOTMB=16
14ROOTSECTS="`expr $ROOTMB '*' 1024 '*' 2`"
15USRKBFILE=/.usrkb
16if [ ! -f "$USRKBFILE" ]
17then echo "Are you really running from CD?"
18 echo "No $USRKBFILE file."
19 exit 1
20fi
21USRKB="`cat /.usrkb`"
22TOTALMB="`expr 3 + $USRKB / 1024 + $ROOTMB`"
23ROOTFILES="`cat /.rootfiles`"
24USRFILES="`cat /.usrfiles`"
25EXTRASRCFILES="`cat /.extrasrcfiles`"
26EXTRASRCKB="`cat /.extrasrckb`"
27
28# Install size without extra sources (rounded up)
29NOSRCMB="`expr $TOTALMB - $EXTRASRCKB / 1024`"
30NOSRCUSRFILES="`expr $USRFILES - $EXTRASRCFILES`"
31
32if [ "$EXTRASRCKB" -lt 1 ]
33then
34 echo "Are you really running from CD?"
35 echo "Something wrong with the extra-source-kb on CD."
36 exit 1
37fi
38
39if [ "$EXTRASRCFILES" -lt 1 ]
40then
41 echo "Are you really running from CD?"
42 echo "Something wrong with the extra-source-files estimate on CD."
43 exit 1
44fi
45
46if [ "$TOTALMB" -lt 1 ]
47then
48 echo "Are you really running from CD?"
49 echo "Something wrong with size estimate on CD."
50 exit 1
51fi
52
53if [ "$ROOTFILES" -lt 1 ]
54then
55 echo "Are you really running from CD?"
56 echo "Something wrong with root files count on CD."
57 exit 1
58fi
59
60if [ "$USRFILES" -lt 1 ]
61then
62 echo "Are you really running from CD?"
63 echo "Something wrong with usr files count on CD."
64 exit 1
65fi
66
67PATH=/bin:/usr/bin
68export PATH
69
70
71usage()
72{
73 cat >&2 <<'EOF'
74Usage: setup # Install a skeleton system on the hard disk.
75 setup /usr # Install the rest of the system (binaries or sources).
76
77 # To install from other things then floppies:
78
79 urlget http://... | setup /usr # Read from a web site.
80 urlget ftp://... | setup /usr # Read from an FTP site.
81 mtools copy c0d0p0:... - | setup /usr # Read from the C: drive.
82 dosread c0d0p0 ... | setup /usr # Likewise if no mtools.
83EOF
84 exit 1
85}
86
87warn()
88{
89 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"
90}
91
92# No options.
93while getopts '' opt; do usage; done
94shift `expr $OPTIND - 1`
95
96if [ "$USER" != root ]
97then echo "Please run setup as root."
98 exit 1
99fi
100
101# Find out what we are running from.
102exec 9<&0 </etc/mtab # Mounted file table.
103read thisroot rest # Current root (/dev/ram or /dev/fd?)
104read fdusr rest # USR (/dev/fd? or /dev/fd?p2)
105exec 0<&9 9<&-
106
107# What do we know about ROOT?
108case $thisroot:$fdusr in
109/dev/ram:/dev/fd0p2) fdroot=/dev/fd0 # Combined ROOT+USR in drive 0
110 ;;
111/dev/ram:/dev/fd1p2) fdroot=/dev/fd1 # Combined ROOT+USR in drive 1
112 ;;
113/dev/ram:/dev/fd*) fdroot=unknown # ROOT is some other floppy
114 ;;
115/dev/fd*:/dev/fd*) fdroot=$thisroot # ROOT is mounted directly
116 ;;
117*) fdroot=$thisroot # ?
118esac
119
120echo -n "
121Welcome to the MINIX 3 setup script. This script will guide you in setting up
122MINIX on your machine. Please consult the manual for detailed instructions.
123
124Note 1: If the screen blanks, hit CTRL+F3 to select \"software scrolling\".
125Note 2: If things go wrong then hit CTRL+C to abort and start over.
126Note 3: Default answers, like [y], can simply be chosen by hitting ENTER.
127Note 4: If you see a colon (:) then you should hit ENTER to continue.
128:"
129read ret
130
131# begin Step 1
132echo ""
133echo " --- Step 1: Select keyboard type --------------------------------------"
134echo ""
135
136 echo "What type of keyboard do you have? You can choose one of:"
137 echo ""
138 ls -C /usr/lib/keymaps | sed -e 's/\.map//g' -e 's/^/ /'
139 echo ""
140step1=""
141while [ "$step1" != ok ]
142do
143 echo -n "Keyboard type? [us-std] "; read keymap
144 test -n "$keymap" || keymap=us-std
145 if loadkeys "/usr/lib/keymaps/$keymap.map" 2>/dev/null
146 then step1=ok
147 else warn "invalid keyboard"
148 fi
149done
150# end Step 1
151
152# begin Step 2
153echo ""
154echo " --- Step 2: Select your Ethernet chip ---------------------------------"
155echo ""
156
157# Ask user about networking
158echo "MINIX 3 currently supports the following Ethernet cards. Please choose: "
159 echo ""
160 echo "0. No Ethernet card (no networking)"
161 echo "1. Intel Pro/100"
162 echo "2. 3Com 501 or 3Com 509 based card"
163 echo "3. Realtek 8139 based card"
164 echo "4. Realtek 8029 based card (also emulated by Qemu)"
165 echo " Note: If you want to use this in Qemu, set 'qemu_pci=1' in the boot monitor."
166 echo "5. NE2000, 3com 503 or WD based card (also emulated by Bochs)"
167 echo "6. AMD LANCE (also emulated by VMWare)"
168 echo "7. Different Ethernet card (no networking)"
169 echo ""
170 echo "You can always change your mind after the setup."
171 echo ""
172step2=""
173while [ "$step2" != ok ]
174do
175 eth=""
176 echo -n "Ethernet card? [0] "; read eth
177 test -z $eth && eth=0
178 driver=""
179 driverargs=""
180 case "$eth" in
181 0) step2="ok"; ;;
182 1) step2="ok"; driver=fxp; ;;
183 2) step2="ok"; driver=dpeth; driverargs="#dpeth_arg='DPETH0=port:irq:memory'";
184 echo ""
185 echo "Note: After installing, edit $LOCALRC to the right configuration."
186 ;;
187 3) step2="ok"; driver=rtl8139; ;;
188 4) step2="ok"; driver=dp8390; driverargs="dp8390_arg='DPETH0=pci'"; ;;
189 5) step2="ok"; driver=dp8390; driverargs="dp8390_arg='DPETH0=240:9'";
190 echo ""
191 echo "Note: After installing, edit $LOCALRC to the right configuration."
192 echo " chose option 4, the defaults for emulation by Bochs have been set."
193 ;;
194 6) driver="lance"; driverargs="lance_arg='LANCE0=on'"; step2="ok"; ;;
195 7) step2="ok"; ;;
196 *) warn "choose a number"
197 esac
198done
199# end Step 2
200
201# begin Step 3
202step3=""
203while [ "$step3" != ok ]
204do
205 echo ""
206 echo " --- Step 3: Select minimal or full distribution -----------------------"
207 echo ""
208 echo "You can install MINIX as (M)inimal or (F)ull. (M)inimal"
209 echo "includes only the binary system and basic system sources."
210 echo "(F)ull also includes commands sources."
211 echo ""
212 echo "Please select:"
213 echo " (M)inimal install (only basic sources) ($NOSRCMB MB required)"
214 echo " (F)ull install (full install) ($TOTALMB MB required)"
215 echo " "
216 echo -n "Basic (M)inimal or (F)ull install? [F] "
217 read conf
218 case "$conf" in
219 "") step3="ok"; nobigsource="" ;;
220 [Ff]*) step3="ok"; nobigsource="" ;;
221 [Mm]*) step3="ok"; nobigsource="1"; TOTALMB=$NOSRCMB; USRFILES=$NOSRCUSRFILES ;;
222 esac
223done
224# end Step 3
225
226# begin Step 4
227step4=""
228while [ "$step4" != ok ]
229do
230 echo ""
231 echo " --- Step 4: Create or select a partition for MINIX 3 -------------------"
232 echo ""
233
234 echo "Now you need to create a MINIX 3 partition on your hard disk."
235 echo "It has to have $TOTALMB MB at the very least."
236 echo "You can also select one that's already there."
237 echo " "
238 echo "If you have an existing installation, reinstalling will let you"
239 echo "keep your current partitioning and subpartitioning, and overwrite"
240 echo "everything except your s1 subpartition (/home). If you want to"
241 echo "reinstall, select your existing minix partition."
242 echo " "
243 echo "Unless you are an expert, you are advised to use the automated"
244 echo "step-by-step help in setting up."
245 echo ""
246 ok=""
247 while [ "$ok" = "" ]
248 do
249 echo -n "Press ENTER for automatic mode, or type 'expert': "
250 read mode
251 if [ -z "$mode" ]; then auto="1"; ok="yes"; fi
252 if [ "$mode" = expert ]; then auto=""; ok="yes"; fi
253 if [ "$ok" != yes ]; then warn "try again"; fi
254 done
255
256 primary=
257
258 if [ -z "$auto" ]
259 then
260 # Expert mode
261 echo -n "
262MINIX needs one primary partition of $TOTALMB MB for a full install,
263plus what you want for /home.
264The maximum file system currently supported is 4 GB.
265
266If there is no free space on your disk then you have to choose an option:
267 (1) Delete one or more partitions
268 (2) Allocate an existing partition to MINIX 3
269 (3) Exit setup and shrink a partition using a different OS
270
271To make this partition you will be put in the editor \"part\". Follow the
272advice under the '!' key to make a new partition of type MINIX. Do not
273touch an existing partition unless you know precisely what you are doing!
274Please note the name of the partition (e.g. c0d0p1, c0d1p3, c1d1p0) you
275make. (See the devices section in usage(8) on MINIX device names.)
276:"
277 read ret
278
279 while [ -z "$primary" ]
280 do
281 part || exit
282
283 echo -n "
284Please finish the name of the primary partition you have created:
285(Just type ENTER if you want to rerun \"part\") /dev/"
286 read primary
287 done
288 echo ""
289 echo "This is the point of no return. You have selected to install MINIX"
290 echo "on partition /dev/$primary. Please confirm that you want to use this"
291 echo "selection to install MINIX."
292 echo ""
293 confirmation=""
294 while [ -z "$confirmation" -o "$confirmation" != yes -a "$confirmation" != no ]
295 do
296 echo -n "Are you sure you want to continue? Please enter 'yes' or 'no': "
297 read confirmation
298 if [ "$confirmation" = yes ]; then step4=ok; fi
299 done
300 biosdrivename="Actual BIOS device name unknown, due to expert mode."
301 else
302 if [ "$auto" = "1" ]
303 then
304 # Automatic mode
305 PF="/tmp/pf"
306 if autopart -m$TOTALMB -f$PF
307 then if [ -s "$PF" ]
308 then
309 set `cat $PF`
310 bd="$1"
311 bdn="$2"
312 biosdrivename="Probably, the right command is \"boot $bdn\"."
313 if [ -b "/dev/$bd" ]
314 then primary="$bd"
315 else echo "Funny device $bd from autopart."
316 fi
317 else
318 echo "Didn't find output from autopart."
319 fi
320 else echo "Autopart tool failed. Trying again."
321 fi
322
323 # Reset at retries and timeouts in case autopart left
324 # them messy.
325 atnormalize
326
327 if [ -n "$primary" ]; then step4=ok; fi
328 fi
329 fi
330
331 if [ ! -b "/dev/$primary" ]
332 then echo "/dev/$primary is not a block device."
333 step4=""
334 else
335 devsize="`devsize /dev/$primary`"
336
337 if [ "$devsize" -lt 1 ]
338 then echo "/dev/$primary is a 0-sized device."
339 step4=""
340 fi
341 fi
342done # while step4 != ok
343# end Step 4
344
345root=${primary}s0
346home=${primary}s1
347usr=${primary}s2
348umount /dev/$root 2>/dev/null && echo "Unmounted $root for you."
349umount /dev/$home 2>/dev/null && echo "Unmounted $home for you."
350umount /dev/$usr 2>/dev/null && echo "Unmounted $usr for you."
351
352devsizemb="`expr $devsize / 1024 / 2`"
353maxhome="`expr $devsizemb - $TOTALMB - 1`"
354
355if [ "$devsizemb" -lt "$TOTALMB" ]
356then echo "The selected partition ($devsizemb MB) is too small."
357 echo "You'll need $TOTALMB MB at least."
358 exit 1
359fi
360
361if [ "$maxhome" -lt 1 ]
362then echo "Note: you can't have /home with that size partition."
363 maxhome=0
364fi
365
366TMPMP=/m
367mkdir $TMPMP >/dev/null 2>&1
368
369confirm=""
370
371while [ "$confirm" = "" ]
372do
373 auto=""
374 echo ""
375echo " --- Step 5: Reinstall choice ------------------------------------------"
376 if mount -r /dev/$home $TMPMP >/dev/null 2>&1
377 then umount /dev/$home >/dev/null 2>&1
378 echo ""
379 echo "You have selected an existing MINIX 3 partition."
380 echo "Type F for full installation (to overwrite entire partition)"
381 echo "Type R for a reinstallation (existing /home will not be affected)"
382 echo ""
383 echo -n "(F)ull or (R)einstall? [R] "
384 read conf
385 case "$conf" in
386 "") confirm="ok"; auto="r"; ;;
387 [Rr]*) confirm="ok"; auto="r"; ;;
388 [Ff]*) confirm="ok"; auto="" ;;
389 esac
390
391 else echo ""
392 echo "No old /home found. Doing full install."
393 echo ""
394 confirm="ok";
395 fi
396
397done
398
399rmdir $TMPMP
400
401nohome="0"
402
403homesize=""
404if [ ! "$auto" = r ]
405then
406echo ""
407echo " --- Step 6: Select the size of /home ----------------------------------"
408 while [ -z "$homesize" ]
409 do
410
411 # 20% of what is left over after / and /usr
412 # are taken.
413 defmb="`expr $maxhome / 5`"
414 if [ "$defmb" -gt "$maxhome" ]
415 then
416 defmb=$maxhome
417 fi
418
419 echo ""
420 echo "MINIX will take up $TOTALMB MB, without /home."
421 echo -n "How big do you want your /home to be in MB (0-$maxhome) ? [$defmb] "
422 read homesize
423 if [ "$homesize" = "" ] ; then homesize=$defmb; fi
424 if [ "$homesize" -lt 1 ]
425 then nohome=1
426 echo "Ok, not making a /home."
427 homesize=0
428 else
429 if [ "$homesize" -gt "$maxhome" ]
430 then echo "That won't fit!"
431 homesize=""
432 else
433 echo ""
434 echo -n "$homesize MB Ok? [Y] "
435 read ok
436 [ "$ok" = Y -o "$ok" = y -o "$ok" = "" ] || homesize=""
437 fi
438 fi
439 echo ""
440 done
441 # Homesize in sectors
442 homemb="$homesize MB"
443 homesize="`expr $homesize '*' 1024 '*' 2`"
444else
445 homepart="`devsize /dev/$home`"
446 homesize="`expr $homepart / 2 / 1024`"
447 if [ "$homesize" -gt "$maxhome" ]
448 then
449 echo "Sorry, but your /home is too big ($homesize MB) to leave enough"
450 echo "space on the rest of the partition ($devsizemb MB) for your"
451 echo "selected installation size ($TOTALMB MB)."
452 exit 1
453 fi
454 # Homesize unchanged (reinstall)
455 homesize=exist
456 homemb="current size"
457fi
458
459blockdefault=4
460
461if [ ! "$auto" = "r" ]
462then
463 echo ""
464echo " --- Step 7: Select a block size ---------------------------------------"
465 echo ""
466
467 echo "The maximum (and default) file system block size is $blockdefault KB."
468 echo "For a small disk or small RAM you may want 1 or 2 KB blocks."
469 echo ""
470
471 while [ -z "$blocksize" ]
472 do
473 echo -n "Block size in kilobytes? [$blockdefault] "; read blocksize
474 test -z "$blocksize" && blocksize=$blockdefault
475 if [ "$blocksize" -ne 1 -a "$blocksize" -ne 2 -a "$blocksize" -ne $blockdefault ]
476 then
477 warn "1, 2 or 4 please"
478 blocksize=""
479 fi
480 done
481else
482 blocksize=$blockdefault
483fi
484
485blocksizebytes="`expr $blocksize '*' 1024`"
486
487echo "
488You have selected to (re)install MINIX 3 in the partition /dev/$primary.
489The following subpartitions are now being created on /dev/$primary:
490
491 Root subpartition: /dev/$root $ROOTMB MB
492 /home subpartition: /dev/$home $homemb
493 /usr subpartition: /dev/$usr rest of $primary
494"
495 # Secondary master bootstrap.
496installboot -m /dev/$primary /usr/mdec/masterboot >/dev/null || exit
497 # Partition the primary.
498partition /dev/$primary 1 81:${ROOTSECTS}* 81:$homesize 81:0+ > /dev/null || exit
499
500echo "Creating /dev/$root for / .."
501mkfs -B $blocksizebytes /dev/$root || exit
502
503if [ "$nohome" = 0 ]
504then
505 if [ ! "$auto" = r ]
506 then echo "Creating /dev/$home for /home .."
507 mkfs -B $blocksizebytes /dev/$home || exit
508 fi
509else echo "Skipping /home"
510fi
511
512echo "Creating /dev/$usr for /usr .."
513mkfs -B $blocksizebytes /dev/$usr || exit
514
515echo ""
516echo " --- Step 8: Wait for bad block detection ------------------------------"
517echo ""
518echo "Scanning disk for bad blocks. Hit CTRL+C to stop the scan if you are"
519echo "sure that there can not be any bad blocks. Otherwise just wait."
520
521trap ': nothing;echo' 2
522
523echo ""
524echo "Scanning /dev/$root for bad blocks:"
525readall -b /dev/$root | sh
526
527if [ "$nohome" = 0 ]
528then
529 echo ""
530 echo "Scanning /dev/$home for bad blocks:"
531 readall -b /dev/$home | sh
532 fshome="home=/dev/$home"
533else fshome=""
534fi
535
536echo ""
537echo "Scanning /dev/$usr for bad blocks:"
538readall -b /dev/$usr | sh
539
540trap 2
541
542echo ""
543echo " --- Step 9: Wait for files to be copied -------------------------------"
544echo ""
545echo "This is the final step of the MINIX 3 setup. All files will now be"
546echo "copied to your hard disk. This may take a while."
547echo ""
548
549mount /dev/$usr /mnt >/dev/null || exit # Mount the intended /usr.
550
551(cd /usr || exit 1
552 if [ "$nobigsource" = 1 ]
553 then list="`ls | fgrep -v src. | fgrep -v install`"
554 else list="`ls | fgrep -v install`"
555 fi
556 for d in $list
557 do
558 cpdir -v $d /mnt/$d
559 done
560) | progressbar "$USRFILES" || exit # Copy the usr floppy.
561
562if [ -d /mnt/src.commands ]
563then mv /mnt/src.commands /mnt/src/commands
564fi
565
566if [ -d /mnt/src.contrib ]
567then mv /mnt/src.contrib /mnt/src/contrib
568fi
569 # Set inet.conf to correct driver
570if [ -n "$driver" ]
571then echo "$driverargs" >$MYLOCALRC
572fi
573
574umount /dev/$usr >/dev/null || exit # Unmount the intended /usr.
575mount /dev/$root /mnt >/dev/null || exit
576
577# Running from the installation CD.
578cpdir -vx / /mnt | progressbar "$ROOTFILES" || exit
579cp /mnt/etc/motd.install /mnt/etc/motd
580
581# Fix /var/log
582rm /mnt/var/log
583ln -s /usr/log /mnt/var/log
584
585if [ -n "$driver" ]
586then echo "eth0 $driver 0 { default; };" >/mnt/etc/inet.conf
587fi
588
589# CD remnants that aren't for the installed system
590rm /mnt/etc/issue /mnt/CD /mnt/.* 2>/dev/null
591 # Change /etc/fstab. (No swap.)
592 # ${swap:+swap=/dev/$swap}
593echo >/mnt/etc/fstab "\
594# Poor man's File System Table.
595
596root=/dev/$root
597usr=/dev/$usr
598$fshome"
599
600 # National keyboard map.
601test -n "$keymap" && cp -p "/usr/lib/keymaps/$keymap.map" /mnt/etc/keymap
602
603umount /dev/$root >/dev/null || exit # Unmount the new root.
604mount /dev/$usr /mnt >/dev/null || exit
605
606# Make bootable.
607installboot -d /dev/$root /usr/mdec/bootblock /boot/boot >/dev/null || exit
608
609edparams /dev/$root "rootdev=$root; ramimagedev=$root; minix(1,Start MINIX 3 (requires at least 16 MB RAM)) { image=/boot/image_big; boot; }; smallminix(2,Start Small MINIX 3 (intended for 8 MB RAM systems)) { image=/boot/image_small; boot; }; newminix(3,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
610pfile="/mnt/src/tools/fdbootparams"
611echo "rootdev=$root; ramimagedev=$root; save" >$pfile
612# Save name of CD drive
613cddrive="`mount | grep usr | awk '{ print $1 }' | sed 's/p.*//'`"
614echo "cddrive=$cddrive" >>/mnt/etc/rc.package
615
616bios="`echo $primary | sed -e 's/d./dX/g' -e 's/c.//g'`"
617
618if [ ! "$auto" = "r" ]
619then if mount /dev/$home /home 2>/dev/null
620 then for u in bin ast
621 do if mkdir ~$u
622 then echo " * Creating home directory for $u in ~$u"
623 cpdir /usr/ast ~$u
624 chown -R $u:operator ~$u
625 else echo " * Couldn't create ~$u"
626 fi
627 done
628 umount /dev/$home
629 fi
630fi
631
632echo "Saving random data.."
633dd if=/dev/random of=/mnt/adm/random.dat bs=1024 count=1
634
635echo "
636Please type 'shutdown' to exit MINIX 3 and enter the boot monitor. At
637the boot monitor prompt, type 'boot $bios', where X is the bios drive
638number of the drive you installed on, to try your new MINIX system.
639$biosdrivename
640
641This ends the MINIX 3 setup script. After booting your newly set up system,
642you can run the test suites as indicated in the setup manual. You also
643may want to take care of local configuration, such as securing your system
644with a password. Please consult the usage manual for more information.
645
646"
647
Note: See TracBrowser for help on using the repository browser.