#!/bin/bash # # Knoppix Installation for HardDisk Drive # Version 0.9tested 16/Nov./'02 # adapted by K.Wonderboy # Special Thanks Christian Perle, perle@itm.tu-clausthal.de # Original Version 0.29test # TODO: # Fremde Partitionen (vfat, ntfs) in /etc/fstab eintragen # weitere Filesysteme f? $TR (ext3, reiserfs) initrd.gz # bei DHCP: "iface eth0 inet dhcp" eintragen # Auswahl: Automounter oder nicht # "no cloop"-Install (extract_compressed_fs, doppelter Plattenplatz n?ig) # lo-Device nach Booten von Platte nicht immer "up" gesetzt # LILO im MBR nur auf der ersten Platte installieren (BIOS-Reihenfolge) # SVERSION="0.9jp" rotdash() { p=$1 while [ -d /proc/$p ] do echo -n '/' ; usleep 100000 echo -n '-' ; usleep 100000 echo -n '\' ; usleep 100000 echo -n '|' ; usleep 100000 done } # X oder Textkonsole case "`tty`" in /dev/tty[1-8]) MODE=text DIA=dialog ;; # /dev/pts/*|/dev/ttyp*) # MODE=x # XDIALOG_HIGH_DIALOG_COMPAT=1 # export XDIALOG_HIGH_DIALOG_COMPAT # DIA=Xdialog # ;; *) MODE=text DIA=dialog ;; esac # Textmode wenn DISPLAY nicht gesetzt ist if [ -z "$DISPLAY" ] ; then MODE=text DIA=dialog fi # Mountpoint f? das Rootfilesystem TR="/mnt/target" # Mountpoints f? Loop-Mounts TL1="/mnt/l1" TL2="/mnt/l2" # Name des Template-Archivs INSTDATA="/temp/knx-templates-$SVERSION.tgz" # Hierhin werden die Templates entpackt TM="$TR/templates" # Default Hostname DEFHNAME="localhost" if [ $UID != 0 ] ; then echo "Dieses Skript l?ft nur mit root-Rechten." exit 0 fi TMP="/tmp/hdinst.tmp.$$" ORIG_LANG="ja_JP.eucJP" ORIG_LANGUAGE="ja" ORIG_LC_ALL="ja_JP.eucJP" # ...weg mit den locales export LANG=C export LANGUAGE=C export LC_ALL=C umask 022 killall dhcpcd >/dev/null 2>&1 killall -9 pump >/dev/null 2>&1 killall automount >/dev/null 2>&1 swapoff -a >/dev/null 2>&1 $DIA --backtitle "Knoppix Installation" --title "knx-hdinstall $SVERSION" \ --msgbox "このスクリプトは、KNOPPIX を \ ハードデイスクにインストールします \ knx-hdinstalljp by K.Wonderboy " 15 40 # Check f? die Templates tar tzf "$INSTDATA" >/dev/null 2>&1 if [ $? != 0 ] ; then $DIA --backtitle "Knoppix Installation" --title "Datei fehlt" \ --msgbox " $INSTDATA がありません。中止します " 15 60 rm -f $TMP exit 0 fi # G?tige Partitionierung: mind. 2.2 GB Filesystem, mind. 128 MB Swap. FSMIN=2200 SWAPMIN=128 # F? "no cloop"-Methode wird mehr Platz gebraucht NCLOOPFSMIN=4400 # Gr?e der initrd: 2.5 MB INSIZE=2500 # Auswahl der Platte zum Partitionieren > $TMP NUMHD=0 if [ -f /proc/partitions ] ; then while read x x x p x do case "$p" in hd?) if [ "`cat /proc/ide/$p/media`" = "disk" ] ; then echo "$p `tr ' ' _ > $TMP NUMHD=$[NUMHD+1] fi ;; sd?) x="`scsi_info /dev/$p | grep MODEL | tr ' ' _`" x=${x#*\"} x=${x%\"*} echo "$p $x" >> $TMP NUMHD=$[NUMHD+1] ;; *) ;; esac done < /proc/partitions fi HARDDISKS="`cat $TMP`" $DIA --backtitle "Knoppix Installation" --title Partitionieren \ --radiolist "ハードデイスクを選択して下さい" 16 60 $NUMHD \ $(echo "$HARDDISKS" | while read p model ; do echo "$p" "$model" off ; done) \ 2> $TMP HDCHOICE="`cat $TMP`" if [ -z "$HDCHOICE" ] ; then $DIA --backtitle "Knoppix Installation" --title Partitionieren \ --msgbox "選択されてません。中止します" 15 40 rm -f $TMP exit 0 fi x=$(fdisk -l /dev/$HDCHOICE 2>/dev/null | grep "^Disk.*cylinders") HDS=${x%% heads*} HDS=${HDS##* } SECT=${x%% sectors*} SECT=${SECT##* } CYLS=${x% cylinders} CYLS=${CYLS##* } $DIA --backtitle "Knoppix Installation" --title Partitionieren \ --msgbox " /dev/$HDCHOICE が選択されました。 Die Platte hat eine Kapazit? von $[CYLS*HDS*SECT/2048] MB. パーテイション作成プログラム cfdisk を起動します" 15 40 if [ $MODE = text ] ; then ( LANG="$ORIG_LANG" LANGUAGE="$ORIG_LANGUAGE" LC_ALL="$ORIG_LC_ALL" cfdisk /dev/$HDCHOICE ) else ( LANG="$ORIG_LANG" LANGUAGE="$ORIG_LANGUAGE" LC_ALL="$ORIG_LC_ALL" xterm -e cfdisk /dev/$HDCHOICE ) fi # Auswahl: Swap oder nicht $DIA --backtitle "Knoppix Installation" --title "Virtueller Speicher (Swap)" \ --yesno "スワップ領域を選択しますか" 15 60 x=$? if [ $x = 0 ] ; then # Auswahl der Swap-Partition (Swap einrichten) > $TMP fdisk -l /dev/$HDCHOICE | grep "^/dev.*Linux swap$" | while read dev x x size x do size=${size%+} echo $dev $[size/1024]_MB off >> $TMP done NUMSWAP="`wc -l <$TMP`" SWAPART="`cat $TMP`" if [ $NUMSWAP = 0 ] ; then $DIA --backtitle "Knoppix Installation" --title "Swap einrichten" \ --msgbox "領域が有りません。処理を中止します" 15 40 rm -f $TMP exit 0 fi $DIA --backtitle "Knoppix Installation" --title "Swap einrichten" \ --radiolist "スワップ領域を選択して下さい" 16 60 $NUMSWAP \ $SWAPART 2> $TMP SWCHOICE="`cat $TMP`" if [ -z "$SWCHOICE" ] ; then $DIA --backtitle "Knoppix Installation" --title "Swap einrichten" \ --msgbox "処理を中止します" 15 40 rm -f $TMP exit 0 fi size=$(echo "$SWAPART" | grep "$SWCHOICE") size=${size%%_*} size=${size##* } if [ $size -lt $SWAPMIN ] ; then $DIA --backtitle "Knoppix Installation" --title "Swap einrichten" \ --msgbox " 領域が足りません" 15 40 rm -f $TMP exit 0 fi $DIA --backtitle "Knoppix Installation" --title "Swap einrichten" \ --yesno " $SWCHOICE をスワップ領域として初期化します" 15 60 x=$? if [ $x != 0 ] ; then $DIA --backtitle "Knoppix Installation" --title "Swap einrichten" \ --msgbox "処理を中止します" 15 40 rm -f $TMP exit 0 fi echo "Partition $SWCHOICE を作成中 ..." sleep 2 dd if=/dev/zero of=$SWCHOICE bs=1k count=16 >/dev/null 2>&1 sync mkswap $SWCHOICE 2> $TMP if [ $? != 0 ] ; then $DIA --backtitle "Knoppix Installation" --title "Swap einrichten" \ --msgbox "作成できませんでした :`tail -8 $TMP` " 15 60 rm -f $TMP exit 0 fi swapon $SWCHOICE >/dev/null 2>&1 else SWCHOICE=none fi # Auswahl der Rootpartition (Filesystem anlegen) > $TMP fdisk -l /dev/$HDCHOICE | grep "^/dev.*Linux$" | tr -d '*' | while read dev x x size x do size=${size%+} echo $dev $[size/1024]_MB off >> $TMP done NUMEXT2="`wc -l <$TMP`" EXT2PART="`cat $TMP`" if [ $NUMEXT2 = 0 ] ; then $DIA --backtitle "Knoppix Installation" --title "Filesystem anlegen" \ --msgbox "領域が有りません。処理を中止します" 15 40 rm -f $TMP exit 0 fi $DIA --backtitle "Knoppix Installation" --title "Filesystem anlegen" \ --radiolist "システム領域を選択して下さい" 16 60 $NUMEXT2 \ $EXT2PART 2> $TMP FSCHOICE="`cat $TMP`" if [ -z "$FSCHOICE" ] ; then $DIA --backtitle "Knoppix Installation" --title "Filesystem anlegen" \ --msgbox "処理を中止します" 15 40 rm -f $TMP exit 0 fi size=$(echo "$EXT2PART" | grep "$FSCHOICE") size=${size%%_*} size=${size##* } if [ $size -lt $FSMIN ] ; then $DIA --backtitle "Knoppix Installation" --title "Filesystem anlegen" \ --msgbox "領域不足です。処理を中止します" 15 40 rm -f $TMP exit 0 fi #FIXME: FSTYPE ausw?len $DIA --backtitle "Knoppix Installation" --title "Filesystem anlegen" \ --yesno " $FSCHOICE をファイルシステムとして初期化します" 15 60 x=$? if [ $x != 0 ] ; then $DIA --backtitle "Knoppix Installation" --title "Filesystem anlegen" \ --msgbox "処理を中止します" 15 40 rm -f $TMP exit 0 fi echo "Filesystem $FSCHOICE を作成中 ..." sleep 2 dd if=/dev/zero of=$FSCHOICE bs=1k count=16 >/dev/null 2>&1 sync mke2fs $FSCHOICE 2> $TMP #mkfs -t ext3 $FSCHOICE 2> $TMP if [ $? != 0 ] ; then $DIA --backtitle "Knoppix Installation" --title "Filesystem anlegen" \ --msgbox "作成できませんでした :`tail -8 $TMP` " 15 60 rm -f $TMP exit 0 fi $DIA --backtitle "Knoppix Installation" --title "Dateien kopieren" \ --msgbox "これから Knoppix-CD をハードデイスクにコピーします \ 10-40分くらいかかります" 15 60 mkdir -p $TR >/dev/null 2>&1 mount -t ext2 $FSCHOICE $TR 2> $TMP #mount -t ext3 $FSCHOICE $TR 2> $TMP if [ $? != 0 ] ; then $DIA --backtitle "Knoppix Installation" --title "Dateien kopieren" \ --msgbox "コピーできません :`tail -8 $TMP` " 15 60 rm -f $TMP exit 0 fi # Jetzt beginnt die eigentliche Datenschaufelei echo -n "コピー中..." (cd /KNOPPIX ; cp -a * $TR ; sync) & rotdash $! # Zwei Beeps echo -ne "\007" >/dev/tty1 ; usleep 500000 echo -ne "\007" >/dev/tty1 ; usleep 500000 $DIA --backtitle "Knoppix Installation" --title "Dateien kopiert" \ --msgbox "コピーは完了しました" 15 40 # Entpacken der Templates mkdir -p $TM tar xpzf $INSTDATA -C $TM >/dev/null 2>&1 # "Normalisieren" der Runlevel-Verzeichnisse rm -f $TR/etc/rc[026S].d/* for x in 0 2 6 S do cp -a $TM/etc/rc$x.d/* $TR/etc/rc$x.d/ done # Nicht alle Dienste m?sen gestartet werden $DIA --backtitle "Knoppix Installation" --title "Mailserver" \ --yesno " Mailserver (smail) を起動しますか?" 15 60 x=$? if [ $x != 0 ] ; then rm -f $TR/etc/rc2.d/S??smail fi $DIA --backtitle "Knoppix Installation" --title "Secure Shell Server" \ --yesno " Secure Shell Server (sshd) を起動しますか?" 15 60 x=$? if [ $x != 0 ] ; then rm -f $TR/etc/rc2.d/S??ssh fi $DIA --backtitle "Knoppix Installation" --title "Samba Server" \ --yesno " Samba Server (smbd/nmbd) を起動しますか?" 15 60 x=$? if [ $x != 0 ] ; then rm -f $TR/etc/rc2.d/S??samba fi $DIA --backtitle "Knoppix Installation" --title "K Display Manager" \ --yesno " K Display Manager の設定を行ないます" 15 60 x=$? if [ $x != 0 ] ; then rm -f $TR/etc/rc2.d/S??kdm fi # hotplug entfernen, wenn kein USB-Modul geladen ist grep -E "usb|uhci|ohci" /proc/modules >/dev/null 2>&1 if [ $? != 0 ] ; then rm -f $TR/etc/rc2.d/S??hotplug fi # cardmgr entfernen, wenn kein PCMCIA-Modul geladen ist grep "pcmcia_core" /proc/modules >/dev/null 2>&1 if [ $? != 0 ] ; then rm -f $TR/etc/rc2.d/S??pcmcia fi # Keymap auf de-latin1-nodeadkeys setzen #cp -af $TM/etc/init.d/keymap.sh $TR/etc/init.d/keymap.sh ###UPD cp -af $TM/etc/init.d/* $TR/etc/init.d/ # Anlegen der Symlinks /dev/cdrom und /dev/mouse if [ -f /etc/sysconfig/mouse ] ; then x="`grep DEVICE= /etc/sysconfig/mouse`" x=${x#*/dev/} MOUSEDEV=${x%\"*} fi [ -z "$MOUSEDEV" ] && MOUSEDEV="psaux" (cd $TR/dev ; ln -sf $MOUSEDEV mouse ; ln -sf sr0 cdrom) # Prompt ?dern und "." aus PATH entfernen in /etc/profile cp -af $TM/etc/profile $TR/etc/profile # "Normaliseren" von /etc/inittab cp -af $TM/etc/inittab $TR/etc/inittab # Update von /etc/motd echo -e "Welcome to Knoppix (Kernel `uname -r`)\n" > $TR/etc/motd # Erzeugen von /etc/modules aus den aktuell geladenen Kernelmodulen cat <<\EOF >$TMP # /etc/modules: kernel modules to load at boot time. # # This file should contain the names of kernel modules that are # to be loaded at boot time, one per line. Comments begin with # a `#', and everything on the line after them are ignored. EOF tail +1 /proc/modules | grep -v '\[.*\]' | grep -v cloop | while read mod x do echo $mod >>$TMP done cp -f $TMP $TR/etc/modules # Anpassen von /etc/inputrc (8-bit clean) ###UPD cp -af $TM/etc/inputrc $TR/etc/inputrc # Erzeugen von /etc/fstab ###UPD #none /dev/pts devpts mode=0622 0 0 cat <$TR/etc/fstab # /etc/fstab: Tabelle einzubindender Dateisysteme. # # Dateisystem Mountpunkt Typ Optionen dump pass none /proc proc defaults 0 0 $FSCHOICE / ext2 defaults 0 0 EOF if [ $SWCHOICE != none ] ; then echo "$SWCHOICE swap swap defaults 0 0" >>$TR/etc/fstab fi cat <>$TR/etc/fstab /dev/fd0 /mnt/auto/floppy auto user,noauto,exec,umask=000 0 0 /dev/cdrom /mnt/auto/cdrom auto user,noauto,exec,ro 0 0 EOF cat $TM/etc/fstab >> $TR/etc/fstab # ?ertragen der Knoppix-generierten XF86Config cp -af /etc/X11/XF86Config $TR/etc/X11/XF86Config cp -af /etc/X11/XF86Config-4 $TR/etc/X11/XF86Config-4 # X-Session nicht auf KDE festlegen mv $TR/etc/X11/Xsession.d/45xsession $TR/root # Display-Permissions f? xdm/kdm (Bug in Woody?) sed -e 's,DisplayManager\*authorize:.*true,DisplayManager*authorize: false,g' /etc/X11/xdm/xdm-config >$TR/etc/X11/xdm/xdm-config for x in /etc/kde[23]/kdm/kdmrc do sed -e 's,#Authorize=false,Authorize=false,g' $x >$TR/$x done # Hostname setzen $DIA --backtitle "Knoppix Installation" --title "Rechnernamen setzen" \ --inputbox "ホストサーバー名を設定します :" 15 60 $DEFHNAME 2>$TMP HNAME="`cat $TMP`" [ -z "$HNAME" ] && HNAME=$DEFHNAME cat <$TR/etc/hosts 127.0.0.1 $HNAME localhost # The following lines are desirable for IPv6 capable hosts # (added automatically by netbase upgrade) ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts EOF echo "$HNAME" > $TR/etc/hostname echo "$HNAME" > $TR/etc/mailname # Netzwerkkarte einrichten, wenn vorhanden grep eth0 /proc/net/dev >/dev/null 2>&1 if [ $? = 0 ] ; then ( LANG="$ORIG_LANG" LANGUAGE="$ORIG_LANGUAGE" LC_ALL="$ORIG_LC_ALL" rm -f /etc/resolv.conf touch /etc/resolv.conf netcardconfig ) cp -af /etc/network/interfaces $TR/etc/network/interfaces rm -f $TR/etc/resolv.conf cat /etc/resolv.conf >$TR/etc/resolv.conf fi # Alle Dienste in /etc/inetd.conf deaktivieren cp -af $TM/etc/inetd.conf $TR/etc/inetd.conf # Knoppix-Eintrag aus /etc/sudoers entfernen ###UPD #cp -af $TM/etc/sudoers $TR/etc/sudoers cp -af /etc/sudoers $TR/etc/sudoers cp -af $TM/etc/sysconfig/* $TR/etc/sysconfig/ #cp -af $TM/etc/fstab $TR/etc/fstab mv /ramdisk/var $TR/var ( cp -af $TM/etc/.xsession $TR/etc/kde3/kdm/ ) cp -af $TM/etc/Xsession $TR/etc/kde3/kdm/ mkdir $TR/proc # /etc/hosts.allow weniger restriktiv cp -af $TM/etc/hosts.allow $TR/etc/hosts.allow # "Echtes" /tmp mit Modus 1777 erzeugen rm -rf $TR/tmp mkdir $TR/tmp chmod 1777 $TR/tmp # /etc/mtab als normale Datei erzeugen rm -f $TR/etc/mtab touch $TR/etc/mtab # ?dern des Homeverzeichnisses f? root auf /root sed -e 's,/home/root,/root,g' /etc/passwd > $TR/etc/passwd # Erzeugen des Homeverzeichnisses f? User knoppix ###UPD follow3line cp -af $TM/etc/filemanagement $TR/etc/skel/.kde/share/apps/konqueror/profiles/ cp -af $TM/etc/kxkbrc $TR/etc/skel/.kde/share/config/ cp -af $TM/etc/kbabelrc $TR/etc/skel/.kde/share/config/ cp -af $TM/etc/Desktop/* $TR/etc/skel/Desktop/ cp -af $TM/etc/kdeglobals $TR/etc/skel/.kde/share/config/ cp -af $TM/etc/kdesktoprc $TR/etc/skel/.kde/share/config/ cp -af $TM/etc/kickerrc $TR/etc/skel/.kde/share/config/ cp -af $TM/etc/.kderc $TR/etc/skel/ cp -af $TM/etc/qtrc $TR/etc/skel/.qt/ rm -rf $TR/etc/skel/office rm -rf $TR/home/knoppix cp -a $TR/etc/skel $TR/home mv $TR/home/skel $TR/home/knoppix chown -R knoppix.knoppix $TR/home/knoppix # Setzen g?tiger Passw?ter f? die User root und knoppix mittels # chroot-Umgebung echo "root パスワードを設定して下さい" chroot $TR passwd root echo "ユーザ knoppix のパスワードを設定して下さい" chroot $TR passwd knoppix # Bei SCSI-System: Erzeugen einer initrd mit ash.static und SCSI-Modul #FIXME: auch bei FSTYPE ext3 und reiserfs INITRD="" SCSIMODS="" mkdir -p $TL1 $TL2 >/dev/null 2>&1 case "$FSCHOICE" in /dev/sd*) mount -t vfat -o loop,ro /cdrom/KNOPPIX/boot.img $TL1 gzip -cd $TL1/miniroot.gz > $TR/miniroot umount $TL1 dd if=/dev/zero of=$TR/ird bs=1k count=$INSIZE mke2fs -F -m 0 -i 1024 -q $TR/ird mount -t ext2 -o loop,ro $TR/miniroot $TL1 mount -t ext2 -o loop,rw $TR/ird $TL2 cp -a $TL1/dev $TL1/etc $TL1/static $TL2 mkdir -p $TL2/proc $TL2/modules for i in `ls $TL1/modules/scsi` do i=${i%.o} if [ -n "`grep $i /proc/modules`" ] ; then SCSIMODS="$SCSIMODS $i" fi done echo "#!/static/sh" >$TL2/linuxrc for i in $SCSIMODS do cp $TL1/modules/scsi/$i.o $TL2/modules echo "insmod /modules/$i.o" >>$TL2/linuxrc done chmod 755 $TL2/linuxrc umount $TL1 umount $TL2 rm -rf $TR/miniroot gzip -9 $TR/ird mv $TR/ird.gz $TR/boot/initrd.gz INITRD=" initrd=/boot/initrd.gz" ;; *) ;; esac # Einrichten von LILO mittels chroot-Umgebung $DIA --backtitle "Knoppix Installation" --title "Bootloader einrichten" \ --yesno "Bootloader (LILO) を Master Boot Record (MBR) に書き出しますか?" 15 60 x=$? if [ $x = 0 ] ; then LBOOT=${FSCHOICE%%[1-9]*} else LBOOT=$FSCHOICE fi BKERNEL="/boot/vmlinuz-`uname -r`" cat <$TR/etc/lilo.conf boot=$LBOOT vga=791 prompt timeout=50 append = "hda=scsi hdb=scsi hdc=scsi hdd=scsi hde=scsi hdf=scsi hdg=scsi hdh=scsi apm=power-off noapic" image=/boot/vmlinuz label=knoppix root=$FSCHOICE read-only $INITRD #other=/dev/hda1 # label=freedos # table=/dev/hda EOF echo "Bootloader (LILO) 書き込み中..." lilo -r $TR # LILO-Bootsektor in Datei schreiben (f? boot.ini von NT/2k) if [ $LBOOT = $FSCHOICE ] ; then dd if=$LBOOT of=$TR/linboot.img bs=512 count=1 fi # Bootdiskette erzeugen $DIA --backtitle "Knoppix Installation" --title "Bootdiskette erzeugen" \ --yesno "Boot Floppy を作成しますか?" 15 60 x=$? if [ $x = 0 ] ; then $DIA --backtitle "Knoppix Installation" --title "Bootdiskette erzeugen" \ --msgbox "フロッピーは初期化されます" 15 40 echo "ブートフロッピー作成中..." mformat -t 80 -h 2 -s 18 a: syslinux -sf /dev/fd0 mount -t vfat /dev/fd0 $TL1 cp $BKERNEL $TL1/vmlinuz [ -n "$INITRD" ] && cp $TR/boot/initrd.gz $TL1 cat <$TL1/syslinux.cfg default knoppix prompt 1 timeout 50 label knoppix kernel vmlinuz EOF echo -n " append root=$FSCHOICE ro vga=791 apm=power-off hda=scsi hdb=scsi hdc=scsi hdd=scsi hde=scsi hdf=scsi hdg=scsi hdh=scsi noapic" >>$TL1/syslinux.cfg if [ -n "$INITRD" ] ; then echo " initrd=initrd.gz" >>$TL1/syslinux.cfg else echo "" >>$TL1/syslinux.cfg fi [ $LBOOT = $FSCHOICE ] && cp $TR/linboot.img $TL1 umount $TL1 fi #echo -n "debug delay... " #read x # Templates entfernen rm -rf $TM # Loopdevices explizit l?en (sonst ist $FSCHOICE busy) for i in 7 6 5 4 3 2 1 0 do losetup -d /dev/loop$i >/dev/null 2>&1 done # Rootpartition unmounten umount $TR >/dev/null 2>&1 $DIA --backtitle "Knoppix Installation" --title "Beendet" \ --msgbox "インストール完了" 15 40 rm -f $TMP exit 0