Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - General > Member Success Stories
User Name
Password Member Success Stories Just spent four hours configuring your favorite program? Just figured out a Linux problem that has been stumping you for months?
Post your Linux Success Stories here.


  Search this Thread
Old 03-27-2009, 05:52 AM   #1
Registered: Oct 2007
Distribution: Fedora, openSUSE
Posts: 252

Rep: Reputation: 39
Creating rescue CDs for the computer illiterate

I recently had to install Win XP on a friend's computer, as it had apparentlty accumulated various mystery errors over the years. This being a bit of a hassle, and since the box didn't ship with a rescue cd (or even drivers), I decided to create my own. It's basically a Fedora Live CD image, written to a DVD, along with an image of the hard drive containing a fresh install of XP+drivers, and a script that writes the image to the hard drive, so that a trained monkey can use it if I'm not around. No doubt there are tools around that will do this automatically, but with DIY you learn more and have more control (and, of course, it's more fun )

This is for others who want to do the same thing (it took a few experiments and wasted DVDs to get everything right), and to invite comments for improvements. You are of course free to copy the small script below and modify as you see fit - I've tested it as far as I can, but it hasn't actually been used in anger, so use at your own risk!

First thing to know to make this easier: Windows can store user files and settings on a separate 'home' partition, Linux-style. This means you can keep the system partition reasonably small, so that the compressed image will fit on a DVD, and the rescue DVD can be used without overwriting user data. This Knowledge Base article tells you how:

For a single-user system, you just have to change one registry entry. Haven't tried it for moving the whole Documents and Settings dir for all users.

Once the OS is installed as you want it for the rescue image, boot your live cd of choice and take the image. There are plenty of online tutorials on how to do this, I've used this one:

The actual commands I used were
dd if=/dev/sda of=/media/usb-hdd/mbr.bak bs=512 count=1  # back up MBR (inc. partition table)
dd if=/dev/sda1 bs=1k conv=sync,noerror | gzip > /media/usb-hdd/sda1.img.gz  # back up first partition
A handy tip from the above link, to make the image smaller, is to zero the unused space before taking the image, so that it can be better compressed. Obviously if you're backing up a Windows partition you need a live cd that can write to NTFS for this.

mount /dev/sda1 /mnt/sda1
dd if=/dev/zero of=/mnt/sda1/delme bs=8M
rm /mnt/sda1/delme
umount /mnt/sda1
Now you need to modify a live cd image so that our hypothetical monkey can use it without messing around with dd and other such dangerous tools. Credits go to homey for the commands here, which are for the Fedora 8 live cd.

Find the squashfs image on the live image and unsquash it to get a 4GB ext3 image:

/usr/sbin/unsquashfs /pathtocd/LiveOS/squashfs.img   # creates directory squashfs-root in the current dir
mount -o loop squashfs-root/LiveOS/ext3fs.img /mnt/cdimage # mounts the / filesystem of the live cd
Now modify as you see fit. I added a script to write the hdd image to the hdd, and a text file of instructions. The user fedora doesn't actually exist on the Fedora live cd until it boots - it's created in an init script - so for maximum usability I modified an init script to copy them to /home/fedora after the directory is created. The obvious way to do that is to have the files elsewhere on the filesystem and just copy them over, but for some reason the init scripts couldn't access them, saying they didn't exist. I went with the kludge of creating them by redirecting the output of echo, maybe someone has a better way.

This is the modified /etc/rc.d/rc.local I put on the new live cd. It creates the restore script and the instructions file, and sets permissions etc as they should be.

# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

# normally Gnome creates the Desktop dir when user first logs in.
# create it here instead so we can put stuff on it
mkdir /home/fedora/Desktop
chown fedora.fedora /home/fedora/Desktop

echo 'To restore your C: drive, go to the Applications menu in the top-left and select System Tools -> Terminal

In the window that appears, simply type:

and hit enter.  This is case-sensitive: do not use any capital letters.

WARNING: this will overwrite your C: drive with a fresh install of Windows.  After that, you can reboot into Windows, and need to switch on Windows Update and install any programs you want to use.   "restore" is written so that it will not touch anything on your D: drive, but it is best to have everything backed up just in case!
' > /home/fedora/Desktop/instructions.txt

echo '
# add . to the path so that script will execute according to instructions.txt, without prepending ./
' >> /home/fedora/.bash_profile

echo '#!/bin/bash

# restore MBR, partition table and partition 1.
# intended to be run from modified Live DVD with backup files
# on /restore of the DVD.

# calls a separate script in order for exit status to be correct
# (using a single script with su -c "..." means $EXIT_STATUS cannot
# be set and read inside the "...")

su -c
' > /home/fedora/restore

echo '#!/bin/bash

# restore MBR, partition table and partition 1.
# intended to be called by the script "restore"


terminate () {
    exit $1

    { [ -r $imgdir/sda1.img.gz ] && [ -w . ] ; } || \
        { echo "Error: cannot read $imgdir/sda1.img.gz or cannot write to current directory."
        terminate 1
        } &&

    echo -n "Restoring MBR and partition table... " &&
    dd if=$imgdir/mbr.bak of=/dev/sda >> $logfile 2>>$logfile  &&
    echo "OK." &&

    echo -n "Re-reading partition table... " &&
    /sbin/partprobe /dev/sda >> $logfile 2>>$logfile &&
    echo "OK." &&

    echo -n "Restoring C: drive (this will take several minutes)... " &&
    gunzip -c $imgdir/sda1.img.gz | dd of=/dev/sda1 bs=1k >> $logfile 2>>$logfile  &&
    echo "OK." &&

    echo -e "\n Restore completed successfully.\n" \
        "Activity logged to $logfile.\n" \
        "Please reboot your computer." &&
    dd if=$imgdir/mbr.bak of=/dev/sda >> $logfile 2>>$logfile  &&
    echo "OK." &&

    echo -n "Re-reading partition table... " &&
    /sbin/partprobe /dev/sda >> $logfile 2>>$logfile &&
    echo "OK." &&

    echo -n "Restoring C: drive (this will take several minutes)... " &&
    gunzip -c $imgdir/sda1.img.gz | dd of=/dev/sda1 bs=1k >> $logfile 2>>$logfile  &&
    echo "OK." &&

    echo -e "\n Restore completed successfully.\n" \
        "Activity logged to $logfile.\n" \
        "Please reboot your computer." &&

} ||

    echo "There was an error.  Please save $logfile on a memory stick."

terminate $EXIT_STATUS
' > /home/fedora/

chown fedora.fedora /home/fedora/{restore,} /home/fedora/Desktop/instructions.txt
chmod a+x /home/fedora/{restore,}
Now create the new squashfs from the modified ext3fs.img:
umount /mnt/cdimage
/sbin/mksquashfs squashfs-root squashfs.img
Careful: different versions of squashfs are incompatible with one another. Make sure you're using a version compatible with the one on the live CD - the simplest solution is to get a live cd which matches the distro you're working on.

Finally, make the new ISO, with the hdd image in the place expected by the restore script (/restore in the version above):
# The volume label "Fedora-8-Live-i686" should match the isolinux.cfg entry.
sudo mkisofs -R -l -L -D -b isolinux/isolinux.bin -c isolinux/ -o /mnt/data/rescue.iso -no-emul-boot -boot-load-size 4 -boot-info-table -V "Fedora-8-Live-i686" /path-to-cd-files
And you're done! Oh, it's also a good idea to include an instructions.txt on the root of the DVD, which explains how to boot from the optical drive for that particular computer, and also includes the instructions above.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
automating module rebuilds on kernel upgrades - for the computer illiterate lurko Debian 6 02-22-2009 05:28 PM
Desktop Environment for the Computer illiterate Hydroksyde General 10 10-21-2005 06:41 PM
Creating a win95 rescue disk from within Linux drumvudu Linux - General 8 01-01-2005 09:43 AM
creating rescue disks after installation Ravager Fedora 1 11-07-2004 10:57 AM
KDM & KDE setup for computer ILliterate people ZX_SA Linux - General 3 10-28-2004 11:37 AM > Forums > Linux Forums > Linux - General > Member Success Stories

All times are GMT -5. The time now is 05:01 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration