Saturday, September 6, 2008

Creating Bootable USB from System Rescue CD

Creating Bootable USB from System Rescue CD
In order to create bootable USB stick from CD image (ISO file)
of System Rescue Linux, generally we follow steps given
in this link. After following instructions given, I have created
a small shell script to create bootable rescue USB.

The contents of the script create_rescue_usb.sh are:
$ cat create_rescue_usb.sh
#!/bin/bash

if [[ $# < 4 ]]
then
  echo "Usage: $0 CDROM_Device CDROM_mount USB_Device USB_mount"

  exit

fi


CDROM_Device=$1

CDROM_mount=$2
USB_Device=$3

USB_mount=$4


if
 [[ -e $CDROM_Device ]]
then
  echo "$CDROM_Device is present."
else
  echo "$0: $CDROM_Device is not present."
  exit
fi

if
 [[ -e $USB_Device ]]
then
  echo "$USB_Device is present."
else
  echo "$0: $USB_Device is not present."
  exit
fi

echo "Mounting..."
mount -o loop $CDROM_Device $CDROM_mount

if
 [ $? -ne 0 ]
then

  echo "$0: cannot mount $CDROM_Device on $CDROM_mount."
  exit
fi

mount $USB_Device $USB_mount


i
f [ $? -ne 0 ]
then

  echo "$0: cannot mount $USB_Device on $USB_mount."
  umount $CDROM_mount
  exit
fi

echo "Copying Files..."
cp $CDROM_mount/syslinux/syslinux.cfg $USB_mount/
cp -r $CDROM_mount/isolinux/* $USB_mount/
cp -r $CDROM_mount/bootdisk/* $USB_mount/
cp $CDROM_mount/sysrcd.dat $USB_mount/

echo "Unmounting..."
umount $USB_mount
umount $CDROM_mount

echo "Making $USB_Device bootable..."
syslinux $USB_Device
sync

echo "$USB_Device is now ready to serve as bootable Linux USB."
#end of script


Now, you can make it executable.
$ chmod u+x create_rescue_usb.sh

Sample execution of above script (Please run as root user):
# ./create_rescue_cd.sh /path/of/system-rescue-cd.iso /mnt/cdrom /dev/sdb /mnt/usb

Where,
a. /path/of/system-rescue-cd.iso -- ISO image of the CD can be created as given in blog Creation of ISO Image of CD/DVD.
b. /mnt/cdrom -- directory, where you want to mount above ISO.
c. /dev/sdb -- or /dev/sdb1, your usb-stick device. May differ
according to your system configuration
d. /mnt/usb -- directory, where you want to mount usb-stick.

Now, your usb stick is ready to serve as bootable rescue USB.
You can test it. At the time of BIOS boot, please select USB device
as first boot device in BIOS. then save and reboot with the usb-stick
plugged in one USB port.

No comments: