Live OS CD to USB Script

Prerequisites:
1. Insert your LiveOS CD/DVD and USB drive.
2. CR drive is automatically selected and USB drive you need to choose when prompted.
3. By default, script takes whole device, in case of partition, you need to create and mention it.
4. Size of USB drive should be same or more than that of CD/DVD drive/image size.

Live OS CD to USB Writer Tool or Script enables you to write your Live Linux Operating System CD to a USB drive.

 

I. Download Script

[root@nglinux ]# mkdir /usr/nglinux; cd $_;  \
wget --auth-no-challenge http://ngelinux.com/scripts/ngelinux_usb_install.sh; \
wget --auth-no-challenge http://ngelinux.com/scripts/livecd-iso-to-disk; \
chmod +x ./livecd-iso-to-disk ./ngelinux_usb_install.sh;

II. Writing LiveCD to a USB drive

a. Successful attempt

[root@nglinux ]# ./ngelinux_usb_install.sh
This Script will copy the NGE Linux CD/DVD to a USB Disk and make it bootable..
Select the disk for installation
1. Disk /dev/sda: 8589 MB, 8589934592 bytes
2. Disk /dev/sdb: 8589 MB, 8589934592 bytes
3. Other
2
You have selected Disk Disk /dev/sdb: 8589 MB, 8589934592 bytes
The disk is going to be formatted.
WARNING !! All data on Disk /dev/sdb: 8589 MB, 8589934592 bytes will be erased. Are you sure(y/n) ?
y
Formatting Disk Disk /dev/sdb: 8589 MB, 8589934592 bytes in ext4 format....
mke2fs 1.41.12 (17-May-2010)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
524288 inodes, 2097152 blocks
104857 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
FORMAT Complete...
Now transferring the image file to /dev/sdb device...
Verifying image...

The media check is complete, the result is: NA.

No checksum information available, unable to verify media.
Are you SURE you want to continue?
Press Enter to continue or ctrl-c to abort

Copying live image to USB stick
progress 65536/1722208256 (64.0 KB/s)
progress 131072/1722208256 (128.0 KB/s)
progress 196608/1722208256 (192.0 KB/s)
progress 262144/1722208256 (256.0 KB/s)
progress 327680/1722208256 (320.0 KB/s)
progress 393216/1722208256 (384.0 KB/s)
progress 458752/1722208256 (448.0 KB/s)
progress 524288/1722208256 (512.0 KB/s)
progress 589824/1722208256 (576.0 KB/s)
progress 655360/1722208256 (640.0 KB/s)
......
......
progress 1721630720/1722208256 (17.1 MB/s)
progress 1721696256/1722208256 (17.1 MB/s)
progress 1721761792/1722208256 (17.1 MB/s)
progress 1721827328/1722208256 (17.1 MB/s)
progress 1721892864/1722208256 (17.1 MB/s)
progress 1721958400/1722208256 (17.1 MB/s)
progress 1722023936/1722208256 (17.1 MB/s)
progress 1722089472/1722208256 (17.1 MB/s)
progress 1722155008/1722208256 (17.1 MB/s)
progress 1722208256/1722208256 (17.1 MB/s)
progress 1722208256/1722208256 (17.1 MB/s)
Updating boot config file
Initializing persistent overlay file
0+0 records in
0+0 records out
0 bytes (0 B) copied, 3.2193e-05 s, 0.0 kB/s
Initializing persistent /home
0+0 records in
0+0 records out
0 bytes (0 B) copied, 4.9793e-05 s, 0.0 kB/s
Formatting unencrypted /home
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
51200 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks: 
	8193, 24577, 40961, 57345, 73729

Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
tune2fs 1.41.12 (17-May-2010)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds
Installing boot loader
/media/usbdev.Z3xSqZ/syslinux is device /dev/sdb
USB stick set up as live image!
The NG Linux 1.0 is now installed on device /dev/sdb. Just reboot the system and check the live OS installation your USB/disk.
Press any key to exit ....
[root@nglinux ]# 

b. Unsuccessful Attempt
In case device is used.

[root@nglinux nglinux]# ./ngelinux_usb_install.sh 
This Script will copy the NGE Linux CD/DVD to a USB Disk and make it bootable..
Select the disk for installation
1. Disk /dev/sdb: 8589 MB, 8589934592 bytes
2. Disk /dev/sda: 34.4 GB, 34359738368 bytes
3. Other
2
You have selected Disk Disk /dev/sda: 34.4 GB, 34359738368 bytes
The disk is going to be formatted.
WARNING !! All data on Disk /dev/sda: 34.4 GB, 34359738368 bytes will be erased. Are you sure(y/n) ?
y
Formatting Disk Disk /dev/sda: 34.4 GB, 34359738368 bytes in ext4 format....
mke2fs 1.41.12 (17-May-2010)
/dev/sda is entire device, not just one partition!
Proceed anyway? (y,n) y
/dev/sda is apparently in use by the system; will not make a filesystem here!
Error encountered in formatting the disk
Please review if filesystem is not used and rerun this script to install CD image on USB. 
If required please report above error to NGELINUX.com for support with current screen session log
Press any key to exit now...
[root@nglinux nglinux]# 

 


Note:– The script livecd-iso-to-disk is a Copyright 2007 of Red Hat, Inc. and Ngelinux used it alongwith our script to accomplish this task easily.
The script is named as “ngelinux_usb_install” and the script can be found below for reference.

#!/bin/bash
## Script made by Saket Jain(http://saketjain.com) for NGE Linux (http://ngelinux.com) 
#### Installs NGE Linux on USB disks..
echo "This Script will copy the NGE Linux CD/DVD to a USB Disk and make it bootable.."

DISKFILE=/tmp/disks_available
NGPATH=/usr/nglinux/
CDROM=`cat /proc/sys/dev/cdrom/info | grep 'drive name' | awk '{print $3}'`

fdisk -l | grep Disk | grep -i '/dev' | grep -v loop | grep -v mapper > $DISKFILE

function otherdisk()
{
echo "Please type the disk name /dev/sdX or /dev/hdX format.";
echo "It should not be any partition like /dev/sda1, /dev/hda1, etc";
read diskname;
diskname2=$diskname;
if [[ `fdisk -l $diskname` == "" ]]; then
echo "There is no such partition $diskname";
echo ""
otherdisk
fi

}


function selectdisk()
{
echo "Select the disk for installation"
i=1;
while read line
do
echo "$i. $line"
(( i=$i+1 ));
done < $DISKFILE
echo "$i. Other";
read disknumber

if [[ $disknumber == $i ]]; then
otherdisk;
elif [[ $disknumber != 0 &&  $disknumber -lt $i  && $disknumber != "" && $disknumber == $((disknumber)) ]]; then
diskname=`cat $DISKFILE | sed "${disknumber}q;d"`;
diskname2=`echo $diskname| awk '{print $2}' | tr -d ":"`;
else
echo "Please enter correct option. $disknumber is not correct option .... "
selectdisk
fi
}

selectdisk;

function takeconfirmation()
{
echo "You have selected Disk $diskname";
echo "The disk is going to be formatted.";
echo "WARNING !! All data on $diskname will be erased. Are you sure(y/n) ?"
read confirm1
if [[ $confirm1 == "y" ]]; then
formatdisk;
elif [[ $confirm1 == "n" ]]; then
showmessageexit;
else
takeconfirmation;
fi

}

function showmessageexit()
{
echo "Exiting on User Demand.";
echo "In case you need to install NGE Linux on another disk, please re-run this script.";
echo "Press any key to exit...."
read randomkey
exit 0
}

function formatdisk()
{
echo "Formatting Disk $diskname in ext4 format....";
mkfs.ext4 $diskname2;
if [[ $? != 0 ]]; then
echo "Error encountered in formatting the disk"
echo "Please review if filesystem is not used and rerun this script to install CD image on USB. "
echo "If required please report above error to NGELINUX.com for support with current screen session log"
echo "Press any key to exit now..."
read randomkey
exit 1
fi
## run the script iso to disk/usb ...
echo "FORMAT Complete..."
echo "Now transferring the image file to $diskname2 device..."
$NGPATH/livecd-iso-to-disk --reset-mbr --overlay-size-mb 300 --home-size-mb 200 --unencrypted-home /dev/$CDROM $diskname2
echo "The NG Linux 1.0 is now installed on device $diskname2. Just reboot the system and check the live OS installation your USB/disk."
echo "Press any key to exit ...."
read randomkey
exit 0
}


takeconfirmation;