All pastes #475944 Raw Edit

ubuntuLiveCdUsbBoot2

public shellscript v1 · immutable
#475944 ·published 2007-05-07 20:07 UTC
rendered paste body
#!/bin/bash# This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; version 2 of the License.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the# GNU General Public License for more details.################################################# Creator:		Raxius# Credits:		The tutorial at http://www.pendrivelinux.com/2007/02/12/usb-ubuntu-tutorial-for-linux-users/ inspired me# Last Modified:	07.05.2007################################################DEVICE=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. Use su or sudo."		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 "	--help			Shows this help text."	echo "	--install-prereqs	Install all programs needed for this to run"	echo "	--create		Creates the image on the usb stick. All data on this device will be DESTROYED."	echo "		device		The device file of the usb stick, usually /dev/sdX"	echo "		sourcedir	The directory that contains the mounted ubuntu image"	echo "Note: You must have lilo, sfdisk, dd, syslinux and mtools installed."}installPrereqs(){	apt-get install lilo syslinux mtools	}case "$1" in	"--help")		help;		;;	"--install-prereqs")		installPrereqs;		;;	"--create")		DEVICE="$2"		SRC_DIR="$3"		mkUbuntuUsbBootImage;		;;	*)		help;		;;esac