# this script will create a bootable debian system on the specified device (normally for an usb-key)
# this script is provided AS IS, without any WARRANTY.
# written by bomboclat@malasystem.com
# this script is published under the GPL licence
# thanks for all the ideas published on http://feraga.com/node/25
DEVICE="$1"
DEST="/mnt/buildroot"
USBNAME="$2"
modprobe ehci_hcd &>/dev/null
modprobe ohci_hcd &>/dev/null
modprobe usbhid &>/dev/null
modprobe usb_storage &>/dev/null
function help() {
echo -e "Usage:\t$0 devicename systemname\n\twhere devicename is where your usb key is (/dev/sda for example)\n\tand devicename is to set the hostname for your new system on usb-key."
exit 1
}
function muori() {
if [ "$?" != "0" ]; then
echo -e "$1\n"
exit 1
fi
}
if [ -z "$DEVICE" ] ; then
help
echo -e "\nHint!\ton which device?\n"
fi
if [ -z "$USBNAME" ] ; then
help
echo -e "\nHint!\twouldn't you give an hostname to your usb-system?\n"
echo -e "\n*** WARNING!! this script will DESTROY all the data contained in $DEVICE.\n*** exit now pressing ctrl+C if not sure. you have 5 seconds to decide.\n"
echo -e "*** the name provided is not a valid name for the kernel package\n"
CHECK="NOTOK"
else
CHECK="OK"
chroot $DEST LC_ALL=C apt-get install $REPLY
if [ $? != "0" ] ; then
muori "something went wrong with your kernel installation.\nYou can check this later, by chrooting into the key and re-run the install, BUT do this before rebooting your usb-key, becouse it will not work with a wrong kernel install."
fi
fi
done
VERSION="`ls $DEST/boot | grep vmlinuz | sed -e 's/vmlinuz-//'`"
[ $? = "0" ] && echo -e "*** will now set the root password for your new system." \
|| muori "I'm sorry. something went wrong with grub installation.\nChroot into the usb-key and try yourself."
chroot $DEST passwd root
echo -e "*** would you run localepurge to delete some useless locales and free some space on your installed usb-key system?\n\n[Y/n]"
read
if [ "$REPLY" == "n" ] ; then
umount "$DEVICE"1 && umount "$DEVICE"2
[ "$?" = "0"] && echo -e "*** we have now fineshed succesfully the installation. Try and reboot.\n" \
|| muori "check your mounted partitions on $DEST. I couldn't umount them.\nis there some program running in that partitions?\nfuser -m $DEST should provide some infos and fuser -k -m $DEST should do the work for you."
else
chroot $DEST apt-get install localepurge
chroot $DEST localepurge
[ "$?" = "0"] && echo "*** we have now fineshed succesfully the installation. Try and reboot.\n" \
|| muori "something went wrong, but this step should be optional and the system should work anyway. Good luck!"
I wrote a script for doing all this