« 301 Redirect and Dreamhost | Hiding Links With PHP and Counting Clicks with MySQL »

Creating a USB Flash Drive System Recovery System

By Studge | March 29, 2007

One of my favorite programs to use is Partimage for backing up my system regularly. I grew tired of booting a LiveCD each time I wanted to perform this task. It was time to put it on my USB flash drive.

I have used several bootable operating systems in the past: Knoppix, Damn Small Linux, and Puppy Linux. None of these really did much for me. I would boot into them and then I was merely stuck with an environment that was crippled in comparison to my usual environment. I can see how they might be applicable to users who are considering the switch to Linux, but as a regular user it provided little value. I noticed that the only time I was really booting into a live environment and using it was with the excellent SystemRescueCd. It is a Gentoo Linux distribution that is comprised of many useful system utilities - and it had a very small footprint at around 110MB. Here is how I put it on my 512MB USB thumb drive as a bootable operating system.

Before starting, you need to back up the data that already exists on the drive because this process will entirely wipe the drive out.

While the drive was plugged in I had to find out what address it was using. There are several ways to do this, if the drive was being used before it would have been partitioned:

[user@localhost ~]$ df

This will return the available partitions - we are looking for something in the /dev/sd? range. If there is only one USB drive plugged it, then it is most likely /dev/sda. If the drive does not contain any partitions yet, then try this:

[user@localhost ~]$ ls /dev/sd*

Now that we have the address, we need to first remove any partitions. This needs to be done as the root user and the drive should not be mounted:

[root@localhost ~]# fdisk /dev/sda

Press “p” to list the current partitions. Then press “d” to delete each one, you may be prompted to enter the partition number. Press “w” to write the changes to the disk and exit. Now that the partitions are removed we are going to wipe the drive out. Warning! This will absolutely remove everything on the drive! This process will take some time since it is writing zeroes over every bit of the drive.

[root@localhost ~]# dd if=/dev/zero of=/dev/sda

Now the drive is clean and we can set it up. First we need to put an MBR (Master Boot Record) on the drive. I am not aware of a program in Fedora that does this, so I installed ms-sys. If you are on a Debian based system, then you can probably use the install-mbr command. Once installed we will create a Windows 95 boot record on the drive:

[root@localhost ~]# ms-sys--mbr95b /dev/sda
Windows 95B/98/98SE/ME master boot record successfully written to /dev/sda

We will now create one partition to house the SystemRescueCD system and another to use as regular storage. We invoke fdisk again:

[root@localhost ~]# fdisk /dev/sda

This time we will press “n” to create a new partition. Then “p” for primary partition and “1″ to signify it as the first partition. Enter “1″ again to select the first cylinder. Next it requests the last cylinder, I entered “+150M” to grow the partition by 150MB. We need to change the type of partition by pressing “t” and then “e” to select W95 FAT16 (LBA). We need to make this partition bootable, so press “a” and then “1″ again to select the first partition. You can create whatever partition you like with the leftover space. Once done, press “w” to write the changes and exit.

Next, we format the partition:

[root@localhost ~]# mkdosfs /dev/sda1

And then we will use SYSLINUX as a bootloader for the distribution.

[root@localhost ~]# syslinux /dev/sda1

At this point, you may want to reboot into the USB drive to see that it is working and set up correctly. If it is, then you should see a message similar to this:

SYSLINUX 3.11 2005-09-02 EBIOS Copyright (C) 1994-2005 H. Peter Anvin
Could not find kernel image: linux
boot:

If it did not work, then you should see something along the lines of “boot failed”, “Missing operating system” or “Boot error”. If you see any of these, you should try repeating the above processes. If it just boots into your regular system, then you will need to tweak a setting in your BIOS to boot to the USB device. If everything went well, then it is time to transfer the system files. You need to boot back into your regular system and mount your new thumb drive partition:

[root@localhost ~]# mkdir /mnt/usb
[root@localhost ~]# mount -t vfat /dev/sda1 /mnt/usb

You will next need to download the disk image from their download page and mount it:

[root@localhost ~]# mkdir /mnt/rescue
[root@localhost ~]# mount -o loop systemrescuecd-x86-x.x.x.iso /mnt/rescue

And then copy the files over:

[root@localhost ~]# cp /mnt/rescue/syslinux/syslinux.cfg /mnt/usb
[root@localhost ~]# cp /mnt/rescue/sysrcd.dat /mnt/usb
[root@localhost ~]# cp /mnt/rescue/isolinux/* /mnt/usb
[root@localhost ~]# cp /mnt/rescue/bootdisk/* /mnt/usb

That is it. The drive should be ready now. When you reboot you should be prompted by the SystemRescueCd boot screen.

Topics: Linux

Share: del.icio.us | digg | reddit

RSS feed | Trackback URI

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.