All pastes #475915 Raw Edit

ubuntuLiveCdUsbBoot

public shellscript v1 · immutable
·published 2007-05-07 19:36 UTC
rendered paste body
#!/bin/bashDEVICE=DEST_PARTITION=TMP_MOUNTPOINT="/tmp/${RANDOM}_usb_mount"SYSLINUX_CFG_FILE="/tmp/syslinux.cfg"SRC_DIR=FILES_TO_COPY="casper disctree dists install pics pool preseed .disk isolinux/* md5sum.txt README.diskdefines ubuntu.ico casper/vmlinuz casper/initrd.gz install/mt86plus"mkUbuntuUsbBootImage(){	# check params	if [ ! -b "$DEVICE" ]; then		echo "The given device is not a valid block device."		exit 1	fi	if [ ! -d "$SRC_DIR" ]; then		echo "The source directory is not valid."		exit 2	fi	uid=`id -u`	if [ "$uid" != "0" ]; then		echo "You must be root to use this script."		exit 3	fi	echo "$DEVICE1"	DEST_PARTITION=${DEVICE}"1"	echo "**********************************************"	echo "* Destination Device: $DEVICE"	echo "* Source Directory: $SRC_DIR"	echo "*"	echo "* Destination Partition: $DEST_PARTITION"	echo "**********************************************"	echo "Umount the destination device."	umount "$DEST_PARTITION"	echo "Delete the mbr."	dd if=/dev/zero of="$DEVICE" bs=512 count=1	echo "Write new mbr."	echo ',,6,*' | sfdisk "$DEVICE"	# the auto mounter mounts it	umount "$DEST_PARTITION"	echo "Create FAT16 filesystem."	mkfs.vfat -F 16 -n usb "$DEST_PARTITION"	echo "Prepare the usbstick for booting."	syslinux -sf "$DEST_PARTITION"	echo "Ensure that the mbr is proper."	lilo -M "$DEVICE"	# create temporary mount point	mkdir "$TMP_MOUNTPOINT"	# mount the usb stick	mount "$DEST_PARTITION" "$TMP_MOUNTPOINT"	if [ ! -f "$SYSLINUX_CFG_FILE" ]; then		getSysLinuxCfg	fi	# copy the syslinux config file to the usb stick	echo "Copy syslinux configuration file to the destination device."	cp "$SYSLINUX_CFG_FILE" "$TMP_MOUNTPOINT"	# go to the directory that contains the ubuntu	cd "$SRC_DIR"	# copy ubunto to the usb stick	echo "Copy the Ubuntu Live System image to the device."	cp -rf ${FILES_TO_COPY} "$TMP_MOUNTPOINT"	umount "$DEST_PARTITION"	echo "Operation successful. You can now safely plug out your usb device."}getSysLinuxCfg(){	TMP_FILE="/tmp/${RANDOM}_syslinux_cfg_file"	# download the config file	echo "Download syslinux configuration file."	wget "http://pendrivelinux.com/downloads/usyslinux.tar" -O "$TMP_FILE"	# untar it	echo "Download succeded, untar it."	cd /tmp	tar -xf "$TMP_FILE"}help(){	# echo the help	echo "Usage: $0 operation device sourcedir"	echo "	--create"	echo "		device		The device file of the usb stick"	echo "		sourcedir	The directory that contains the ubuntu image"	echo "Note: You must have lilo, sfdisk, dd, syslinux and mtools installed."}case "$1" in	"--help")		help;		;;	"--create")		DEVICE="$2"		SRC_DIR="$3"		mkUbuntuUsbBootImage;		;;	*)		help;		;;esac