2008-11-06

Copy Knoppix to HD

# How to set up a "Poor Man's Install" so that the machine boots from a CD
# image that's been copied to the hard disk.  GRUB is used as the boot loader.
# It is assumed that you are booted to Knoppix CD 5.1.1, and ALL HARD DISK
# CONTENTS WILL BE ERASED!!!

#  0.  Switch to root with su -

#  1.  Partition the hard disk as follows (minimum 20GB hard disk recommended)
#      10GB /dev/hda1, type 83
#      2GB /dev/hda2, type 82
#      (the rest of the disk) /dev/hda3, type 83
#

# determine the disk device name, which is usually /dev/hda for IDE and
# /dev/sda for SATA

DEVICE=`fdisk -l 2>/dev/null | head -2 | tail -1 | awk '{print $2}' | sed 's/\:$//'`

# print warning and confirmation
clear
echo "This CD will install Knoppix 5.1 on your hard disk."
echo "The system will then boot from the hard disk as if you had booted from"
echo "the Knoppix CD, also known as a Poor Man's Install."
echo
echo "WARNING:"
echo "ALL EXISTING DATA ON THE HARD DISK $DEVICE WILL BE ERASED BY THIS PROCESS!!!"
echo
echo -n "Do you wish to continue? (y/n): "
read ANSWER
if [ "$ANSWER" = "y" -o "$ANSWER" = "Y" ]
then
:
else
  echo "Installation aborted!"
  sleep 3
  exit
fi


# clear the old partition table
dd if=/dev/zero of=$DEVICE bs=512 count=1

# determine the cylinder size
CYL_SIZE=`fdisk -l $DEVICE 2>/dev/null | grep "Units = cylinders" | awk '{print $9}'`

# determine the number of cylinders in 10GB
SIZE1=`echo "1073741824 * 10 / $CYL_SIZE" | bc`

# determine the number of cylinders in 2GB
SIZE2=`echo "1073741824 * 2 / $CYL_SIZE" | bc`

# partition the disk
sfdisk -f $DEVICE <<EOF
,$SIZE1,L
,$SIZE2,S
,,L
EOF


#  2.  Create an ext3 filesystem on the first and third partitions
mke2fs -j -m0 ${DEVICE}1
mke2fs -j -m0 ${DEVICE}3


#  3.  Create a swap area on the second partition
mkswap ${DEVICE}2


#  4.  Mount first partition on /media/p1
mkdir /media/p1
mount ${DEVICE}1 /media/p1


#  5.  Copy the contents of the Knoppix CD to /media/p1
echo
echo "Copying CD contents to hard drive.  This will take a few minutes."
/bin/cp -af /cdrom/KNOPPIX /media/p1

# remove /media/p1/KNOPPIX/knoppix.sh
/bin/rm -f /media/p1/KNOPPIX/knoppix.sh


#  6.  Create a boot directory on /media/p1 and copy the kernel and initrd
#      there
mkdir /media/p1/boot
/bin/cp -af /boot/vmlinuz-2.6.19 /media/p1/boot
/bin/cp -af /cdrom/boot/isolinux/minirt.gz /media/p1/boot


#  7.  Create a directory for GRUB
mkdir /media/p1/boot/grub


#  8.  Populate the GRUB config file.  If you require different default boot
#      options, include them in the kernel line.
cat <<EOF > /media/p1/boot/grub/menu.lst
default=0
timeout=10

title Knoppix 5.1 (Poor Man's HD install)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.19 ramdisk_size=100000 init=/etc/init lang=us apm=power-off vga=normal initrd=minirt.gz nomce loglevel=0 quiet BOOT_IMAGE=knoppix BOOT_IMAGE=linux lang=us fromhd=${DEVICE}1 noeject noprompt
        initrd /boot/minirt.gz
EOF
cd /media/p1/boot/grub
ln -s menu.lst grub.conf


#  9.  Install GRUB
cd /media/p1
grub-install --root-directory=/media/p1 --no-floppy $DEVICE


#  10.  Reboot (and remove CD)
reboot