#!/bin/sh #---------------------------------------------------------------------------- # /linuxrc2 - installer script of inst.tar.gz # # Creation: 2001-10-15 fm # Last Update: $Id$ # # Copyright (c) 2007 The eisfair Team # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- debug=0 #---------------------------------------------------------------------------- # definition #---------------------------------------------------------------------------- mecho () { _colecho_tcol="" _colecho_bkgcol="" _colecho_tmode="" _colecho_flags="" while [ 1 ] do case "$1" in -n) _colecho_flags='-n' shift ;; -std) _colecho_tcol="" _colecho_bkgcol="" _colecho_tmode="" shift ;; -info) _colecho_tcol="\033[32m" _colecho_bkgcol="" _colecho_tmode="" shift ;; -warn) _colecho_tcol="\033[33m" _colecho_bkgcol="\033[40m" _colecho_tmode="\033[1m" shift ;; -error) _colecho_tcol="\033[31m" _colecho_bkgcol="\033[47m" _colecho_tmode="\033[1m\033[7m" shift ;; *) break ;; esac done echo -e $_colecho_flags "$_colecho_tcol$_colecho_bkgcol$_colecho_tmode$1\033[0m" } change_pw() { local user=$1 echo mecho -info "Setting password for user $user:" while ! $rootdir/usr/sbin/chroot $rootdir passwd $user do mecho -error "Passwords does not match or invalid input" done } exitFailure() { echo mecho -info "Sorry. Exit." while [ 1 ] do read dummy done exit 1 } getDevices() { local prefix=$1 local quantity=$2 local device_list local alphabet="abcdefghijklmnopqrstuvwxyz" local idx=0 while [ $idx -lt $quantity ] do device_list="$device_list $prefix${alphabet:$idx:1}" idx=`expr $idx + 1` done echo "$device_list" } replaceBaseVariable() { local variableName=$1 local variableValue=$2 sed "s/$variableName='[^']*'/$variableName='$variableValue'/" $base > $base.$$ cp $base.$$ $base rm $base.$$ } installerAsk() { local question="$1" local defaultValue="$2" local rangeType="$3" local range="" local answer="" defaultValueText=" [$defaultValue]" case "x$rangeType" in xyesno) range="(y/n)" ;; xnoyes) range="(y/n)" defaultValue="" defaultValueText="" ;; esac exec 3>&1 # save stdout exec 1>&2 # redirect stdout to stderr. The return value of this will be printed to stdout while [ 1 ] do echo -n "$question ${range}${defaultValueText}: " read answer if [ -z "$answer" -a -n "$defaultValue" ] then answer="$defaultValue" fi case "x$rangeType" in xyesno|xnoyes) case "x$answer" in xy*|xz*|xY*|xZ*) answer="yes" break ;; xn*|xN*) answer="no" break ;; x*) echo "please enter Y or N " ;; esac ;; *) break ;; esac done exec 1>&3 # restore stdout echo $answer } isCompaqDevice() { echo "$1" | grep -q 'c[0-9]d[0-9]' return $? } # check if the type of partition from list checkPartitionTypeIs() { local AllowPartTypes="$1" case $AllowPartTypes in *SWAP*) if echo "$partitionList" | grep $device | grep -q '82 Linux swap' then return 0 fi esac case $AllowPartTypes in *LINUX*) if echo "$partitionList" | grep $device | grep -q '83 Linux' then return 0 fi esac case $AllowPartTypes in *LVM*) if echo "$partitionList" | grep $device | grep -q '8e Linux LVM' then return 0 fi esac mecho -error "$device is no valid partition type of ${AllowPartTypes}. Please try again." return 1 } askForPartitionIndex() { local type=$1 local userChoicePartitionIndex local userChoiceOk=false local allowNoneString="" local firstIndex=1 eval defaultPartitionIndex='$defaultPartitionIndex_'$type exec 3>&1 # save stdout exec 1>&2 # redirect stdout to stderr. The return value of this will be printed to stdout case "$type" in boot|data) # data and boot partitions are optional allowNoneString=", 0=none" firstIndex=0 break ;; swap) foundSwapPartitions=`echo "$partitionList" | grep '82 Linux swap' | tail -n1` if [ -n "$foundSwapPartitions" ] then defaultPartitionIndex=`echo $foundSwapPartitions | cut -f1 -d" " | sed 's/.*\([0-9]\)/\1/g'` else mecho -error "No swap partition found! It is strongly recommended to create a swap partition first". fi ;; esac while [ "$userChoiceOk" = "false" ] do echo -n "Index of $type partition ${diskDevice}${partitionPrefix}X ($firstIndex-15$allowNoneString) [$defaultPartitionIndex]? " read userChoicePartitionIndex [ "$userChoicePartitionIndex" = "" ] && userChoicePartitionIndex=$defaultPartitionIndex case "$userChoicePartitionIndex" in 1|2|3|4|5|6|7|8|9|10|11|12|13|14|15) device="/dev/$diskPrefix$disk$partitionPrefix$userChoicePartitionIndex" case "$type" in root) if checkPartitionTypeIs LINUX,LVM then # Nothing to check userChoiceOk=true break fi ;; boot) if checkPartitionTypeIs LINUX then if [ "$userChoicePartitionIndex" = "$root_idx" ] then mecho -info "Ok, you want to use the same partition for boot/root, using $device" userChoicePartitionIndex=0 fi userChoiceOk=true break fi ;; swap) if checkPartitionTypeIs SWAP then userChoiceOk=true break fi ;; data) if checkPartitionTypeIs LINUX,LVM then if [ "$userChoicePartitionIndex" = "$boot_idx" ] then mecho -error "$device is already reserved for boot partition. Please try again." continue fi if [ "$userChoicePartitionIndex" = "$root_idx" ] then mecho -error "$device is already reserved for root partition. Please try again." continue fi userChoiceOk=true break fi ;; esac ;; *) if [ "$userChoicePartitionIndex" = "0" -a $firstIndex -eq 0 ] then userChoiceOk=true continue fi mecho -error "Your answer must be numeric between $firstIndex - 15. Please try again." ;; esac done exec 1>&3 # restore stdout echo $userChoicePartitionIndex } scanPartitions() { for j in $ide_devices do eval $j=`cat /proc/ide/$j/media 2>/dev/null` eval type='$'$j case "$type" in disk) ide_found="true" if [ "$disk" = "none" ] then disk="$j" fi ;; cdrom) #ide_found="true" if [ "$cdrom" = "none" ] then cdrom="$j" fi ;; "") eval $j='none' ;; esac # In some cases the disk is not represented in /proc/ide/hdX if grep -q " $j"'$' /proc/partitions then eval $j='disk' ide_found="true" if [ "$disk" = "none" ] then disk="$j" fi fi done for j in $scsi_devices do if grep -q " $j"'$' /proc/partitions then eval $j='disk' scsi_found="true" if [ "$disk" = "none" ] then disk="$j" fi else eval $j='none' fi done # set -x # detect Compaq server controllers # TODO. Kann nur mit einem einzigen Smart Array umgehen. for currentCompaqPrefix in $compaqPrefixes do for device in /sys/block/$currentCompaqPrefix?c?d?/dev do device=${device%/dev} device=${device#*/$currentCompaqPrefix?} if [ "$device" = "c?d?" ] then continue fi if grep -qs " $currentCompaqPrefix/$device"'$' /proc/partitions then eval $device='disk' scsi_found="true" compaqPrefix="$currentCompaqPrefix" if [ "$disk" = "none" ] then disk="$device" fi else eval $device='none' fi done done # set +x } showPartitions() { if [ "$ide_found" = "true" ] then echo echo -e " IDE-Disk\t\t\t\t| Type" echo " ------------------------------------+--------------" masterSlave="Master" controllerIndex=1 for device in $ide_devices do eval type=\$$device controllerDesc="`echo $controllerDescriptions | cut -f$controllerIndex -d ' ' | sed 's/-/ /g'`" case "$type" in none|cdrom|floppy) ;; *) sizeKB=`sfdisk -s /dev/$device 2>/dev/null` sizeMB=`expr $sizeKB / 1024` echo -e " $device $masterSlave on $controllerDesc controller\t| $type ($sizeMB MB)" sizeMB="" sizeKB="" ;; esac if [ "$masterSlave" = "Master" ] then masterSlave="Slave " else masterSlave="Master" controllerIndex=`expr $controllerIndex + 1` fi done echo fi if [ "$scsi_found" = "true" ] then echo -e " SCSI/SATA/USB-Disk\t| Type" echo " --------------------+-----------------------" for device in $scsi_devices do eval type=\$$device if [ "$type" != "none" ] then # device names for compaq are e.g. /dev/ida/c0d0 if isCompaqDevice $device then tmpDevicePrefix="$compaqPrefix/" else tmpDevicePrefix="" fi sizeKB=`sfdisk -s /dev/${tmpDevicePrefix}$device 2>/dev/null` if [ -n "$sizeKB" ] then sizeMB=`expr $sizeKB / 1024` fi echo -e " $device\t\t| $type ($sizeMB MB)" sizeMB="" sizeKB="" fi done echo fi if [ "$disk" = "none" ] then mecho -warn -n "No disk found. " if [ `installerAsk "Rescan now?" "yes" "yesno"` = "yes" ] then udevadm trigger --subsystem-nomatch=tty \ --subsystem-nomatch=backlight \ --subsystem-nomatch=video4linux scanPartitions showPartitions else exitFailure fi fi } ### TODO Does only detect the first and the second hdd of the same size getRaid1CapableDevices() { local lastNumberOfBlocks=0 local lastDeviceName='' # transform output of /proc/partitions to the following format: # [size in blocks of dev0] [devicename0] # [size in blocks of dev1] [devicename1] # ... sfdisk -s | grep '/dev/' | sed 's/:[ ]*/ /' | sed -e "s#\([a-z/]*\) *\([0-9]*\)#\2 \1#" | sort | while read numberOfBlocks deviceName do if [ "$numberOfBlocks" -eq "$lastNumberOfBlocks" ] then echo "$lastDeviceName $deviceName" return 0 fi lastNumberOfBlocks=$numberOfBlocks lastDeviceName=$deviceName done return 1 } setupRaid() { local raid1CapableDevices=`getRaid1CapableDevices` set -- $raid1CapableDevices primaryDiskDevice=$1 secondaryDiskDevice=$2 local disknames=`echo $raid1CapableDevices | sed 's#/dev/##g'` if [ -n "$raid1CapableDevices" ] then if [ `installerAsk "Do you want to use $disknames as software RAID1 (mirroring)?" "yes" "noyes"` = "yes" ] then echo raidLevel="1" initrdOptions="${initrdOptions}raid=$raidLevel " fi fi } createRaid() { if [ "$raidLevel" = "1" ] then mecho -info "Creating RAID1 ..." mdadm --zero-superblock ${secondaryDiskDevice}$boot_idx >/dev/null 2>&1 mdadm --zero-superblock ${secondaryDiskDevice}$swap_idx >/dev/null 2>&1 mdadm --zero-superblock ${secondaryDiskDevice}$root_idx >/dev/null 2>&1 mdadm --zero-superblock ${secondaryDiskDevice}$data_idx >/dev/null 2>&1 dd if=/dev/zero of=${secondaryDiskDevice} bs=512 count=1 2>/dev/null sfdisk -d $primaryDiskDevice | sfdisk -f $secondaryDiskDevice >/dev/null 2>&1 echo yes | mdadm --create /dev/md0 --bitmap=internal --level=$raidLevel --raid-devices=2 --force ${primaryDiskDevice}$boot_idx ${secondaryDiskDevice}$boot_idx >/dev/null 2>&1 echo yes | mdadm --create /dev/md1 --bitmap=internal --level=$raidLevel --raid-devices=2 --force ${primaryDiskDevice}$swap_idx ${secondaryDiskDevice}$swap_idx >/dev/null 2>&1 echo yes | mdadm --create /dev/md2 --bitmap=internal --level=$raidLevel --raid-devices=2 --force ${primaryDiskDevice}$root_idx ${secondaryDiskDevice}$root_idx >/dev/null 2>&1 if [ $data_idx -gt 0 ] then echo yes | mdadm --create /dev/md3 --bitmap=internal --level=$raidLevel --raid-devices=2 --force ${primaryDiskDevice}$data_idx ${secondaryDiskDevice}$data_idx >/dev/null 2>&1 fi bootDevice="/dev/md0" swapDevice="/dev/md1" rootDevice="/dev/md2" dataDevice="/dev/md3" fi } # Checks whether the parameter contains a valid ip isValidIp() { if echo $1 | egrep -qs '\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b' then return 1 else return 0 fi } #---------------------------------------------------------------------------- # variable definition #---------------------------------------------------------------------------- PATH=$PATH:/usr/local/bin export PATH rootdir='/rootfs' bootdir="${rootdir}/boot" datadir="${rootdir}/data" grubBootPrefix="/boot" controllerDescriptions="primary-- secondary third---- fourth---" # "-" will be replaced by spaces to have fixed line length ide_devices="`getDevices hd 8`" # generate 8 device names hdx beginning with hda scsi_devices="`getDevices sd 15`" # generate 15 device names sdx beginning with sda defaultPartitionIndex_boot=1 defaultPartitionIndex_swap=2 defaultPartitionIndex_root=3 defaultPartitionIndex_data=4 keepPartitions="false" base="$rootdir/etc/config.d/base" networkInterfaces="$rootdir/etc/network/interfaces" networksFile="$rootdir/etc/networks" resolvConf="$rootdir/etc/resolv.conf" hostsFile="$rootdir/etc/hosts" disk="none" cdrom="none" ide_found="false" scsi_found="false" compaqPrefixes='ida cciss' raidLevel="" initrdOptions="quiet console=tty7 kmapger " #initrdOptions="debug kmapger " #---------------------------------------------------------------------------- # welcome #---------------------------------------------------------------------------- # change verbose level kernelverbose=`cat /proc/sys/kernel/printk` echo 0 > /proc/sys/kernel/printk echo mecho -info -n "Welcome to " if [ -e /xen ] then mecho -warn -n "eisxen " else mecho -warn -n "eisfair-2 " fi mecho -info "installation!" echo if [ -f /build ] then echo "Build `cat /build`" echo fi #---------------------------------------------------------------------------- # check for pae support when installing eisxen #---------------------------------------------------------------------------- if [ -e /xen ] then if ! grep -q ' pae ' /proc/cpuinfo then mecho -error "To install eisxen, you need to use a CPU with PAE support." exitFailure fi kernel=`ls /mnt/kernel-* | grep -v -i -e '-xen' | sed -e 's#/mnt/kernel-##' -e 's#.tar.gz##'` xenKernel=`ls /mnt/kernel-* | grep -i -e '-xen' | sed -e 's#/mnt/kernel-##' -e 's#.tar.gz##'` else if grep -q ' pae ' /proc/cpuinfo then kernel=`ls /mnt/kernel-* | grep -E '(-pae|-server)' | sed -e 's#/mnt/kernel-##' -e 's#.tar.gz##'` else kernel=`ls /mnt/kernel-* | grep -v -E '(-pae|-server)' | sed -e 's#/mnt/kernel-##' -e 's#.tar.gz##'` fi fi #---------------------------------------------------------------------------- # loading drivers #---------------------------------------------------------------------------- cd / echo mecho -info "Searching harddisks ..." echo if [ "$debug" != "1" ] then #---------------------------------------------------------------------------- # search for harddisks and cdroms #---------------------------------------------------------------------------- scanPartitions showPartitions if [ -e /etc/rescue ] then echo "Rescue console:" export PS1='\w\$ ' /bin/bash -i /dev/console 2>&1 exit 0 fi echo setupRaid if [ -z "$raidLevel" ] then #---------------------------------------------------------------------------- # partitioning dialog #---------------------------------------------------------------------------- if [ `installerAsk "Use $disk for installation" "yes" "yesno"` = "no" ] then while [ 1 ] do echo echo -n "Disk to use [$disk]: " read a [ -n "$a" ] || a="$disk" # have to grep the output of sfdisk -l because "sfdisk -l /dev/hdx" returns success if hdx is a cdrom drive if sfdisk -l 2>/dev/null | grep -q "/dev/$a" then disk=$a break else mecho -error "'$a' is no valid disk." mecho -error "'$disk' would be a correct answer. Please try again." fi done fi echo "" else disk=`echo $primaryDiskDevice | sed 's#/dev/##'` fi if isCompaqDevice $disk then diskPrefix="${compaqPrefix}/" partitionPrefix="p" fi diskDevice="/dev/${diskPrefix}$disk" partitionList="`sfdisk -l $diskDevice 2>/dev/null`" #---------------------------------------------------------------------------- # search for existing linux partitions #---------------------------------------------------------------------------- foundlinux=`echo "$partitionList" | grep '83 Linux'` if [ -n "$foundlinux" ] && [ `installerAsk "Use existing Linux partition(s)?" "no" "yesno"` = "yes" ] then data_format="no" keepPartitions="true" echo mecho -info "Partition table:" echo "$partitionList" echo boot_idx=`askForPartitionIndex boot` swap_idx=`askForPartitionIndex swap` root_idx=`askForPartitionIndex root` data_idx=`askForPartitionIndex data` echo else . /setup.part $diskDevice keepPartitions="false" fi bootDevice="/dev/${diskPrefix}${disk}${partitionPrefix}$boot_idx" swapDevice="/dev/${diskPrefix}${disk}${partitionPrefix}$swap_idx" rootDevice="/dev/${diskPrefix}${disk}${partitionPrefix}$root_idx" dataDevice="/dev/${diskPrefix}${disk}${partitionPrefix}$data_idx" mecho -info "Summary:" echo if [ "$keepPartitions" = "true" ] then if [ $boot_idx -eq 0 ] then echo " boot partition: none (use root partition for boot)" else echo " boot partition: $bootDevice (will be erased)" fi echo " root partition: $rootDevice (will be erased)" if [ $swap_idx -eq 0 ] then echo " swap partition: none" # never reached else echo " swap partition: $swapDevice (will be erased)" fi if [ $data_idx -eq 0 ] then echo " data partition: none" else if [ "$data_format" = "yes" ] then echo " data partition: $dataDevice (will be erased)" else echo " data partition: $dataDevice (will be left untouched)" exceptionString=" (Except the data partition $dataDevice)\n" fi fi echo mecho -warn "WARNING:" mecho -warn "IF YOU ANSWER yes, COMPLETE data on listed partitions will be ERASED." echo echo -e -n $exceptionString echo if [ -n "$raidLevel" ] then mecho -warn "And also the COMPLETE harddisk ->`echo $secondaryDiskDevice | sed 's#/dev/##'`<-" echo fi if [ `installerAsk "Partition setup ok?" "yes" "yesno"` = "no" ] then exitFailure fi else if [ $boot_idx -gt 0 ] then echo " Boot $bootDevice $bootsizeMB MB" fi echo " Swap $swapDevice $swapsizeMB MB" if [ "$useRestSizeForRootPartition" = "true" ] then echo " Root $rootDevice Rest ($restsizeMB MB)" else echo " Root $rootDevice $rootsizeMB MB" echo " Data $dataDevice Rest ($restsizeMB MB)" fi echo mecho -warn "WARNING:" mecho -warn "IF YOU ANSWER yes, COMPLETE data on the following harddisk(s) will be ERASED:" echo echo " -> $disk" if [ -n "$raidLevel" ] then echo " -> `echo $secondaryDiskDevice | sed 's#/dev/##'`" fi echo if [ `installerAsk "Create partitions as listed above?" "no" "noyes"` = "no" ] then echo echo "If you want to create your partitions manually," echo "you have to choose 'yes' to the question" echo "\"Use existing Linux partition(s)\"" exitFailure fi echo mecho -info "Creating partitions ..." # force stop automount all /dev/md* partitions! for ((x=0;x<15;x++)) do mdadm -r /dev/md$x; done >/dev/null 2>&1 for ((x=0;x<15;x++)) do mdadm --stop /dev/md$x; done >/dev/null 2>&1 mdadm --zero-superblock ${primaryDiskDevice}$boot_idx >/dev/null 2>&1 mdadm --zero-superblock ${primaryDiskDevice}$swap_idx >/dev/null 2>&1 mdadm --zero-superblock ${primaryDiskDevice}$root_idx >/dev/null 2>&1 mdadm --zero-superblock ${primaryDiskDevice}$data_idx >/dev/null 2>&1 dd if=/dev/zero of=${primaryDiskDevice} bs=512 count=1 2>/dev/null sfdisk -qL -uM /dev/$disk /dev/null 2>&1 fi createRaid echo #---------------------------------------------------------------------------- # integrate lvm #---------------------------------------------------------------------------- if [ $data_idx -gt 0 -a "$data_format" = "yes" ] then # force remove old volume group and entries rm -rf /dev/vg rm -f /dev/mapper/v* lvm pvcreate -y -ff $dataDevice >/dev/null #2>&1 # create physical volumen lvm vgcreate vg $dataDevice >/dev/null #2>&1 # create volume group # hier size berechnen lvm vgs --units m | ( while read line do set -- $line if [ "$1" != "VG" ] then lvmKeyLen=${#7} lvmSizeOperator="`echo "$7" | cut -c ${lvmKeyLen}-`" lvmSize="`echo "$7" | cut -c -$((lvmKeyLen-4))`" if [ -e /xen ] then if [ $lvmSize -gt 4096 ] then lvmSize=4096 else lvmSize="`expr $lvmSize / 4`" fi else lvmSize="`expr $lvmSize - 1`" fi echo 'y' | lvm lvcreate -n data -L $lvmSize vg >/dev/null 2>&1 # create logical volume break; fi done ) else lvm vgchange -a y >/dev/null 2>&1 # activate old lvm's fi dataDevice="/dev/vg/data" #---------------------------------------------------------------------------- # setup boot filesystem #---------------------------------------------------------------------------- if [ $boot_idx -gt 0 ] then mecho -info "Formatting $bootDevice ..." mke2fs -j -q $bootDevice fi #---------------------------------------------------------------------------- # setup swap space #---------------------------------------------------------------------------- if [ $swap_idx -gt 0 ] then mecho -info "Formatting $swapDevice (Setting up swapspace) ..." mkswap $swapDevice >/dev/null swapon $swapDevice >/dev/null fi #---------------------------------------------------------------------------- # setup root filesystem #---------------------------------------------------------------------------- mecho -info "Formatting $rootDevice ..." mke2fs -j -q $rootDevice #---------------------------------------------------------------------------- # setup data filesystem #---------------------------------------------------------------------------- if [ $data_idx -gt 0 -a "$data_format" = "yes" ] then mecho -info "Formatting $dataDevice ..." mke2fs -j -q $dataDevice fi echo else ######### Debug END disk=sda boot_idx=1 swap_idx=2 root_idx=3 data_idx=4 cdrom=hda fi #---------------------------------------------------------------------------- # loaded modules detection #---------------------------------------------------------------------------- cat /proc/modules | cut -f1 -d" " | while read module do echo -n "$module " >>/modules done #---------------------------------------------------------------------------- # mount root filesystem #---------------------------------------------------------------------------- mkdir $rootdir mount $rootDevice $rootdir if [ $data_idx -gt 0 ] then mkdir -p $datadir mount $dataDevice $datadir fi cd $rootdir mkdir -p tmp proc sys mnt boot data var/lock chmod 1777 tmp #---------------------------------------------------------------------------- # mount /boot partition #---------------------------------------------------------------------------- if [ $boot_idx -gt 0 ] then grub_boot_idx=`expr $boot_idx - 1` mount $bootDevice $bootdir cd $bootdir && ln -s . boot else grub_boot_idx=`expr $root_idx - 1` fi #---------------------------------------------------------------------------- # install root filesystem #---------------------------------------------------------------------------- [ -e ${datadir}/tmp ] && datadirTmpExists=true cd $rootdir mecho -info "Installing root filesystem ..." bar -n /mnt/rootfs-eisfair.tar.gz | tar xpzf - if [ -e /xen ] then mecho -info "Installing xen system ..." bar -n /mnt/xen.tar.gz | tar xpzf - fi #---------------------------------------------------------------------------- # moving /home and /var/lib directories to the data partition #---------------------------------------------------------------------------- if [ $data_idx -gt 0 ] then mkdir -p ${datadir}/home cp -fa ${rootdir}/home/* ${datadir}/home/ && rm -rf ${rootdir}/home/* mkdir -p ${datadir}/var/lib cp -fa ${rootdir}/var/lib/* ${datadir}/var/lib/ && rm -rf ${rootdir}/var/lib/* mount --rbind ${datadir}/home ${rootdir}/home mount --rbind ${datadir}/var/lib ${rootdir}/var/lib fi if [ ! -e $base ] then mv -f ${rootdir}/data/tmp/etc/config.d ${rootdir}/etc/ fi rm -rf ${rootdir}/data/tmp chmod 700 ${rootdir}/etc/config.d #---------------------------------------------------------------------------- # update hardware database #---------------------------------------------------------------------------- cp -f /usr/share/pci.ids ${rootdir}/usr/share/misc/pci.ids cp -f /usr/share/usb.ids ${rootdir}/var/lib/misc/usb.ids #---------------------------------------------------------------------------- # update ldconfig #---------------------------------------------------------------------------- cd ${rootdir}/etc ${rootdir}/sbin/ldconfig -r $rootdir #---------------------------------------------------------------------------- # install kernel #---------------------------------------------------------------------------- cd $rootdir mecho -info "Installing kernel ${kernel} ..." bar -n /mnt/kernel-${kernel}.tar.gz | tar xpzf - if [ -e /xen ] then mecho -info "Installing xen kernel ${xenKernel} ..." bar -n /mnt/kernel-${xenKernel}.tar.gz | tar xpzf - fi #---------------------------------------------------------------------------- # install boot filesystem #---------------------------------------------------------------------------- mecho -info "Installing boot filesystem ..." cd $bootdir ln -sf vmlinuz-$kernel vmlinuz # copy splashfile if [ -f /mnt/boot/grub/eisfair.xpm.gz ] then cp -f /mnt/boot/grub/eisfair.xpm.gz ${bootdir}/grub/eisfair.xpm.gz fi if [ -e /xen ] then ln -sf vmlinuz-$xenKernel vmlinuz-xen fi #---------------------------------------------------------------------------- # Preparing eisfair2-initrd #---------------------------------------------------------------------------- mecho -info "Preparing eisfair2-initrd ..." sLCompress="gz" [ -e /mnt/initrd-${kernel}.lz ] && sLCompress="lz" cp /mnt/initrd-${kernel}.${sLCompress} ${bootdir}/initrd-${kernel}.${sLCompress} cd $bootdir ln -sf initrd-${kernel}.${sLCompress} initrd.${sLCompress} #---------------------------------------------------------------------------- # Preparing xen-initrd #---------------------------------------------------------------------------- if [ -e /xen ] then sXCompress="gz" [ -e /mnt/initrd-${xenKernel}.lz ] && sXCompress="lz" mecho -info "Preparing xen-initrd ..." cp /mnt/initrd-${xenKernel}.${sXCompress} ${bootdir}/initrd-${xenKernel}.${sXCompress} ln -sf initrd-${xenKernel}.${sXCompress} initrd-xen.${sXCompress} fi #---------------------------------------------------------------------------- # Gather UUIDs for devices #---------------------------------------------------------------------------- rootDevice=`blkid -c /dev/null -s UUID -o value "$rootDevice"` if [ $boot_idx -gt 0 ] then bootDevice=`blkid -c /dev/null -s UUID -o value "$bootDevice"` fi if [ $swap_idx -gt 0 ] then swapDevice=`blkid -c /dev/null -s UUID -o value "$swapDevice"` fi if [ $data_idx -gt 0 ] then dataDevice=`blkid -c /dev/null -s UUID -o value "$dataDevice"` fi #---------------------------------------------------------------------------- # Preparing bootloader #---------------------------------------------------------------------------- mecho -info "Preparing bootloader ..." # check if run virtual then hide serial interface on grub #SPEEDUP="-disable spd -disable cpuid -disable isapnp -disable pcmcia -disable ide -disable usb -disable scsi -disable network" #lshw -short ${SPEEDUP} -class system 2>/dev/null | # while read line # do # case "$line" in # *VirtualBox*) # > /found_virtual # ;; # *VMware*) # > /found_virtual # ;; # esac # done # #if [ -e /found_virtual ] #then commentstr="#" # rm -f /found_virtual #else # commentstr="" #fi echo "(hd0) $diskDevice" > ${bootdir}/grub/device.map if [ "$raidLevel" = "1" ] then echo "(hd1) $secondaryDiskDevice" >> ${bootdir}/grub/device.map fi cat > ${bootdir}/grub/menu.lst << EOF # Optional eisfair start parameters: # doload= # insert aditional module (doload=aic7xxx,nls_cp437) # kmapger # load german keyboard layout for initrd # quiet # hide the kernel debug messages # clrhome # clear screen before run detecting hardware # raid=1 # use RAID level 1 # debug # use debug output # nousb # dont use usb devices on initrd # vga=773 FRAMEBUFFER RESOLUTION SETTINGS # +-------------------------------------------------+ # | 640x480 800x600 1024x768 1280x1024 # ----+-------------------------------------------- # 256 | 0x301=769 0x303=771 0x305=773 0x307=775 # 32K | 0x310=784 0x313=787 0x316=790 0x319=793 # 64K | 0x311=785 0x314=788 0x317=791 0x31A=794 # 16M | 0x312=786 0x315=789 0x318=792 0x31B=795 # +-------------------------------------------------+ # setkey changes the keyboardlayout to german setkey y z setkey z y setkey Y Z setkey Z Y setkey equal parenright setkey parenright parenleft setkey parenleft asterisk setkey doublequote at setkey plus bracketright setkey minus slash setkey slash ampersand setkey ampersand percent setkey percent caret setkey underscore question setkey question underscore setkey semicolon less setkey less numbersign setkey numbersign backslash setkey colon greater setkey greater bar setkey asterisk braceright # begin serial ${commentstr}serial --unit=0 --speed=57600 ${commentstr}terminal --timeout=1 console serial # end serial default 0 timeout 4 color white/green black/light-gray EOF ( if [ -f ${bootdir}/grub/eisfair.xpm.gz ] then echo "# hiddenmenu" echo echo "splashimage=(hd0,${grub_boot_idx})${grubBootPrefix}/grub/eisfair.xpm.gz" echo "foreground ffffff" echo "background 000000" else echo "hiddenmenu" fi echo "" if [ "$raidLevel" = "1" ] then echo "fallback 1" echo fi if [ -e /xen ] then echo "# begin xenkernel" echo "title eisxen kernel $xenKernel" echo " root (hd0,${grub_boot_idx})" echo " kernel ${grubBootPrefix}/xen.gz console=vga noreboot dom0_max_vcpus=1 dom0_vcpus_pin" echo " module ${grubBootPrefix}/vmlinuz-xen root=UUID=$rootDevice ro splash clrhome max_loop=128 swiotlb=16 $initrdOptions" echo " module ${grubBootPrefix}/initrd-xen.${sXCompress}" echo " quiet" echo if [ "$raidLevel" = "1" ] then echo "title eisxen kernel $xenKernel (failover)" echo " root (hd1,${grub_boot_idx})" echo " kernel ${grubBootPrefix}/xen.gz console=vga noreboot" echo " module ${grubBootPrefix}/vmlinuz-xen root=UUID=$rootDevice ro splash clrhome max_loop=128 swiotlb=16 $initrdOptions" echo " module ${grubBootPrefix}/initrd-xen.${sXCompress}" echo " quiet" echo fi echo "# end xenkernel" fi echo "# begin eiskernel" echo "title eisfair-2 kernel $kernel" echo " root (hd0,${grub_boot_idx})" echo " kernel ${grubBootPrefix}/vmlinuz root=UUID=$rootDevice ro $initrdOptions" echo " initrd ${grubBootPrefix}/initrd.${sLCompress}" echo " quiet" echo if [ "$raidLevel" = "1" ] then echo "title eisfair-2 kernel $kernel (failover)" echo " root (hd1,${grub_boot_idx})" echo " kernel ${grubBootPrefix}/vmlinuz root=UUID=$rootDevice ro $initrdOptions" echo " initrd ${grubBootPrefix}/initrd.${sLCompress}" echo " quiet" echo fi echo "# end eiskernel" ) >> $bootdir/grub/menu.lst ( if [ "$raidLevel" = "1" ] then echo "device (hd0) $secondaryDiskDevice" echo "root (hd0,${grub_boot_idx})" echo "install /boot/grub/stage1 d (hd0) /boot/grub/stage2 p /boot/grub/menu.lst" #echo "setup (hd0)" # use install or setup fi echo "device (hd0) $diskDevice" echo "root (hd0,${grub_boot_idx})" echo "install /boot/grub/stage1 d (hd0) /boot/grub/stage2 p /boot/grub/menu.lst" echo "quit" ) > $bootdir/grub/grub.conf mecho -info "Writing bootloader into Master Boot Record of $diskDevice ..." ${rootdir}/usr/sbin/grub --batch --device-map=${bootdir}/grub/device.map < ${bootdir}/grub/grub.conf >/dev/null rm ${bootdir}/grub/grub.conf cd / #---------------------------------------------------------------------------- # setup mountable devices #---------------------------------------------------------------------------- if [ "$cdrom" != "none" ] then cd ${rootdir}/dev ln -sf $cdrom cdrom cd / fi ( echo "proc /proc proc defaults 0 0" echo "UUID=$rootDevice / ext3 defaults,errors=remount-ro,acl,user_xattr 0 1" if [ $boot_idx -gt 0 ] then echo "UUID=$bootDevice /boot ext3 defaults,errors=remount-ro,acl,user_xattr 0 1" fi if [ $swap_idx -gt 0 ] then echo "UUID=$swapDevice none swap sw 0 0" fi if [ $data_idx -gt 0 ] then echo "UUID=$dataDevice /data ext3 defaults,errors=remount-ro,acl,user_xattr 0 2" fi echo "/dev/cdrom /media/cdrom udf,iso9660 user,noauto,exec,utf8 0 0" echo "/dev/fd0 /media/floppy auto rw,user,noauto,exec,utf8 0 0" #echo "procbususb /proc/bus/usb procbususb defaults 0 0" #echo "sysfs /sys sysfs defaults 0 0" #echo "devpts /dev/pts devpts defaults 0 0" ) > $rootdir/etc/fstab #---------------------------------------------------------------------------- # setup sw raid configuration #---------------------------------------------------------------------------- if [ "$raidLevel" = "1" ] then mkdir -p ${rootdir}/etc/mdadm echo "DEVICE ${diskDevice}* ${secondaryDiskDevice}*" > ${rootdir}/etc/mdadm/mdadm.conf mdadm --detail --scan >> ${rootdir}/etc/mdadm/mdadm.conf ( echo "INITRDSTART='all'" echo "AUTOSTART=true" echo "AUTOCHECK=true" echo "START_DAEMON=false" echo "DAEMON_OPTIONS=\"--syslog\"" echo "VERBOSE=false" echo "USE_DEPRECATED_MDRUN=false" ) > ${rootdir}/etc/default/mdadm fi if [ "$debug" != "1" ] then #---------------------------------------------------------------------------- # set root password #---------------------------------------------------------------------------- change_pw root change_pw eis echo #---------------------------------------------------------------------------- # ethernet card detection #---------------------------------------------------------------------------- # write loopback entry ( echo "auto lo" echo "iface lo inet loopback" echo ) > $networkInterfaces echo "loopback 127.0.0.0" > $networksFile mecho -info "Searching for Network cards ..." #SPEEDUP="-disable spd -disable cpuid -disable pci -disable isapnp \ #-disable pcmcia -disable ide -disable usb -disable scsi -disable network" # -short SPEEDUP="-disable spd -disable cpuid -disable ide -disable usb -disable scsi" lshw ${SPEEDUP} -class network 2>/dev/null | while read line do case "$line" in *product*) short=`echo "$line" | sed -e 's/product: //'` ;; *vendor*) vendor=`echo "$line" | sed -e 's/vendor: //'` mecho -info -n "Found: " echo "$vendor $short" > /found_ethernet_card ;; esac done # check if ethernet interface a bridge if [ ! -e /found_ethernet_card ] then lshw ${SPEEDUP} -class bridge 2>/dev/null | while read line do case "$line" in *product*) case "$line" in *thernet*) short=`echo "$line" | sed -e 's/product: //'` > /found_bridge_net ;; esac ;; *vendor*) if [ -e /found_bridge_net ] then vendor=`echo "$line" | sed -e 's/vendor: //'` mecho -info -n "Found: " echo "$vendor $short" > /found_ethernet_card rm /found_bridge_net fi ;; esac done fi cd / if [ -e /found_ethernet_card ] then echo "" if [ `installerAsk "Use DHCP for network card?" "yes" "yesno"` = "no" ] then echo ipaddr="`installerAsk "Enter IP-Address." "192.168.0.253"`" while isValidIp $ipaddr do mecho -error "Please enter a valid IP-Address." ipaddr="`installerAsk "Enter IP-Address." "192.168.0.253"`" done subnetmask="`installerAsk "Enter Subnetmask." "255.255.255.0"`" while isValidIp $subnetmask do mecho -error "Please enter a valid Subnetmask." subnetmask="`installerAsk "Enter Subnetmask." "255.255.255.0"`" done gateway="`installerAsk "Enter IP-Adress of the gateway." "192.168.0.254"`" while isValidIp $gateway do mecho -error "Please enter a valid IP-Address." gateway="`installerAsk "Enter IP-Adress of the gateway." "192.168.0.254"`" done dns="`installerAsk "Enter IP-Address of DNS server." "$gateway"`" while isValidIp $dns do mecho -error "Please enter a valid IP-Address." dns="`installerAsk "Enter IP-Address of DNS server." "$gateway"`" done replaceBaseVariable IP_NET_1_IPADDR $ipaddr replaceBaseVariable IP_NET_1_NETMASK $subnetmask replaceBaseVariable IP_NET_1_GATEWAY $gateway replaceBaseVariable DNS_SERVER $dns else # using DHCP replaceBaseVariable IP_NET_1_STATIC_IP "no" fi else # no NIC found echo "Not found" fi echo else ######################### Debug END ( echo "auto eth0" echo "iface eth0 inet dhcp" ) >> $networkInterfaces fi . ${rootdir}/var/install/config.d/network.sh cp /prep ${rootdir}/prep ${rootdir}/usr/sbin/chroot $rootdir sh /prep rm ${rootdir}/prep #---------------------------------------------------------------------------- # umount devices and directories #---------------------------------------------------------------------------- cd / mecho -info "Unmounting file systems ..." # umount config.d and /home from the data partition if [ $data_idx -gt 0 ] then umount ${rootdir}/home umount ${rootdir}/var/lib umount $datadir fi if [ $boot_idx -gt 0 ] # /boot then umount $bootdir fi umount /mnt umount $rootdir # rechange verbose level echo "$kernelverbose" > /proc/sys/kernel/printk #---------------------------------------------------------------------------- # ok, we are ready #---------------------------------------------------------------------------- swapoff 2>/dev/null echo mecho -info "Ready to go." echo echo "Remove installation medium and reboot your computer." echo mecho -warn "Good luck." echo while [ 1 ] do read dummy done exit 0