Chapter 8. Linux

Like many other things in the Linux world, the ease with which you can do a bare-metal recovery will depend on your configuration. If you are running Linux on an Intel-based system, have a parallel-port Zip drive, and can fit a compressed copy of your operating system on that Zip drive, you’re in luck! That’s the configuration I used to test this recovery procedure.

Chances are, of course, that your configuration is slightly different than this. If you are running Linux on an Intel-based system, this procedure will work for you without modification. If you’re running Linux on a Sparc system, you will need to use a different boot floppy and silo instead of lilo. If you are using an Alpha version of Linux, your options are a bit more complicated.

How It Works

Most Linux administrators are familiar with the typical bare-metal recovery answer: install a minimal operating system and recover on top of it. However, this answer presents the same problems for Linux systems that it does for other versions of Unix—it takes too long, you could run into open-file conflicts, and it is difficult to document and recover operating system customizations.

Like the other bare-metal recovery procedures in this book, this procedure does not require a reinstallation of the operating system in order to recover it. It is based on a homegrown procedure, which breaks down into six major steps, and will work with any Intel-based Linux distribution:

  1. Back up the important metadata.

  2. Back up the operating system with a native utility.

  3. Boot from alternate media.

  4. Partition and format the new root disk.

  5. Restore the operating system information.

  6. Restore the boot block to the new root disk.

Back Up the Important Metadata

The first important piece of information that you need to save is the metadata. Metadata is the information about how the system is physically configured—specifically, how the root disk is partitioned. This information is not typically included in a normal backup.

To save this information, run the command fdisk -l and redirect the output to a file that will be included in the backup of the operating system. You also might want to keep a copy of the /etc/fstab in an alternate location. If you create these files prior to running your operating system backup and place them in an easy-to-find location, you will be able to easily retrieve this data if you need it.

Back Up the Operating System with a Native Utility

If you are going to restore the operating system without reinstalling it, you will need to use a utility that is easily available. In this case, you need to use a backup and recovery utility that is available on a rescue floppy . (Rescue floppies are special floppies designed to help boot and rebuild a Linux box when it becomes damaged.) Both tar and cpio were available on the rescue floppy that I chose, but they were actually links to pax . (pax will emulate both tar and cpio.) I prefer tar ’s syntax, so that is what I used to create the backup.[49] Since gzip also was available, I compressed the backup so that it would easily fit on the media.

Speaking of media, you must decide where you are going to back up your operating system. You need to back it up to something that you can access from a rescue floppy. It doesn’t do any good to make a backup to a tape drive that you can’t access during a recovery! If you have a tape drive and a SCSI card that is supported by one of these rescue floppies, you’re set. In my case, I had a parallel-port Zip drive, and its driver was available on the rescue floppy. Since a compressed pax backup was only 68 MB, this was perfect for me.

If you can’t figure out how to use your tape drive or other backup device from a rescue floppy, you may consider backing up to an NFS or SMB (CIFS) partition. Many of these floppies support mounting an NFS or SMB filesystem. This means that you would boot from the rescue floppy, mount the NFS or SMB filesystem to the system to be recovered, and then use gzip and pax to recovery the operating system.

In summary, there are three things that matter when deciding on a method of backing up the operating system:

  • Make sure that the backup utility you use is available on your rescue floppy.

  • Make sure that the backup utility you use is able to recover special files and named pipes, since such files will be found within the operating system. ( pax will do this for you.)

  • Make sure that the backup media you use is supported by your rescue floppy.

Boot the System from Alternate Media

In order to easily recover your operating system, you will need a “miniroot,” or limited root shell where you can run fdisk, mkfs, gzip, and pax/tar/cpio, or whatever. You also will need support for whatever backup media you have chosen. This functionality is provided via rescue floppies. These floppies contain a minimal version of Linux and all of the recovery utilities listed previously. They also have several drivers for popular backup media, such as parallel-port Zip drives, SCSI tape drives, NFS, and SMB.

Intel Linux

A list of Intel rescue floppies may be found at http://metalab.unc.edu/pub/Linux/system/recovery. The rescue floppy that I chose to use was tomsrtbt and can be found at http://www.toms.net/rb. Just look at all the drivers and utilities that you get on one floppy:

The 2.0.36 kernel, 3c589_cs, BusLogic, CVF, DEC_ELCP, EEXPRESS, EEXPRESS_PRO, EL2, EL3, EXT2, FAT, FAT32, FD, IDE, IDECD, IDEFLOPPY, IDEPCMCIA, IDETAPE, ISO9660, JOLIET, LOOP, MATH_EMULATION, MINIX, MSDOS, NE2000, NFS, PROC, RAM, SD, SERIAL, SLIP, SMC, SR, TR, ULTRA, VFAT, VORTEX, WD80x3, ah152x_cs, aha152x, aha1542, aic7xxx, ash, awk, badblocks, bdflush, bZip2, cardbus, cardmgr, cat, ce, ce.help, chattr, chgrp, chmod, chown, chroot, clear, cmp, cp, cpio, cut, date, dd, ddate, debugfs, df, dirname, dmesg, dmsdos, ds, du, dumpe2fs, dutil, e2fsck, eata, echo, egrep, elvis, emacs, extend, false, fdflush, fdformat, fdisk, fdomain, filesize, find, fmt, fsck.ext2, fsck.msdos, fstab, grep, gzip, halt, head, hexedit, hostname, i82365, ifconfig, ifport, ile, init, inittab, insmod, kill, killall5, ksyms, length, less, libc.so.5.4.13, lilo, lilo.conf, ln, loadkeys, login, losetup, ls, lsattr, mawk, memtest, mingetty, miterm, mkdir, mkdosfs, mke2fs, mkfifo, mkfs,minix, mklost+found, mknod, mkswap, mnsed, more, mount, mt, mv, nc, ncr53c8xx, nmclan_cs, ntfs, pax, pcmcia, pcmcia_core, pcnet_cs, ping, plip, ppa, printf, ps, pwd, qlogic_cs, qlogicfas, reboot, reset, rm, rmdir, rmmod, route, rsh, rshd, script, scsi_info, seagate, sed, serial_cs, setserial, sh, slattach, sleep, slip, snarf, sort, split, stty, swapoff, swapon, sync, tail, tar, tcic, tee, telnet, test, touch, tune2fs, umount, update, vi, vi.help, and wc.

If the driver that you need is not available on the default floppy, Tom Oehser has compiled a huge set of drivers that you can use to build your own custom floppy and has included instructions on how to do so. He even tells me that it is possible to build a “rescue CD” that could contain all of these drivers for use anywhere, but I don’t think it has been done. Needless to say, I was quite impressed with tomsrtbt and have included it on the CD-ROM (CD content is available online at http://examples.oreilly.com/unixbr). Tom deserves quite a bit of credit for developing such a good tool. He asked that I include this disclaimer:

*******************************************************************************
* If you base something on it, use any of the scripts, distribute binaries or *
* libraries from it, or distribute customized versions of it: You must credit *
* tomsrtbt and include a pointer to http://www.toms.net/rb/ and [email protected], *
* and include this notice verbatim. Copyright Tom Oehser 1999. This notice in *
* no way supercedes or nullifies any other protections on the component parts *
* such as the BSD and GPL copyrights which apply to practically everything!!! *
* Within these strictures you may redistribute, incorporate, copy, modify, or *
* do anything else to it or with it that you like. Tomsrtbt has no warranties *
* not even implied fitness or usefulness. If it breaks you keep both pieces. *
*******************************************************************************

Once you boot from your rescue floppy, you can perform the rest of this procedure from a fully functional root shell.

Sparc Linux

There is a rescue floppy for UltraLinux (the new name of the Sparc Linux port) at ftp://vger.rutgers.edu/pub/linux/Sparc/rescue. It contains all of the necessary utilities to boot into a miniroot, partition the root drive, and restore the boot block image. To use this rescue floppy, simply insert it into the Sparc floppy drive and enter boot floppy. Once it prompts for the root image floppy, swap floppies and press Return. tar, cpio, gzip, and silo will all be available.

Alpha Linux

Debian Linux comes with a rescue floppy that you can use to boot into a miniroot, and you can use this floppy to recover any type of distribution. (Once you get into the miniroot, you can restore your distribution, even though you’ve booted from a Debian floppy.) You can find the current image at ftp://ftp.debian.org/debian/dists/stable/main/disks-i386/current. How you actually boot your system with this floppy depends on which type of firmware you are using. Updated information about how to boot each type of firmware can be found in the README file in the preceding FTP directory. Once you have booted the system to a miniroot, you can use tar, cpio, gzip, or silo to recover your system.

Partition and Format the New Root Drive

Since you saved a copy of how the root disk was partitioned, you will be able to partition the new root drive the same way. The way to do this is with fdisk . Unfortunately, many people are becoming less familiar with fdisk and more familiar with the Disk Druid. (Disk Druid is another interface that allows you to partition your disk, and is much more user friendly than fdisk.) Since Disk Druid is not available on the rescue floppies, you will need to learn how fdisk works. An example of how to use fdisk is included later in this chapter.

After you have repartitioned the root drive, you’ll need to use mkfs to recreate the root filesystem(s). Finally, you are ready to restore the data.

Restore the Operating System to the New Root Disk

First, you must have access to the backed-up data. On the system on which I tested this procedure, the ppa driver was already loaded, and I just needed to mount the Zip drive as a filesystem. You may have to do one of the following:

  • Mount a Zip or Jaz drive as a filesystem.

  • Load drivers for your SCSI card and tape drive.

  • Load network and NFS drivers, configure your network interface, and mount an NFS filesystem.

  • Load network and SMB drivers, configure your network interface, and mount an SMB filesystem.

  • Use pax to spread the backup of your operating system across 200 floppies.[50]

My backup was made with pax (emulating tar) and gzip, to a Zip drive. The drivers and tools that I needed to do this were all available on tomsrtbt. There is an example later in this chapter that shows how to restore the operating system without reinstalling it.

Restore the Boot Block Information

The boot block is a special part of the disk that is used to load the operating system by its “bootstraps.” It contains just enough executable code to locate and load the kernel. In Linux Intel situations, this boot block is referred to as the Master Boot Record (MBR), and you can restore it using the lilo command.

Although this restore is as simple as running lilo, you will not be able to use the lilo command provided on tomsrtbt ; since that version probably is not the same as the one on the restored root disk. If the restored operating system disk was mounted on /root, you will need to run chroot /root /sbin/lilo. (If your version of lilo isn’t in /sbin, you will have to use the full path for your particular version.) This command performs a chroot to /root, then reads /etc/lilo.conf to determine what to put in the master boot block. It then rebuilds the boot block for you.

Once this is done, you’re ready to remove the floppy and boot the restored system.



[49] This causes pax to make a tar image instead of a pax image.

[50] I remember when we were forced to load SVR3 like this on the AT&T 3B2s. Boy, was that fun!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.182.45