Friday, April 2, 2010

A fast guide to system rescue using open tools

Technology is wonderful, until it stops working as expected. Computers have a nasty habit of developing glitches or just going belly up altogether at the worst possible times. There's nothing that can prevent that, but a couple of open source tools can help mitigate disaster and maybe even save the day altogether. With Clonezilla you can create a perfect copy of your system. Using the System Rescue CD, you'll have all the tools you need to recover from many system crashes.

To thy data be kind

It might be tempting to rely on system troubleshooting skills to save the day, but the only guaranteed way to keep your data safe is to do regular system backups. Never ask "should I be paranoid about losing my data?" Ask "just how paranoid should I be about losing my data?"The answer to that question, if you have any files that can't be easily replaced—especially things like family photos or documents that you've created—is very paranoid.

So let's start with Clonezilla, an open source clone system. That is to say, it's a system for creating a clone of your existing system. Clonezilla is designed to do more than just back up your data—it's actually designed to create a fully working copy of an installed system. Clonezilla comes in two editions: Clonezilla Live and Clonezilla Server. The server edition is geared towards massive clone/restore scenarios and it requires a server to receive the cloned partitions and a system or systems booted off of PXE or Etherboot.

That's probably overkill for most users, so I'll focus here on Clonezilla Live. What you'll need, aside from the the CD itself, is a system to clone and a target system or hard drive to receive the image or images. Using Clonezilla you can copy images over SSH, Samba, NFS, or to a USB disk.

Clonezilla isn't just for Linux systems, either. You can create clone images of Linux machines, sure, but also Microsoft Windows systems, and even Intel-based Mac OS X systems. Clonezilla supports Ext2, Ext3, Ext4, ReiserFS, FAT, NTFS, and HFS+. If your filesystem isn't on that list, Clonezilla can still tackle it with the dd utility, but it loses a bit of flexibility. With supported filesystems, Clonezilla can save space by copying only the used blocks on partitions. With unsupported filesystems, Clonezilla has to do a total copy of the filesystem regardless of space used.

As an example, if you're backing up an Ext3-based system with a 90GB partition that has 45GB of space used, Clonezilla should only copy 45GB of data (give or take). In the same scenario with an unsupported filesystem, Clonezilla would copy the whole partition, even the empty space.

Using Clonezilla

The simplest way to use Clonezilla, and my preference, is to boot a system using the Clonezilla Live CD with an attached USB drive. Note that you'll want to have the USB drive partitioned beforehand.

Clonezilla boot choices

Truth be told, Clonezilla isn't quite as user-friendly as its proprietary counterparts. Tons of functionality, but it does suffer from a few rough edges. Case in point, when you start walking though the Clonezilla startup the first time, it requires you to mount an image as /home/partimag — but the language in the Clonezilla dialogs makes it murky as to whether /home/partimag is the target device or the device being backed up. You'll want to mount /home/partimag as the target device to receive the clone image.

Choosing Clonezilla modes

Clonezilla uses Partclone to copy the system images. As soon as the process is underway, there's not much to do but watch the status messages tick by. Once you've kicked off the process, it's time to go get a cup of coffee, a slice of pizza, and maybe read a goodly chunk of War and Peace. To put it another way, the process of copying a relatively large system image can take a whlie. Using a recent vintage laptop with two Ext3 partitions weighing in at 69GB and an external USB drive, Clonezilla took more than two hours to run the process.

Once you've got a cloned image, you can restore by booting into Clonezilla and following the same steps, but choosing the "restore image" option and choosing the cloned images you created the first time. Again, this will take some time, but it beats having to re-install a system by hand.

Restoring from the Clonezilla image

Aside from being somewhat slow, the other downside of Clonezilla is this: it's an all-or-nothing proposition, and it doesn't support live imaging. This means that the system being cloned is going to be offline while Clonezilla is working. Not so bad for home desktop systems, laptops, workstations, etc. Not so good when you're looking at backups for servers. Clonezilla Server is still a great solution for creating and deploying production images, but not for regular backups.

Because of these limitations, I recommend a dual strategy of cloning your system on a weekly or monthly basis, and daily (if not hourly) backups of your data using rsync or another system backup tool. You don't want to restore your entire system just to recover a few files deleted by accident.

But having a full system clone can get you up and running in an hour or two with all your apps intact in the event of a disaster. Having a recent backup of your data means not losing any work due to disk crashes or hardware disasters.

If at all possible, it's also a very good idea to do a trial run or two to test restoring your system before disaster strikes. There's nothing like attempting a restore after a system crash to find out that the backups are useless!

System recovery

When disaster does strike, if you're caught without a backup, you can still find help in the form of Linux recovery tools. Almost any Linux live CD will help as a rescue disk in a pinch, especially if you're a Linux user. In particular, you probably want to have the release that you're running of your favorite Linux distro handy at all times

Using a live CD of your favorite distro, you can often recover a system when the damage isn't too dire by booting the live CD, mounting the system partitions using chroot and installing stock packages to the target system. But it's also handy to have a copy of the System Rescue CD as an all-purpose rescue utility.

The System Rescue CD is sort of a Swiss Army Knife of utilities. It includes a stripped-down Linux distribution (based on Gentoo) and a slew of other tools. You'll have a hardware detection utility, memtest, a low-level hard disk diagnostic tool (mhdd), FreeDOS, and much more.

When you boot the live CD, it presents a text boot screen with a list of its capabilities and options if you need to do more than boot the default image. Hitting F2 and F3 will display a list of options. F4 gives information about using additional scripts with the System Rescue CD, F5 gives information about troubleshooting the CD if you run into hardware problems. F6 explains using PXE boot with the System Rescue CD, and F7 explains network options.

System Rescue CD F2 Menu

One option you probably want to use, unless the system is seriously memory constrained, is the "docache" option. This tells the System Rescue CD to copy the system to RAM, rather than running off the live CD.

The System Rescue CD is also handy if you need to rescue a Windows system. You can access NTFS filesystems from the System Rescue CD live system, so if you need to pull some files off of a Windows machine that won't boot for some reason, the System Rescue CD is your go-to tool.

But you can also use the CD to run "ntpassword," which allows you to edit and reset passwords on Windows systems. According to the help docs, this works with Windows Vista, but no word on whether it also works with Windows 7. Normally I'm a stickler for testing all the features of a tool myself, but running out and getting a Windows 7 system to see whether I could reset the password seemed a bit drastic. If it doesn't support Win7 now, though, odds are the System Rescue CD will support it very soon.

The CD can also be used to run the Ranish Partition Manager. This tool gives you a lot of flexibility in working with Linux and Windows partitions. Also useful if you want to back up (or restore) your MBR to/from a file before attempting to revive a non-booting system.

The System Recovery Live System

After starting the System Rescue CD default image, you'll be dropped at a shell prompt with a relatively standard Linux userland. If you're used to GNU Bash (and who isn't?) you might be thrown slightly when you boot into the System Rescue CD. It uses zsh as its default shell. However, it does come with GNU Bash, so if you need or prefer bash, you can run /bin/bash to get a bash shell.

System Rescue CD F2 Menu

Want a GUI to work in? The System Rescue CD sports a nice Xfce implementation with a small complement of tools. You'll start out at the shell, so to get Xfce up and running the easiest way is to run the wizard command. This will attempt to auto-detect your video card settings and start X without any additional intervention on your part. If all goes well, you'll see a somewhat sparse Xfce implementation that starts up in no time at all. Alternately, if you know you want a GUI, start the System Rescue CD with "rescuecd dostartx" at the boot prompt.

System Rescue CD F2 Menu

You won't find a ton of GUI applications on the System Rescue CD, but it does come with Firefox, a PDF reader, GParted, a CD-burning app, and a few other tools you might find useful when troubleshooting or rescuing files. Naturally, all the CLI tools are still available as well.

Though this isn't technically a recovery tool, the System Recovery CD also includes Darik's Boot And Nuke. Not very good for recovering a system, but if you've managed to recover your data off a failing hard drive, you might want to give it a wipe before tossing it, just to be on the safe side.

Maintaining your system rescue toolkit

As with backups, it's a good idea to get some practice before you actually need it. If you want to become adept with the system rescue tools, it's a good idea to download and see what they offer when everything is working well. You can get a feel for the tools and be ready in case disaster strikes.

Both the System Rescue CD and Clonezilla distributions tend to move quickly, so they may have newer revisions by the time that you read this article. Be sure to check the distro sites or regularly for updates.

At a minimum, I'd recommend downloading new releases at least once every three months or so. CD media is cheap, and having a rescue disc handy when you need it is priceless.

No comments:

Post a Comment