Magellan Linux

Contents of /alx-src/trunk/alxinstall-ng/bin/alxinstall-ng.sh.in

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6959 - (show annotations) (download)
Wed Jul 29 09:30:23 2015 UTC (8 years, 9 months ago) by niro
File size: 25399 byte(s)
-added a fix for ASUS P4VD2-X and equivalent boards
1 #!/bin/sh
2 # $Id$
3
4 # ignore environment!
5 LC_ALL=C
6
7 MLIBDIR="@@LIBDIR@@"
8
9 # images: (get ${CDIMAGENAME})
10 source /mnt/cdrom/system/images.conf
11
12 # includes
13 source ${MLIBDIR}/functions/generic.sh
14 source ${MLIBDIR}/functions/hwdetection.sh
15
16 ### System/Config Version
17 VERSION="@@VERSION@@"
18 TITLE="alxinstall-ng - ${VERSION}"
19
20 # locations
21 CDPATH="/mnt/cdrom"
22 INSTALL_ROOT="/mnt/magellan"
23
24 # default system settings
25 # standard kernel opts
26 DEFAULT_KERNELOPTS="quiet video=1024x768"
27
28 # grub options
29 DEFAULT_GRUBLEGACYOPTS=""
30 DEFAULT_GRUB2OPTS=""
31 DEFAULT_GRUB2GFXPAYLOAD="1024x768x16,1024x768"
32
33 # default specialdevices
34 DEFAULT_FORMFACTOR="desktop"
35
36 # target filesystem
37 DEFAULT_FORMAT_FILESYSTEM="ext4"
38
39 # initialize global variables so they are exportable
40 INSTALL_METHOD=""
41 KERNELOPTS=""
42 GRUBLEGACYOPTS=""
43 GRUB2OPTS=""
44 GRUB2GFXPAYLOAD=""
45 FORMFACTOR=""
46 FORMAT_FILESYSTEM=""
47 FORMAT_FILESYSTEM_BOOTHDD=""
48 FORMAT_FILESYSTEM_ROOTHDD=""
49 FDISKPARTIONBELOW256MB=0
50 SPECIALDEVICE=""
51 FLASHDISK=0
52 ### linecount of system.tar.gz -1 !
53 CURRENTLINE=0
54 #TOTALLINES=11072 # -> now in images.conf
55
56 #################################################
57 # DIALOG BOXES #
58 #################################################
59
60 die()
61 {
62 ERROR=$1
63 RETVAL=$?
64 dialog_install_failure
65 trap_exit
66 exit 1
67 }
68
69 dialog_warning()
70 {
71 dialog \
72 --backtitle "${TITLE}" \
73 --colors \
74 --defaultno \
75 --yesno "\Z1 !!! Achtung !!! \Zn\n\n\
76 Diese Festplatte wird unwiederruflich geloescht werden.\n\n\
77 Soll ich wirklich fortfahren ?" 10 70
78 RES=$?
79 if [[ ${RES} -eq 1 ]]
80 then
81 clear
82 echo "Der Vorgang wurde abgebrochen."
83 exit 1
84 fi
85 }
86
87 dialog_setup_hdd_info()
88 {
89 case "${INSTALL_METHOD}" in
90 auto)
91 dialog_setup_hdd_info_auto
92 dialog_setup_hdd_create_partitions
93 ;;
94 normal) dialog_setup_hdd_info_normal ;;
95 single) dialog_setup_hdd_info_single ;;
96 flash) dialog_setup_hdd_info_flash ;;
97 esac
98 }
99
100 dialog_setup_hdd_info_normal()
101 {
102 local SHDD="$(echo ${HDD} | sed 's/\/dev\///')"
103
104 dialog \
105 --colors \
106 --title "[ Festplatten Partitionierung ]" \
107 --backtitle "${TITLE}" \
108 --ok-label "Weiter" \
109 --msgbox "\nBitte legen Sie 3 Partitionen an.\n\n\
110 [ \Z3${SHDD}1\Zn ] Typ: \Z3Linux\Zn mit ca. 50MB\n\
111 [ \Z3${SHDD}2\Zn ] Typ: \Z3Linux Swap\Zn mit ca. 256MB\n\
112 [ \Z3${SHDD}3\Zn ] Typ: \Z3Linux \Zn mit dem Rest (min. 256MB)\n\n\
113 Bitte ${SHDD}1 als \Z3bootable\Zn markieren." 12 81
114 }
115
116 dialog_setup_hdd_info_single()
117 {
118 local SHDD="$(echo $HDD | sed 's/\/dev\///')"
119
120 dialog \
121 --colors \
122 --title "[ Festplatten Partitionierung ]" \
123 --backtitle "${TITLE}" \
124 --ok-label "Weiter" \
125 --msgbox "\nBitte legen Sie 1 Partition an.\n\n\
126 [ \Z3${SHDD}1\Zn ] Typ: \Z3Linux\Zn mit dem gesamten Speicher\n\
127 Bitte ${SHDD}1 als \Z3bootable\Zn markieren." 12 81
128 }
129
130 dialog_setup_hdd_info_flash()
131 {
132 local SHDD="$(echo ${HDD} | sed 's/\/dev\///')"
133
134 dialog \
135 --colors \
136 --title "[ Festplatten Partitionierung ]" \
137 --backtitle "${TITLE}" \
138 --ok-label "Weiter" \
139 --msgbox "\nBitte legen Sie 2 Partitionen an.\n\n\
140 [ \Z3${SHDD}1\Zn ] Typ: \Z3Linux\Zn mit ca. 50MB\n\
141 [ \Z3${SHDD}2\Zn ] Typ: \Z3Linux \Zn mit dem Rest (min. 256MB)\n\n\
142 Bitte ${SHDD}1 als \Z3bootable\Zn markieren." 12 81
143 }
144
145 dialog_setup_hdd_info_auto()
146 {
147 local SHDD="$(echo $HDD | sed 's/\/dev\///')"
148
149 dialog \
150 --colors \
151 --title "[ Festplatten Partitionierung ]" \
152 --backtitle "${TITLE}" \
153 --ok-label "Weiter" \
154 --msgbox "\nAchtung!\n\
155 Alle Daten werden von der Disk [ \Z3${HDD}\Zn ] gelöscht!" 12 81
156 }
157
158 dialog_setup_system_menu()
159 {
160 local i
161
162 i=$(dialog \
163 --backtitle "${TITLE}" \
164 --title "[ Festplatten Partitionierung ]" \
165 --cancel-label "Abbrechen" \
166 --ok-label "Weiter" \
167 --stdout \
168 --colors \
169 --menu "\nWaehlen Sie die Installations-Methode" 14 70 6 \
170 "1" "Automatisches Setup (Empfohlen)" \
171 "" "" \
172 "" "\Z1Experten Modi:\Zn" \
173 "2" "Normale IDE-Disk (Manuell)" \
174 "3" "Normale IDE Disk (Single)" \
175 "4" "Flash SDHC/NAND oder USBStick (Manuell)")
176 RES=$?
177 [[ ${RES} -eq 1 ]] && return 1
178 if [[ ${RES} -eq 0 ]]
179 then
180 case "${i}" in
181 "1") run_install auto ;;
182 "2") run_install normal ;;
183 "3") run_install single ;;
184 "4") run_install flash ;;
185 "") dialog_setup_system_menu;;
186 esac
187 fi
188 }
189
190 dialog_hardware_detection()
191 {
192 local i
193 local hwtmp
194
195 if [ -x $(type -P mktemp) ]
196 then
197 hwtmp="$(mktemp)"
198 else
199 hwtmp="/tmp/hwtmp.sh"
200 fi
201
202 run_hardware_detection_disks
203
204 echo "dialog \\" > ${hwtmp}
205 echo "--backtitle \"${TITLE}\" \\" >> ${hwtmp}
206 echo "--ok-label \"Weiter\" \\" >> ${hwtmp}
207 echo "--stdout \\" >> ${hwtmp}
208 echo "--colors \\" >> ${hwtmp}
209 echo "--msgbox \"Gefundene Hardware:\n\n \\" >> ${hwtmp}
210 echo " Festplatten:\n \\" >> ${hwtmp}
211
212 if [[ ! -z ${ALL_DISKS} ]]
213 then
214 for i in ${ALL_DISKS}
215 do
216 echo " \\Z3${i}\\Zn\n \\" >> ${hwtmp}
217 done
218 fi
219
220 if [[ ! -z ${ALL_CDROMS} ]]
221 then
222 echo " \n \\" >> ${hwtmp}
223 echo " CDROM Laufwerke:\n \\" >> ${hwtmp}
224 for i in ${ALL_CDROMS}
225 do
226 echo " \\Z3${i}\\Zn\n \\" >> ${hwtmp}
227 done
228 fi
229
230 # other devices
231 run_hardware_detection
232 case "${SPECIALDEVICE}" in
233 zotac*) echo " \n \\Z2Zotac Device erkannt.\\Zn \\" >> ${hwtmp} ;;
234 rangee) echo " \n \\Z2Rangee Device erkannt.\\Zn \\" >> ${hwtmp} ;;
235 maxdata) echo " \n \\Z2Maxdata Device erkannt.\\Zn \\" >> ${hwtmp} ;;
236 i845) echo " \n \\Z2Intel i845 Device erkannt.\\Zn \\" >> ${hwtmp} ;;
237 *) echo " \n \\ZnStandard Device erkannt.\\Zn \\" >> ${hwtmp} ;;
238 esac
239 if [[ ${FORMFACTOR} = laptop ]]
240 then
241 echo " \n \\ZnFormfactor Laptop, Powersave Modus 'ondemand' wird aktiviert.\\Zn \\" >> ${hwtmp}
242 fi
243 if [[ ${FLASHDISK} = 1 ]]
244 then
245 echo " \n \\ZnFlash Speicher erkannt, F2FS wird als Dateisystem bei der\\Zn \\" >> ${hwtmp}
246 echo " \n \\Znautomatischen Installation benutzt.\\Zn \\" >> ${hwtmp}
247 fi
248
249 echo " \" 14 70" >> ${hwtmp}
250 chmod a+x ${hwtmp}
251 ${hwtmp}
252
253 # remove tmp file
254 if [[ -f ${hwtmp} ]]
255 then
256 rm ${hwtmp}
257 fi
258 }
259
260 dialog_setup_hdd_partitions()
261 {
262 local i
263
264 if [[ -z ${ALL_DISKS} ]]
265 then
266 dialog \
267 --backtitle "${TITLE}" \
268 --ok-label "Beenden" \
269 --msgbox "Kein geeignetes Laufwerk gefunden.\nDie Installation ist fehlgeschlagen." 6 70
270 exit 1
271 else
272
273 echo "dialog \\" > /tmp/hddtmp.sh
274 echo "--backtitle \"${TITLE}\" \\" >> /tmp/hddtmp.sh
275 echo "--ok-label \"Weiter\" \\" >> /tmp/hddtmp.sh
276 echo "--cancel-label \"Beenden\" \\" >> /tmp/hddtmp.sh
277 echo "--stdout \\" >> /tmp/hddtmp.sh
278 echo "--menu \"Installations Laufwerk auswaehlen:\" 10 70 3 \\" >> /tmp/hddtmp.sh
279
280 for i in ${ALL_DISKS}
281 do
282 echo "\"${i}\" \"\" \\" >> /tmp/hddtmp.sh
283 done
284 echo -e "\n" >> /tmp/hddtmp.sh
285
286 chmod a+x /tmp/hddtmp.sh
287 HDD="$(/tmp/hddtmp.sh)"
288 RES=$?
289 [[ ${RES} -eq 1 ]] && return 1
290 if [[ ${RES} -eq 0 ]]
291 then
292 dialog_setup_hdd_info
293 setup_hdd_partitions
294 fi
295 fi
296 }
297
298 dialog_setup_hdd_create_partitions()
299 {
300 dialog \
301 --backtitle "${TITLE}" \
302 --infobox "Erstelle Disk Partitionen ..." 3 70
303 }
304
305 dialog_setup_hdd_format()
306 {
307 dialog \
308 --backtitle "${TITLE}" \
309 --infobox "Erstelle Datei-Systeme ..." 3 70
310 }
311
312 dialog_install_settings()
313 {
314 dialog \
315 --backtitle "${TITLE}" \
316 --infobox "Speichere System-Einstellungen ..." 3 70
317 }
318
319 dialog_install_system_image()
320 {
321 dialog \
322 --backtitle "${TITLE}" \
323 --gauge "Kopiere System-Image ..." 6 80
324 }
325
326 dialog_install_meter()
327 {
328 while [[ ${CURRENTLINE} != ${TOTALLINES} ]]
329 do
330 CURRENTLINE=$(grep -c . /tmp/install.log)
331 PERCENT=$(( ${CURRENTLINE} * 100 / ${TOTALLINES}))
332 echo ${PERCENT}
333 sleep 1
334 done
335 rm -f /tmp/install.log
336 return 0
337 }
338
339 dialog_install_bootsector()
340 {
341 dialog \
342 --backtitle "${TITLE}" \
343 --infobox "Schreibe den Bootsektor ..." 3 70
344 }
345
346 dialog_install_successful()
347 {
348 dialog \
349 --backtitle "${TITLE}" \
350 --colors \
351 --msgbox "Die Installation war \Z2erfolgreich\Zn." 5 81
352 }
353
354 dialog_install_failure()
355 {
356 dialog \
357 --backtitle "${TITLE}" \
358 --colors \
359 --msgbox "Die Installation ist \Z1Fehlgeschlagen\Zn.\n\n\
360 Fehler bei ${ERROR}, RetVal: ${RETVAL} \
361 " 10 81
362 }
363
364 dialog_main()
365 {
366 METHOD=0
367
368 while [[ ${METHOD} -le 2 ]]
369 do
370 METHOD=$(dialog \
371 --backtitle "${TITLE}" \
372 --no-cancel \
373 --ok-label "Weiter" \
374 --stdout \
375 --menu "Konfiguration" 14 70 6 \
376 "1" "AutoSta_LX installieren" \
377 "2" "Uebersicht gefundener Laufwerke" \
378 "3" "Beenden und neustarten" \
379 "4" "Beenden und eine Shell starten")
380 RES=$?
381 [[ ${RES} -eq 1 ]] && exit 1
382 if [[ ${RES} -eq 0 ]]
383 then
384 case ${METHOD} in
385 "1") dialog_setup_system_menu ;;
386 "2") dialog_hardware_detection ;;
387 "3") install_do_reboot ;;
388 "4") /bin/bash --login -i ;;
389 esac
390 fi
391 done
392 }
393
394 #################################################
395 # Install Commands #
396 #################################################
397 run_hardware_detection()
398 {
399 local hwinfo
400 hwinfo="$(hwinfo --bios --storage --pci --gfxcard --sys)"
401
402 # check for special devices/clients:
403 # if zotac a zotac and the disk is a removeable device, then add rootdelay to kernelcmd
404 local removable=0
405 if [[ ! -z $(echo "${hwinfo}" | grep -i zotac) ]]
406 then
407 for i in /sys/block/[hs]d*/removable
408 do
409 if [[ $(< ${i}) = 1 ]]
410 then
411 removable=1
412 # we assume that all removable disks are flash disks
413 export FLASHDISK=1
414 fi
415 done
416
417 # only add this for grub legacy, grub2 detect these settings on its own
418 export GRUBLEGACYOPTS="rootdelay=8"
419 # there are two zotac types in the wild, nvidia based gfx and intel
420 if [[ ! -z $(echo "${hwinfo}" | grep -i nouveau) ]]
421 then
422 export SPECIALDEVICE="zotac_nvidia"
423 else
424 export SPECIALDEVICE="zotac_intel"
425 fi
426 fi
427
428 # check for special devices/clients:
429 # if a rangee and disk ist smaller then 256mb move partion one block further ahead
430 if [[ ! -z $(echo "${hwinfo}" | grep -i CLE266) ]]
431 then
432 # for a rangee always define partion startblock +1
433 export FDISKPARTIONBELOW256MB="1"
434 export SPECIALDEVICE="rangee"
435 export GRUBLEGACYOPTS=""
436 fi
437
438 # check for special devices/clients:
439 # check for maxdata / i810/ i815 Chipsets and disable KMS and use i810fb frambuffer
440 if [[ ! -z $(echo "${hwinfo}" | grep -i i810) ]] || [[ ! -z $(echo "${hwinfo}" | grep -i i815) ]]
441 then
442 export SPECIALDEVICE="maxdata"
443 export GRUBLEGACYOPTS=""
444 fi
445
446 # check for i845 Chipsets and disable KMS and use 915 drm driver
447 if [[ ! -z $(echo "${hwinfo}" | grep -i i845) ]]
448 then
449 export SPECIALDEVICE="i845"
450 # unset default video=1024x768 opt or the drm driver breaks
451 export KERNELOPTS="quiet"
452 export GRUBLEGACYOPTS=""
453 # enable full kms support
454 export GRUB2GFXPAYLOAD="keep"
455 fi
456
457 # check for radeon gfxcards
458 if [[ ! -z $(echo "${hwinfo}" | grep -i radeon) ]]
459 then
460 # enable full kms support
461 export GRUB2GFXPAYLOAD="keep"
462 fi
463
464 # requires nomsi to prevent massive IRQ error spam
465 # see: http://ubuntuforums.org/showthread.php?t=1234983
466 if [[ ! -z $(echo "${hwinfo}" | grep -i 'ASUS P5VD2-X') ]] ||
467 [[ ! -z $(echo "${hwinfo}" | grep -i 'VT8237') ]] ||
468 [[ ! -z $(echo "${hwinfo}" | grep -i 'VX700') ]]
469 then
470 export SPECIALDEVICE="P5VD2-X/VT8237/VX700"
471 export KERNELOPTS="${KERNELOPTS} pci=nomsi,noaer"
472 fi
473
474 # check for special devices/clients:
475 # check for laptops and activate cpufreq scaling
476 if [[ $(echo "${hwinfo}" | grep 'Formfactor:' | sed 's:.*Formfactor\:\ \"\(.*\)\":\1:') = laptop ]]
477 then
478 export FORMFACTOR="laptop"
479 export KERNELOPTS="${KERNELOPTS} cpufreq.governor=ondemand"
480 fi
481 }
482
483 run_hardware_detection_disks()
484 {
485 local bootdev
486
487 # all disks but exclude ramdisks
488 export ALL_DISKS=$(get_hwinfo disk | sed '/\/dev\/ram[0-9].*/d')
489 # remove the boot device from ALL_DISKS if it was an usbstick
490 if [[ $(grep '[[:space:]]/mnt/cdrom[[:space:]]' /proc/mounts | cut -d' ' -f3) != iso9660 ]]
491 then
492 bootdev="$(grep '[[:space:]]/mnt/cdrom[[:space:]]' /proc/mounts | cut -d' ' -f1 | sed 's:[0-9]::g')"
493 export ALL_DISKS=$(echo "${ALL_DISKS}" | grep -v "${bootdev}")
494 fi
495 export ALL_CDROMS="$(get_hwinfo cdrom)"
496 }
497
498 hdd_size_below_256mb()
499 {
500 local hdd="$1"
501 local size
502 local retval
503 [[ -z ${hdd} ]] && die "Error: get_hdd_size() no \$hdd given!"
504
505 size=$(fdisk -l ${hdd} | grep "Disk.*${hdd}" | sed 's:.*,\ \(.*\)\ byte.*:\1:')
506 if [[ ${size} -le 257000000 ]]
507 then
508 retval="0"
509 else
510 retval="1"
511 fi
512
513 return "${retval}"
514 }
515
516 setup_hdd_partitions()
517 {
518 case "${INSTALL_METHOD}" in
519 auto)
520 if [[ ${FLASHDISK} = 1 ]]
521 then
522 BOOTHDD="${HDD}1"
523 SWAPHDD=""
524 ROOTHDD="${HDD}2"
525 else
526 BOOTHDD=""
527 SWAPHDD=""
528 ROOTHDD="${HDD}1"
529 fi
530 ;;
531
532 normal)
533 BOOTHDD="${HDD}1"
534 SWAPHDD="${HDD}2"
535 ROOTHDD="${HDD}3"
536 ;;
537
538 single)
539 BOOTHDD=""
540 SWAPHDD=""
541 ROOTHDD="${HDD}1"
542 ;;
543
544 flash)
545 BOOTHDD="${HDD}1"
546 SWAPHDD=""
547 ROOTHDD="${HDD}2"
548 ;;
549 esac
550
551 if [[ ${INSTALL_METHOD} = auto ]]
552 then
553 # run this only if FDISKPARTITIONBELOW256MB is not already 1
554 if [[ ${FDISKPARTIONBELOW256MB} != 1 ]]
555 then
556 if hdd_size_below_256mb ${HDD}
557 then
558 FDISKPARTIONBELOW256MB=1
559 else
560 FDISKPARTIONBELOW256MB=0
561 fi
562 fi
563
564 ## delete disk
565 dd if=/dev/zero of=${HDD} count=1 &> /dev/null || die
566
567 if [[ ${FLASHDISK} = 1 ]]
568 then
569 if [[ ${FDISKPARTIONBELOW256MB} = 1 ]]
570 then
571 ## setup one bootable partition
572 # 1. n= new disk
573 # 2. p= primary disk
574 # 3. 1= first partition
575 # 4. 2= default sector start // small disk needs more space for grub2 mbr sector
576 # 5. ''= defaul sector end
577 # 6. a= bootable flag
578 # 7. 1= boot flag for partition 1
579 # 8. n= new disk
580 #10. p= primary disk
581 #11. 2= second partition
582 #12. ''= default sector start
583 #13. ''= defaul sector end
584 #14. w= write/quit
585 fdisk ${HDD} &> /dev/null << EOF
586 n
587 p
588 1
589 2
590 +50M
591 a
592 1
593 n
594 p
595 2
596
597
598 w
599 EOF
600 else
601 ## setup one bootable partition
602 # 1. n= new disk
603 # 2. p= primary disk
604 # 3. 1= first partition
605 # 4. ''= default sector start
606 # 5. ''= defaul sector end
607 # 6. a= bootable flag
608 # 7. 1= boot flag for partition 1
609 # 8. n= new disk
610 #10. p= primary disk
611 #11. 2= second partition
612 #12. ''= default sector start
613 #13. ''= defaul sector end
614 #14. w= write/quit
615 fdisk ${HDD} &> /dev/null << EOF
616 n
617 p
618 1
619
620 +50M
621 a
622 1
623 n
624 p
625 2
626
627
628 w
629 EOF
630 fi
631 else
632 if [[ ${FDISKPARTIONBELOW256MB} = 1 ]]
633 then
634 ## setup one bootable partition
635 #1. n= new disk
636 #2. p= primary disk
637 #3. 1= first partition
638 #4. 2= default sector start // small disk needs more space for grub2 mbr sector
639 #5. ''= defaul sector end
640 #6. a= bootable flag
641 #7. 1= boot flag for partition 1
642 #8. w= write/quit
643 fdisk ${HDD} &> /dev/null << EOF
644 n
645 p
646 1
647 2
648
649 a
650 1
651 w
652 EOF
653 else
654 ## setup one bootable partition
655 #1. n= new disk
656 #2. p= primary disk
657 #3. 1= first partition
658 #4. ''= default sector start
659 #5. ''= defaul sector end
660 #6. a= bootable flag
661 #7. 1= boot flag for partition 1
662 #8. w= write/quit
663 fdisk ${HDD} &> /dev/null << EOF
664 n
665 p
666 1
667
668
669 a
670 1
671 w
672 EOF
673 fi
674 fi
675 else
676 ## hdds partitionieren manuell
677 cfdisk ${HDD} || die
678 fi
679 }
680
681 setup_hdd_format()
682 {
683 install -d /tmp
684 :> /tmp/format.log
685
686 if [[ -n ${SWAPHDD} ]]
687 then
688 mkswap ${SWAPHDD} || die
689 fi
690 if [[ -n ${BOOTHDD} ]]
691 then
692 mkfs.${FORMAT_FILESYSTEM_BOOTHDD} ${BOOTHDD} &> /tmp/format.log || die
693 fi
694 if [[ -n ${ROOTHDD} ]]
695 then
696 mkfs.${FORMAT_FILESYSTEM_ROOTHDD} ${ROOTHDD} &> /tmp/format.log || die
697 fi
698 }
699
700 install_mount_rootfs()
701 {
702 local opts
703
704 if [[ -n ${SWAPHDD} ]]
705 then
706 swapon ${SWAPHDD} || die
707 fi
708 if [[ -n ${ROOTHDD} ]]
709 then
710 mount -t ${FORMAT_FILESYSTEM_ROOTHDD} ${ROOTHDD} ${INSTALL_ROOT} || die
711 fi
712 if [[ -n ${BOOTHDD} ]]
713 then
714 install -d ${INSTALL_ROOT}/boot || die
715 mount -t ${FORMAT_FILESYSTEM_BOOTHDD} ${BOOTHDD} ${INSTALL_ROOT}/boot || die
716 fi
717
718 cd ${INSTALL_ROOT} || die
719 }
720
721 install_system_image()
722 {
723 tar xvjpf ${CDPATH}/system/${CDIMAGENAME} -C ${INSTALL_ROOT}
724 }
725
726 install_bootsector_chroot()
727 {
728 local my_roothdd
729 local grubconf=${INSTALL_ROOT}/boot/grub/grub.conf
730 local grub2conf=/boot/grub/grub.cfg
731 local CONFIG
732
733 # check for grub2
734 if [[ -f ${INSTALL_ROOT}/sbin/grub-mkconfig ]]
735 then
736 # needed by grub-mkconfig on the first run
737 if [[ ! -f ${INSTALL_ROOT}/boot/grub/video.lst ]]
738 then
739 install -m0644 ${INSTALL_ROOT}/lib/grub/*/video.lst ${INSTALL_ROOT}/boot/grub/video.lst || die
740 fi
741
742 # set kernelopts
743 if [[ -f ${INSTALL_ROOT}/etc/conf.d/grub ]]
744 then
745 sed -i "s:^\(export GRUB_CMDLINE_LINUX_DEFAULT=\).*:\1\"${KERNELOPTS}\":" ${INSTALL_ROOT}/etc/conf.d/grub || die
746 sed -i "s:^\(export GRUB_GFXPAYLOAD_LINUX=\).*:\1\"${GRUB2GFXPAYLOAD}\":" ${INSTALL_ROOT}/etc/conf.d/grub || die
747 else
748 CONFIG=${INSTALL_ROOT}/etc/conf.d/grub
749 clearconfig
750 addconfig "export GRUB_CMDLINE_LINUX_DEFAULT=\"${KERNELOPTS}\""
751 addconfig "export GRUB_GFXPAYLOAD_LINUX=\"${GRUB2GFXPAYLOAD}\""
752 fi
753 CONFIG=${INSTALL_ROOT}/.installrc
754 clearconfig
755 addconfig 'grub-mkdevicemap'
756 addconfig "LC_ALL=C grub-mkconfig -o ${grub2conf} &> /dev/null"
757 addconfig "grub-install --no-floppy ${HDD} &> /dev/null"
758 addconfig "exit 0"
759
760 # grub-legacy
761 else
762 ### grubconf schreiben
763 source ${INSTALL_ROOT}/boot/kernelversion
764
765 #for alx only
766 if [ -e ${INSTALL_ROOT}/etc/alx_version ]
767 then
768 OLD_ALXVER="${ALXVER}"
769 source ${INSTALL_ROOT}/etc/alx_version
770 KRNVER="ALX-${ALXVER}"
771 ALXVER="${OLD_ALXVER}"
772 fi
773
774 [[ -z ${KRNVER} ]] && KRNVER="AutoSta_LX"
775 [[ -z ${KRNINITRD} ]] && KRNINITRD="initrd"
776 [[ -z ${KRNIMG} ]] && KRNIMG="vmlinuz"
777
778 # uuid support
779 if is_uuid_supported
780 then
781 my_roothdd="UUID=$(get_uuid ${ROOTHDD})"
782 else
783 my_roothdd="${ROOTHDD}"
784 fi
785
786 CONFIG="${grubconf}"
787 clearconfig
788 addconfig "default 0"
789 addconfig "timeout 3"
790 # using current root password
791 addconfig "password --md5 $(cat ${INSTALL_ROOT}/etc/shadow | grep root | cut -d: -f2)"
792 addconfig
793 addconfig "# normal boot"
794 addconfig "title ${KRNVER}"
795 addconfig "root (hd0,0)"
796 addconfig "kernel /boot/${KRNIMG} root=${my_roothdd} ${KERNELOPTS} ${GRUBLEGACYOPTS}"
797 if is_initrd_supported
798 then
799 addconfig "initrd /boot/${KRNINITRD}"
800 fi
801 addconfig
802 addconfig "# admin boot"
803 addconfig "title ${KRNVER} - Re-run hardware-detection"
804 addconfig "lock"
805 addconfig "root (hd0,0)"
806 addconfig "kernel /boot/${KRNIMG} root=${my_roothdd} ${KERNELOPTS} ${GRUBLEGACYOPTS} hardware-auto-detection"
807 if is_initrd_supported
808 then
809 addconfig "initrd /boot/${KRNINITRD}"
810 fi
811 addconfig
812 addconfig "title ${KRNVER} - Reset *all* local settings"
813 addconfig "lock"
814 addconfig "root (hd0,0)"
815 addconfig "kernel /boot/${KRNIMG} root=${my_roothdd} ${KERNELOPTS} ${GRUBLEGACYOPTS} alx-reset-settings"
816 if is_initrd_supported
817 then
818 addconfig "initrd /boot/${KRNINITRD}"
819 fi
820
821 # write bootsector chrooted (lfs/magellan)
822 CONFIG=${INSTALL_ROOT}/.installrc
823 clearconfig
824 addconfig '/usr/sbin/grub --no-floppy --batch << "EOF" 1> /dev/null 2> /dev/null'
825 addconfig 'root (hd0,0)'
826 addconfig 'setup (hd0)'
827 addconfig 'quit'
828 addconfig 'EOF'
829 addconfig 'exit 0'
830 fi
831
832 ## enter chroot
833 enter_chroot_installrc
834 }
835
836 is_initrd_supported()
837 {
838 # only generate initrds if the cmd exists
839 [[ -x ${INSTALL_ROOT}/sbin/mkinitrd ]] && return 0
840 return 1
841 }
842
843 install_initrd_chroot()
844 {
845 local CONFIG
846
847 # only generate initrds if the cmd exists
848 is_initrd_supported || return 0
849
850 FSMODS="${FORMAT_FILESYSTEM_BOOTHDD} ${FORMAT_FILESYSTEM_ROOTHDD}"
851 DISKMODS="sd_mod"
852 OLDPATAMODS="amd74xx piix sis5513 via82cxxx"
853 PATAMODS="ata_piix pata_amd pata_mpiix pata_oldpiix pata_sis pata_via"
854 SATAMODS="sata_via sata_sis sata_nv"
855 DRMMODS="i915 mga nouveau r128 radeon savage sis tdfx ttm via"
856 OTHERMODS=""
857 case ${SPECIALDEVICE} in
858 zotac_intel|i845) FBMODS=""; DRMMODS="i915" ;;
859 zotac_nvidia) FBMODS=""; DRMMODS="nouveau" ;;
860 rangee) FBMODS="" ;; ## fallback to vesafb, viafb does not run on all CLE266 boards
861 # not working with kms enabled drivers -> segfaults
862 #maxdata) FBMODS="i810fb" ;; ## check for maxdata / i810/ i815 Chipsets and disable KMS and use i810fb frambuffer
863 maxdata) FBMODS="" ;;
864 *) FBMODS="uvesafb" ;;
865 esac
866
867 if [[ ${FORMFACTOR} = laptop ]]
868 then
869 OTHERMODS="acpi-cpufreq cpufreq_ondemand cpufreq_conservative cpufreq_powersave"
870 fi
871
872 # install an appropriate uvesafb.conf
873 CONFIG=${INSTALL_ROOT}/etc/modprobe.d/uvesafb.conf
874 clearconfig
875 addconfig "options uvesafb mode_option=1024x768-32@60 scroll=ywrap"
876
877 # install an appropriate viafb.conf
878 CONFIG=${INSTALL_ROOT}/etc/modprobe.d/viafb.conf
879 clearconfig
880 addconfig "options viafb viafb_mode=1024x768 viafb_refresh=60"
881
882 # install an appropriate i810fb.conf
883 CONFIG=${INSTALL_ROOT}/etc/modprobe.d/i810fb.conf
884 clearconfig
885 addconfig "options i810fb xres=1024 yres=768 bpp=16 mtrr=1 hsync1=30 hsync2=62 vsync1=30 vsync2=60"
886
887 CONFIG=${INSTALL_ROOT}/.installrc
888 clearconfig
889 addconfig "echo \"MODULES=\\\"${FSMODS} ${DISKMODS} ${OLDATAMODS} ${PATAMODS} ${SATAMODS} ${DRMMODS} ${FBMODS} ${OTHERMODS}\\\"\" > /etc/conf.d/mkinitrd"
890 addconfig "mkinitrd -f /boot/$(readlink /boot/initrd) $(readlink /boot/vmlinuz | sed "s:kernel-::g") > /dev/null"
891 addconfig "exit 0"
892 ## enter chroot
893 enter_chroot_installrc
894 }
895
896 is_uuid_supported()
897 {
898 # f2fs needs special treatments as the old busybox does not support this fs
899 # use the blkid from util-linux instead of busybox
900 if [[ ${FORMAT_FILESYSTEM} = f2fs ]]
901 then
902 if [[ -x $(type -P blkid) ]]
903 then
904 return 0
905 fi
906 else
907 if [[ -x $(type -P busybox.mkinitrd) ]]
908 then
909 # only detect uuids if supported
910 if [[ ! -z $(busybox.mkinitrd | grep blkid) ]]
911 then
912 return 0
913 fi
914 fi
915 fi
916
917 return 1
918 }
919
920 get_uuid()
921 {
922 local UUID
923 local SEC_TYPE
924 local TYPE
925 local blkidcmd
926
927 local dev="$1"
928 [[ -z ${dev} ]] && die "no dev given"
929
930 # check if given device is already an UUID
931 if [[ ${dev/UUID=/}x != ${dev}x ]]
932 then
933 eval "${dev}"
934 else
935 # f2fs needs special treatments as the old busybox does not support this fs
936 # use the blkid from util-linux instead of busybox
937 if [[ ${FORMAT_FILESYSTEM} = f2fs ]]
938 then
939 blkidcmd="blkid"
940 else
941 blkidcmd="busybox.mkinitrd blkid"
942 fi
943 eval $(${blkidcmd} ${dev} | grep "${dev}:" | sed 's/.*:\ //')
944 fi
945 echo "${UUID}"
946 }
947
948 install_system_settings()
949 {
950 local CONFIG
951 local fstype
952
953 # write fstab
954 CONFIG=${INSTALL_ROOT}/etc/fstab
955 clearconfig
956
957 if [[ -n ${BOOTHDD} ]]
958 then
959 if is_uuid_supported
960 then
961 addconfig -e "UUID=$(get_uuid ${BOOTHDD})\t/boot\t${FORMAT_FILESYSTEM_BOOTHDD}\tnoatime,noauto\t1 1"
962 else
963 addconfig -e "${BOOTHDD}\t/boot\t${FORMAT_FILESYSTEM_BOOTHDD}\tnoatime,noauto\t1 1"
964 fi
965 fi
966
967 if [[ -n ${ROOTHDD} ]]
968 then
969 if is_uuid_supported
970 then
971 addconfig -e "UUID=$(get_uuid ${ROOTHDD})\t/\t${FORMAT_FILESYSTEM_ROOTHDD}\tnoatime\t0 0"
972 else
973 addconfig -e "${ROOTHDD}\t/\t${FORMAT_FILESYSTEM_ROOTHDD}\tnoatime\t0 0"
974 fi
975 fi
976
977 # not needed busybox loads all with swapon -a, even if not mentioned in fstab
978 #addconfig -e "UUID='$(get_uuid ${SWAPHDD})'\tswap\tswap\tpri=1\t0 0"
979 addconfig -e "proc\t/proc\tproc\tdefaults\t0 0"
980 addconfig -e "shm\t/dev/shm\ttmpfs\tdefaults\t0 0"
981
982 # install network config skeleton
983 install -m0644 ${INSTALL_ROOT}/etc/alxconfig-ng/skel/net/net.eth0 ${INSTALL_ROOT}/etc/conf.d/ || die
984
985 # intel framebufer quirk
986 if [[ -e /proc/fb ]]
987 then
988 if [[ ! -z $(grep 'inteldrmfb' /proc/fb) ]]
989 then
990 fbdev=$(grep 'inteldrmfb' /proc/fb | sed 's:\([0-9]\).*:\1:')
991 if [[ ${fbdev} != 0 ]]
992 then
993 sed -i "s:^\(SPLASH_DEV=\).*:\1\"/dev/fb${fbdev}\":" ${INSTALL_ROOT}/etc/splash/splash.conf || die
994 fi
995 fi
996 fi
997 }
998
999 install_umount_rootfs()
1000 {
1001 cd /
1002 if [[ -n ${BOOTHDD} ]]
1003 then
1004 umount ${INSTALL_ROOT}/boot || die
1005 fi
1006 if [[ -n ${ROOTHDD} ]]
1007 then
1008 umount ${INSTALL_ROOT} || die
1009 fi
1010 if [[ -n ${SWAPHDD} ]]
1011 then
1012 swapoff ${SWAPHDD} || die
1013 fi
1014 }
1015
1016 install_do_reboot()
1017 {
1018 reboot
1019 }
1020
1021 #################################################
1022 # Install Main Scripts #
1023 #################################################
1024
1025 run_install()
1026 {
1027 local method="$1"
1028
1029 # setup install environment
1030 export KERNELOPTS="${DEFAULT_KERNELOPTS}"
1031 export GRUBLEGACYOPTS="${GRUBLEGACYOPTS}"
1032 export GRUB2OPTS="${GRUB2OPTS}"
1033 export GRUB2GFXPAYLOAD="${DEFAULT_GRUB2GFXPAYLOAD}"
1034 export FORMFACTOR="${DEFAULT_FORMFACTOR}"
1035 export FORMAT_FILESYSTEM="${DEFAULT_FORMAT_FILESYSTEM}"
1036
1037 # run hardware detections first to get the disktypes detected
1038 dialog_hardware_detection
1039
1040 case "${method}" in
1041 auto)
1042 if [[ ${FLASHDISK} = 1 ]]
1043 then
1044 export FORMAT_FILESYSTEM="f2fs"
1045 export FORMAT_FILESYSTEM_BOOTHDD="ext2"
1046 export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}"
1047 else
1048 export FORMAT_FILESYSTEM_BOOTHDD=""
1049 export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}"
1050 fi
1051 export INSTALL_METHOD="${method}"
1052 ;;
1053 normal)
1054 export FORMAT_FILESYSTEM_BOOTHDD="${FORMAT_FILESYSTEM}"
1055 export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}"
1056 export INSTALL_METHOD="${method}"
1057 ;;
1058 single)
1059 export FORMAT_FILESYSTEM_BOOTHDD=""
1060 export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}"
1061 export INSTALL_METHOD="${method}"
1062 ;;
1063 flash)
1064 export FORMAT_FILESYSTEM="f2fs"
1065 export FORMAT_FILESYSTEM_BOOTHDD="ext2"
1066 export FORMAT_FILESYSTEM_ROOTHDD="${FORMAT_FILESYSTEM}"
1067 export INSTALL_METHOD="${method}"
1068 ;;
1069 *)
1070 die "Unknown install method '${method}', aborting."
1071 ;;
1072 esac
1073
1074 dialog_setup_hdd_partitions
1075 dialog_setup_hdd_format
1076 setup_hdd_format > /dev/null
1077 install_mount_rootfs
1078 (install_system_image > /tmp/install.log) 2> /tmp/install_errors.log | dialog_install_meter | dialog_install_system_image
1079
1080 dialog_install_settings
1081 sleep 1
1082 install_system_settings
1083 install_initrd_chroot
1084
1085 dialog_install_bootsector
1086 install_bootsector_chroot
1087
1088 install_umount_rootfs
1089 dialog_install_successful
1090 }
1091
1092 # set some proper traps
1093 trap "trap_exit" SIGINT SIGQUIT
1094
1095 dialog_main
1096
1097 exit 0