Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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