#!/bin/sh # hd-install "Install live CD on Hard Drive # Based on Arch Linux 0.5 setup. # Markku (Rasatmakananda) # Date: 10 February 2004 ANSWER="/tmp/.setup" TITLE="Hard Drive installer" LOG="/dev/vc/5" DESTDIR="/mnt/copycd" LINUXVER="2.4.20-hwd.w4l" # sources SRC_READY=0 SYNC_SERVER= SYNC_PATH= # partitions PART_ROOT= PART_SWAP= # default filesystem specs (the + is bootable flag) # ::[:+] DEFAULTFS="/boot:32:ext2:+ swap:256:swap /:*:ext3" # install stages S_NET=0 S_PART=0 S_MKFS=0 S_MKFSAUTO=0 S_SELECT=0 S_INSTALL=0 S_LILOCONF=0 S_LILO=0 S_GRUBCONF=0 S_GRUB=0 S_KERNEL=0 KVER="$(uname -r)" # Check usb system case "$KVER" in 2.6.*) VER="2.6" ;; esac case "$KVER" in 2.4.*) VER="2.4" ;; esac [ `id -u` -ne 0 ] && { echo "This program must be run in root (login username: root)!" echo "" exit 1 } # Run HWD if [ -f /tmp/.hwd ]; then dummy="" else echo "Its recommended to run Hwd (hardware detect) before copying this CD to HD!!!" echo "Press any key to continue...." read KEY fi abort() { dodialog yesno "Exit Installer? (if you want to re-boot, press 'Ctrl-Alt Del')" 6 45 && exit 0 return 0 } msg() { dodialog msgbox "$1" return 1 } dodialog() { # use this for msgbox, inputbox, yesnobox, infobox # # dodialog [height] [width] [other] height=0 width=0 if [ "$3" != "" ]; then height=$3 fi if [ "$4" != "" ]; then width=$4 fi dialog --backtitle "$TITLE" --aspect 15 --$1 "$2" $height $width $5 } domenu() { menutype=$1 ; shift text=$1 ; shift height=$1 ; shift width=$1 ; shift mheight=$1 ; shift dialog --backtitle "$TITLE" --$menutype "$text" $height $width $mheight $* } convertdev() { newdev= # assume a regular devfs designation: /dev/discs/discX/partY end=`echo $1 | cut -d/ -f5 | cut -b-4` disc=`echo $1 | cut -d/ -f4 | cut -b5` if [ "$end" = "part" ]; then part=`echo $1 | cut -d/ -f5 | cut -b5` part=$(($part-1)) newdev="(hd${disc},$part)" elif [ "$end" = "disc" ]; then newdev="(hd${disc})" fi echo "$newdev" } _mkfs() { local _domk=$1 local _device=$2 local _fstype=$3 local _dest=$4 local _mountpoint=$5 if [ "${_fstype}" = "swap" ]; then _mountpoint="swap" swapoff ${_device} >/dev/null 2>&1 if [ "${_domk}" = "yes" ]; then mkswap ${_device} >$LOG 2>&1 if [ $? != 0 ]; then msg "Error creating swap: mkswap ${_device}" return 1 fi fi swapon ${_device} >$LOG 2>&1 if [ $? != 0 ]; then msg "Error activating swap: swapon ${_device}" return 1 fi elif [ "${_fstype}" = "reiserfs" ]; then if [ "${_domk}" = "yes" ]; then yes | mkreiserfs ${_device} >$LOG 2>&1 if [ $? != 0 ]; then msg "Error creating partition: mkreiserfs ${_device}" return 1 fi sleep 2 fi mkdir -p ${_dest}${_mountpoint} mount -t reiserfs ${_device} ${_dest}${_mountpoint} >$LOG 2>&1 if [ $? != 0 ]; then msg "Error mounting ${_dest}${_mountpoint}" return 1 fi elif [ "${_fstype}" = "ext2" ]; then if [ "${_domk}" = "yes" ]; then mke2fs "${_device}" >$LOG 2>&1 if [ $? != 0 ]; then msg "Error creating partition: mke2fs ${_device}" return 1 fi sleep 2 fi mkdir -p ${_dest}${_mountpoint} mount -t ext2 ${_device} ${_dest}${_mountpoint} >$LOG 2>&1 if [ $? != 0 ]; then msg "Error mounting ${_dest}${_mountpoint}" return 1 fi elif [ "${_fstype}" = "ext3" ]; then if [ "${_domk}" = "yes" ]; then mke2fs -j ${_device} >$LOG 2>&1 if [ $? != 0 ]; then msg "Error creating partition: mke2fs -j ${_device}" return 1 fi sleep 2 fi mkdir -p ${_dest}${_mountpoint} mount -t ext3 ${_device} ${_dest}${_mountpoint} >$LOG 2>&1 if [ $? != 0 ]; then msg "Error mounting ${_dest}${_mountpoint}" return 1 fi else msg "unknown fstype for ${_device}" return 1 fi # add to temp fstab echo -n "${_device} ${_mountpoint} ${_fstype} defaults 0 " >>/tmp/.fstab if [ "${_fstype}" = "reiserfs" -o "${_fstype}" = "swap" ]; then echo "0" >>/tmp/.fstab else echo "1" >>/tmp/.fstab fi } dolilo() { dodialog infobox "Installing LILO bootloader..." mount -t devfs none $DESTDIR/dev chroot $DESTDIR /sbin/lilo >$LOG 2>&1 if [ $? -gt 0 ]; then umount $DESTDIR/dev msg "Error installing LILO (see $LOG for output)." return 1 fi umount $DESTDIR/dev msg "LILO successfully installed." S_LILO=1 } dogrub() { if [ -f /tmp/.ConfigReady ]; then # busybox's find command doesn't support -or DEVS=`find /dev/discs -follow -name "disc" | sed 's|$| -|g'` DEVS="$DEVS `find /dev/discs -follow -name "part[0-9]" | sed 's|$| -|g'`" if [ "$DEVS" = "" ]; then msg "No hard drives were found" return 1 fi domenu menu "Select the boot device where Grub will be installed" 14 55 7 $DEVS 2>$ANSWER || return 1 ROOTDEV=`cat $ANSWER` dodialog infobox "Installing the GRUB bootloader..." cp -a $DESTDIR/usr/share/grub/i386-pc/* $DESTDIR/boot/grub/ # look for a separately-mounted /boot partition bootpart=`mount | grep $DESTDIR/boot | cut -d' ' -f 1` if [ "$bootpart" = "" ]; then if [ "$PART_ROOT" = "" ]; then dodialog inputbox "Enter the full devfs path to your root device" 8 65 "/dev/discs/disc0/part3" 2>$ANSWER || return 1 bootpart=`cat $ANSWER` else bootpart=$PART_ROOT fi fi bootpart=`convertdev $bootpart` bootdev=`convertdev $ROOTDEV` if [ "$bootpart" = "" ]; then msg "Error: Missing/Invalid root device: $bootpart" return 1 fi $DESTDIR/sbin/grub --batch 2>&1 >/tmp/grub.log <$LOG if grep "Error [0-9]*: " /tmp/grub.log >/dev/null; then msg "Error installing GRUB. (see $LOG for output)" return 1 fi msg "GRUB was successfully installed." S_GRUB=1 else msg "Check lilo.conf to be sure it is correct.. Select step 3 'Edit Config Files' then 'Bootloader Config'." fi } partition() { # # Select disk to partition # dodialog yesno "If you have a swap and linux partition, press NO and go to step 2 'Set Filesystem Mountpoints'. To continue press Yes." 8 60 || return 0 dialog --backtitle "$TITLE" --menu "Partition Hard Drives" 12 65 5 \ "1" "Simple console to add new partitions." \ "2" "Parted - add, resize and move (console)." \ "3" "QTParted - Partition Magic clone (GUI)." \ "4" "Return to Main Menu" 2>$ANSWER case `cat $ANSWER` in "1") # # Select disk to partition # DISCS=`find /dev/discs/disc* | sed 's|$|/disc -|g'` DISCS="$DISCS OTHER -" domenu menu "Select the disk you want to partition" 14 55 7 $DISCS 2>$ANSWER || return 1 DISC=`cat $ANSWER` if [ "$DISC" = "OTHER" ]; then dodialog inputbox "Enter full path to the device you wish to partition" 8 65 "/dev/discs/disc0/disc" 2>$ANSWER || return 1 DISC=`cat $ANSWER` fi while [ "$DISC" != "DONE" ]; do # # Partition disc # msg "You'll be put into the cfdisk program where you can partition your hard drive. You should make one Linux swap partition (256MB) and one Linux partition (1GB or higher)." cfdisk $DISC DISCS=`find /dev/discs/disc* | sed 's|$|/disc _|g'` DISCS="$DISCS OTHER -" domenu menu "Select the disk you want to partition" 14 55 7 $DISCS DONE + 2>$ANSWER || return 1 DISC=`cat $ANSWER` if [ "$DISC" = "OTHER" ]; then dodialog inputbox "Enter the full path to the device you wish to partition" 8 65 "/dev/discs/disc0/disc" 2>$ANSWER || return 1 DISC=`cat $ANSWER` fi done ;; "2") msg "When asked press "i" to ignore. At parted prompt type 'help' to print general help, or help on COMMAND." parted ;; "3") dodialog yesno "QTparted runs in KDE and other X windows only!! Press YES for X window." 8 60 || return 0 qtparted ;; *) DONE=1 ;; esac } mountpoints() { # # Select mountpoints # dodialog yesno "If you DON'T have a swap and linux partition, press NO and go to step 1 'Partition Hard Drives'. To continue press Yes." 8 60 || return 0 if [ -f /tmp/udev.tmp ]; then msg "Next screen is a list of your HD partitions (udev format e.g. /dev/hda1)." PARTS=`find /dev -follow -name "hd*[1-9]" | sed 's|$| _|g'` else msg "Next screen is a list of your HD partitions (devfs format e.g. /dev/discs/disc0/part1 = hda1)." PARTS=`find /dev/discs -follow -name "part*" | sed 's|$| _|g'` fi domenu menu "Select the partition to use as swap" 14 55 7 $PARTS 2>$ANSWER || return 1 PART=`cat $ANSWER` PART_SWAP=$PART DOMKFS="no" dodialog yesno "Would you like to create a filesystem in $PART?\n\n(This will overwrite existing data!)" && DOMKFS="yes" echo "$PART:swap:swap:$DOMKFS" >>/tmp/.parts domenu menu "Select the partition to mount as /" 14 55 7 $PARTS 2>$ANSWER || return 1 PART=`cat $ANSWER` PART_ROOT=$PART # Select root filesystem type domenu menu "Select filesystem for $PART (if unsure select 'ext3')." 10 50 3 ext2 Ext2 ext3 Ext3 reiserfs Reiser 2>$ANSWER || return 1 FSTYPE=`cat $ANSWER` DOMKFS="no" dodialog yesno "Would you like to create a filesystem in $PART?\n\n(This will overwrite existing data!)" && DOMKFS="yes" echo "$PART:$FSTYPE:/:$DOMKFS" >>/tmp/.parts # add to temp fstab echo "$PART_SWAP swap swap defaults 0 0" >> /etc/.fstab echo -n "$PART_ROOT / $FSTYPE defaults 0 " >> /etc/.fstab if [ "$FSTYPE" = "ext2" ]; then echo "1" >> /etc/.fstab else echo "0" >> /etc/.fstab fi # add to temp lilo.conf if [ "$VER" = "2.6" ]; then echo " root=$PART_ROOT" >> /etc/.lilo.conf_26 echo " read-only" >> /etc/.lilo.conf_26 echo "" >> /etc/.lilo.conf echo "##NOTE: kernel 2.4.x use diffrent usb module. Check /etc/rc.conf if" >> /etc/.lilo.conf_26 echo "##you untag the below image." >> /etc/.lilo.conf_26 echo "" >> /etc/.lilo.conf_26 echo "# image=/boot/vmlinuz24-w4l.hwd" >> /etc/.lilo.conf_26 echo "# label=Arch-24" >> /etc/.lilo.conf_26 echo "# root=$PART_ROOT" >> /etc/.lilo.conf_26 echo "# read-only" >> /etc/.lilo.conf_26 echo "" >> /etc/.lilo.conf_26 else echo "# root=$PART_ROOT" >> /etc/.lilo.conf_24 echo "# read-only" >> /etc/.lilo.conf_24 echo "" >> /etc/.lilo.conf_24 echo "image=/boot/vmlinuz24-w4l.hwd" >> /etc/.lilo.conf_24 echo " label=Arch-24" >> /etc/.lilo.conf_24 echo " root=$PART_ROOT" >> /etc/.lilo.conf_24 echo " read-only" >> /etc/.lilo.conf_24 echo "" >> /etc/.lilo.conf_24 fi echo "## Untag below lines if you have Windows on your Hard Drive" >> /etc/.lilo.conf_26 echo "" >> /etc/.lilo.conf_26 echo "# other=/dev/hda1" >> /etc/.lilo.conf_26 echo "# label=Windows" >> /etc/.lilo.conf_26 echo "## Untag below lines if you have Windows on your Hard Drive" >> /etc/.lilo.conf_24 echo "" >> /etc/.lilo.conf_24 echo "# other=/dev/discs/disc0/part1" >> /etc/.lilo.conf_24 echo "# label=Windows" >> /etc/.lilo.conf_24 echo "" >> /tmp/.readyToCopy for line in `cat /tmp/.parts`; do PART=`echo $line | cut -d: -f 1` FSTYPE=`echo $line | cut -d: -f 2` MP=`echo $line | cut -d: -f 3` DOMKFS=`echo $line | cut -d: -f 4` umount $MP if [ "$DOMKFS" = "yes" ]; then dodialog infobox "Creating $FSTYPE on $PART, mounting to ${DESTDIR}${MP}" _mkfs yes $PART $FSTYPE $DESTDIR $MP || return 1 else dodialog infobox "Mounting $PART to ${DESTDIR}${MP}" _mkfs no $PART $FSTYPE $DESTDIR $MP || return 1 fi sleep 1 done msg "Partitions were successfully mounted." S_MKFS=1 } donetwork() { DETECT="no" dodialog yesno "Do you want auto detect your Ethernet / PCMCIA card and copy the configure in HDD? " && DETECT="yes" if [ "$DETECT" = "yes" ]; then msg "This will detect Ethernet or PCMCIA card and adds 'modprobe' command and the module in /etc/rc.local." # Check /proc/modules with PCMCIA and net modlues. hwsetup -p >/dev/null [ -x /usr/sbin/check_net ] && /usr/sbin/check_net echo "Press any key to continue..." read KEY fi if [ "$DETECT" = "no" ]; then msg "No auto detect selected. In HDD load your Ethernet or PCMCIA card module(s) manually!" fi dodialog yesno "Do you want to use DHCP in HDD? This will add 'modprobe dummy' and 'dhcpcd eth0' in /etc/rc.local" if [ $? -eq 0 ]; then echo "dhcpcd eth0" >>/etc/.rc.local msg "Network is configured in HD" else dodialog yesno "Do you want to setup ADSL connection in HDD?" 8 50 || return 0 adsl-setup msg "Trying to test the connect (adsl-start)...." adsl-start echo "Press any key to continue...." read KEY if [ -f /var/run/pppoe.conf-adsl.pid.start ]; then msg "The network is configured on HD." return 0 else msg "The network is NOT configured!!" fi fi S_NET=1 } copyCD () { # # Copy CD to the selected partition # if [ -f /tmp/.readyToCopy ]; then msg "To copy the entire CD takes about 25 minutes depending on your processor." 12 65 dodialog yesno "You selected partitition $PART_ROOT. Ready to copy?" 6 50 || return 0 echo "" echo -e "\033[1;33mPlease wait, CD to HD is in process...\033[0m " if [ -a /mnt/copycd/lost+found ]; then rm -R /mnt/copycd/lost+found fi echo -n "1st stage: " echo -n "bin.. " cp -Ra /cdrom/system/bin /mnt/copycd/ echo -n "boot.. " cp -Ra /cdrom/system/boot /mnt/copycd/ echo -n "usr.. " cp -Ra /cdrom/system/usr /mnt/copycd/ echo -n "dev.. " cp -Ra /cdrom/system/dev /mnt/copycd/ echo -n "etc.. " cp -Ra /cdrom/system/etc /mnt/copycd/ rm -R /mnt/copycd/etc/hwd rm -R /mnt/copycd/etc/X11 cp -Ra /cdrom/system/etc/X11 /mnt/copycd/etc/ cd /mnt/copycd/etc/ rename hwd_org hwd hwd_org cd / echo "home.. " rm -R /home/httpd cp -Ra /home /mnt/copycd/ chown -R amlug:users /mnt/copycd/home/ cp -Ra /cdrom/system/home/httpd /mnt/copycd/home/ echo -e "\033[1;33mPress any key to continue...\033[0m " read KEY echo -n "2nd stage: " echo -n "lib.. " cp -Ra /cdrom/system/lib /mnt/copycd/ echo -n "mnt.. " cp -Ra /cdrom/system/mnt /mnt/copycd/ echo -n "opt.. " cp -Ra /cdrom/system/opt /mnt/copycd/ echo -n "proc.. " cp -Ra /cdrom/system/proc /mnt/copycd/ echo "root.. " cp -Ra /root /mnt/copycd/ echo -n "sbin.. " cp -Ra /cdrom/system/sbin /mnt/copycd/ echo -n "sys.. " cp -Ra /cdrom/system/sys /mnt/copycd/ echo -n "tmp.. " cp -Ra /cdrom/system/tmp /mnt/copycd/ echo -n "var.. " cp -Ra /cdrom/system/var /mnt/copycd/ if [ -f /usr/X11R6/bin/xorgcfg ]; then SERVERx="Xorg" conf_hwd="xorg.conf.hwd" conf_file="xorg.conf" conf_tool="xorgcfg" else SERVERx="XFree86" conf_hwd="XF86Config-4.hwd" conf_file="XF86Config-4" conf_tool="xf86cfg" fi echo "system files.. " if [ -f /etc/X11/$conf_file ]; then dummy="" else cp -f /etc/X11/$conf_hwd /etc/X11/$conf_file fi donetwork cp -f /etc/X11/$conf_file /mnt/copycd/etc/X11/ cp -f /etc/.fstab /mnt/copycd/etc/fstab if [ "$VER" = "2.6" ]; then echo "Configuring LILO with udev for kernel 2.6.6" echo "To use devfs edit LILO before loading bootloader. " cp -f /etc/.lilo.conf_26 /mnt/copycd/etc/lilo.conf else echo "Configuring LILO for kernel 2.4.24" cp -f /etc/.lilo.conf_24 /mnt/copycd/etc/lilo.conf fi cp -f /etc/.rc.local /mnt/copycd/etc/rc.local cp -f /etc/.rc.conf /mnt/copycd/etc/rc.conf cp -Rfa /etc/dhcpc /mnt/copycd/etc/ cp -Rfa /etc/ppp /mnt/copycd/etc/ cp -f /etc/resolv.conf /mnt/copycd/etc/ if [ -f /mnt/copycd/etc/dhcpc/dhcpcd-eth0.pid ]; then rm /mnt/copycd/etc/dhcpc/dhcpcd-eth0.pid fi if [ "$VER" = "2.6" ]; then echo "usbfs /proc/bus/usb usbfs defaults 0 0" >> /mnt/copycd/etc/fstab echo "none /dev/pts devpts defaults 0 0" >> /mnt/copycd/etc/fstab fi rm /mnt/copycd/usr/bin/hd-install rm /mnt/copycd/usr/bin/tdu-install rm /mnt/copycd/usr/bin/net-install echo "" echo "3rd stage installs MySQL, doc and man page files. " echo "" echo "Installing MySQL... " cd /mnt/copycd/var/lib tar zxf mysql.tar.gz rm mysql.tar.gz cd / rm /mnt/copycd/usr/man/man8/howto.8 rm /mnt/copycd/usr/man/man8/howto.8.gz rm /mnt/copycd/usr/share/hwdata/pci.ids rm /mnt/copycd/usr/share/hwdata/pcitable cp -f howto.8 /mnt/copycd/usr/man/man8/ cp -f howto.8.gz /mnt/copycd/usr/man/man8/ cp -f pci.ids /mnt/copycd/usr/share/hwdata/ cp -f pcitable /mnt/copycd/usr/share/hwdata/ echo "Uncompressing doc and man page files... " cd /mnt/copycd tar xjpf /cdrom/system/doc-man.tar.bz2 echo "Deleting temporary TRANS.TBL files... " cd / find /mnt/copycd/ \( -name TRANS.TBL \) -exec rm {} \; msg "CD is successfully copied. Install Bootloader (LILO) before rebooting the system." 15 65 rm -f /tmp/.readyToCopy echo "" >> /tmp/.MountpoinReady S_PART=1 else msg "Select swap and mount one partition as root before copying CD to HD. Go to step 1 'Prepare Hard Drive'." 8 65 fi } hwdcheck() { dodialog yesno "Hwd will ckeck your x-window and sound configure and copies to HD during install. To continue press Yes." 6 60 || return 0 hwd -s msg "Hardware detect completed." 8 60 } mainmenu() { dialog --backtitle "$TITLE" --title "MAIN MENU" \ --menu "Use the UP and DOWN arrows to navigate menus. Use TAB to switch between buttons and ENTER to select." 16 55 8 \ "1" "Hwd - hardware detect" \ "2" "Prepare Hard Drive" \ "3" "Copy CD to HD" \ "4" "Edit Config Files" \ "5" "Install Bootloader" \ "6" "Exit" 2>$ANSWER EDITOR= case `cat $ANSWER` in "1") hwdcheck ;; "2") DONE=0 while [ "$DONE" = "0" ]; do dialog --backtitle "$TITLE" --menu "Prepare Hard Drive" 12 60 4 \ "1" "Partition Hard Drives" \ "2" "Set Swap, Mountpoint and Filesystem" \ "3" "Return to Main Menu" 2>$ANSWER case `cat $ANSWER` in "1") partition ;; "2") mountpoints ;; *) DONE=1 ;; esac done ;; "3") copyCD ;; "4") if [ -f /tmp/.MountpoinReady ]; then if [ "$EDITOR" = "" ]; then echo "" >> /tmp/.ConfigReady dialog --backtitle "$TITLE" --menu "Select a Text Editor to Use" 10 35 3 \ "1" "vi clone" \ "2" "nano (easier)" 2>$ANSWER case `cat $ANSWER` in "1") EDITOR="vi" ;; "2") EDITOR="nano" ;; esac fi else msg "This function is not active until CD is installed on Hard Drive." 8 50 fi DONE=0 while [ "$EDITOR" != "" -a "$DONE" = "0" ]; do dialog --backtitle "$TITLE" --menu "Configuration" 17 65 11 \ "/etc/rc.conf" "System Config" \ "/etc/lilo.conf" "Bootloader Config" \ "/etc/hosts" "Networking" \ "/etc/fstab" "Filesystem Mountpoints" \ "/etc/modules.conf" "Kernel Modules" \ "/etc/resolv.conf" "Dns Servers" \ "/etc/rc.local" "Start Up Files" \ "_" "Return to Main Menu" 2>$ANSWER FILE=`cat $ANSWER` if [ "$FILE" = "_" -o "$FILE" = "" ]; then DONE=1 else $EDITOR ${DESTDIR}${FILE} if [ "$FILE" = "/etc/lilo.conf" ]; then S_LILOCONF=1 fi fi done ;; "5") if [ -f /tmp/.ConfigReady ]; then dialog --backtitle "$TITLE" --menu "Select option." \ 10 55 2 \ "LILO" "Use the LILO bootloader" \ "NO" "No bootloader" 2>$ANSWER case `cat $ANSWER` in "LILO") dolilo ;; "NO") DONE=1 ;; esac else msg "Check lilo.conf to be sure it is correct.. Select step 3 'Edit Config Files' then 'Bootloader Config'." fi ;; "6") abort ;; esac } if [ -f /tmp/.readyToCopy ]; then rm /tmp/.readyToCopy fi if [ "$VER" = "2.6" ]; then dodialog msgbox "To use this CD to HD installer run through the options in the order they are presented." 6 60 dodialog yesno "Kernel 2.6.6 will be installed in HD. To install 2.4.24 reboot this live CD with linux24 or untag the image in /etc/lilo.conf after this install. To continue press Yes." 8 60 || abort else dodialog msgbox "To use this CD to HD installer run through the options in the order they are presented." 8 60 dodialog yesno "Kernel 2.4.24 will be installed in HD. To install 2.6.6 reboot this live CD with linux26 or untag the image in /etc/lilo.conf after this install. To continue press Yes." 8 60 || abort fi loop() { while `/bin/true`; do mainmenu done } loop exit 0