Submitter: Collins Richey

I do not have a reliable and speedy backup device for my system (tape drive, CD/RW, etc) but I have plenty of space on my disk drives to maintain a bootable backup copy of my complete Linux system. From time to time, after major installs for example, I execute this procedure to backup my system to the alternate hard drive, thus providing some protection against head crashes and software installation failure.

I have a dual-boot Win95/eDesktop2.4 system with partitioning as shown below (Win95 on hda, production Linux on hdb). I still use a seperate /boot partition, but current grub/lilo makes that less critical. Your setup will vary, but its a good idea to keep a printed copy of your partitioning layout around. I produced these with (and then added comments):

Disk /dev/hda: 255 heads, 63 sectors, 1868 cylinders
Units = cylinders of 16065 * 512 bytes

   Device Boot Start  End   Blocks  Id System DOS C:/Win95
/dev/hda1  *       1  261  2096451   6 FAT16
/dev/hda2        262 1867 12900195   f Win95 Ext'd (LBA)
/dev/hda5        262  522  2096451   6 FAT16 DOS D:/Win95
/dev/hda6        523  542   160618+ 83 Linux SPARE /boot
/dev/hda7        543  562   160618+ 83 Linux /boot EMERGENCY
/dev/hda8        563  690  1028128+ 82 Linux swap
/dev/hda9        691 1190  4016218+ 83 Linux / EMERGENCY
/dev/hda10      1191 1528  2714953+ 83 Linux SPARE
/dev/hda11      1529 1867  2722986  83 Linux SPARE

Disk /dev/hdb: 255 heads, 63 sectors, 1662 cylinders
Units = cylinders of 16065 * 512 bytes

   Device Boot Start  End  Blocks  Id System
/dev/hdb1  *       1  124  995998+ 83 Linux /boot SPARE
/dev/hdb2        125 1662 12353985  f Win95 Ext'd (LBA)
/dev/hdb5        125  144  160618+ 83 Linux /boot ACTIVE
/dev/hdb6        145  204  481918+ 82 Linux swap
/dev/hdb7        205  803 4811436  83 Linux / ACTIVE
/dev/hdb8        804 1401 4803403+ 83 Linux SPARE
/dev/hdb9       1402 1662 2096451   6 FAT16 DOS E: SPARE

The best time to layout your disks is before installing Linux, but you can create an EMERGENCY system later if you have adequate space on one of your dirves. If you don't understand how to use fdisk to create a new partition, get help with that before continuing with this procedure. You must have an empty partitiont (in my case a boot partition and a swap partition also) to make use of this procedure.

My example shows an EMERGENCY system on a seperate drive, but you can create an EMERGENCY system even if you only have a single drive. This won't be much help if the disk crashes though.

  1. Creating the EMERGENCY backup system
    1. In the text that follows, replace hdb5 and hdb7 (the ACTIVE system partitions) and hda7 and hda9 (the EMERGENCY system partitions) with the partition nu,bers that you have chosen. Also, if you don't use a /boot partition, ignore the instructions for hdb5 and hda7.
    2. Before you start, be sure you have mapped out and partitinoed your disk for the backup system correctly. Your partition(s) must be at leaszt as large as the used space in your active system
    3. To minimize the chance of copying files that are in use (some can't be avoided), I run this from a console logged in as root (KDE, etc are NOT running). In any case, you need to be root to run this procedure.
    4. Issue the following commands to clear previous contents of the EMERGENCY partition(s). BE SURE YOU HAVE THE RIGHT DISKS!!! mke2fs will overwrite anything that is there, and you'll be quite sorry if you don't get it right the first time!
      • mke2fs /dev/hda7
      • mke2fs /dev/hda9
    5. If you have not already done so, you must format the swap partition. This only needs to be done once. The swap partition will be activated by your fstab when booting.
      • mkswap /dev/hda8
    6. Unfortunately, you can't just copy the input file system to the output file system because the files under /proc and /mnt must not be copied. What you must do is to create the root directory structure on the output filesystem, then copy the appropriate directories from the input file system.
    7. Mount the output root file system.
      • mount /dev/hda9 /mnt/hda9
    8. Key the following commands or put them in an executable script.
      • cd /mnt/hda9
      • mkdir bin boot dev etc home initrd lib lost+found mnt opt
      • mkdir proc root sbin shlib tmp usr var
      • chmod 1777 tmp
      • ln -s var/lib/LST install
      • cd mnt
      • mkdir ...(see below)
      • (include all your mount points, but be sure to change the mount points for the EMERGENCY system with those for the ACTIVE system. In my case, I have /mnt/hda7 & /mnt/hda9 in the active system, but /mnt/hdb5 & /mnt/hdb7 in the EMERGENCY system)
    9. Check to be sure that all the directories other than tmp have 755 permissions
    10. Now, mount the boot partition (if you have one).
      • mount /dev/hda7 /mnt/hda9/boot
    11. Copy the directories with the following commands. All of this could be part of the executable script. Please note that I do not copy the /tmp directory. If you have anything valuable in /tmp, add a copy statement for that directory as well.
      • cd /
      • cp -a /bin/* /mnt/hda9/bin
      • cp -a /boot/* /mnt/hda9/boot
      • cp -a /dev/* /mnt/hda9/dev
      • cp -a /etc/* /mnt/hda9/etc
      • cp -a /home/* /mnt/hda9/home
      • cp -a /initrd/* /mnt/hda9/initrd
      • cp -a /lib/* /mnt/hda9/lib
      • cp -a /opt/* /mnt/hda9/opt
      • cp -a /root/* /mnt/hda9/root
      • cp -a /sbin/* /mnt/hda9/sbin
      • cp -a /shlib/* /mnt/hda9/shlib
      • cp -a /usr/* /mnt/hda9/usr
      • cp -a /var/* /mnt/hda9/var
  2. Making the EMERGENCY system bootable
    1. All but one of the files in the EMERGENCY system are identical to those in the ACTIVE system. You must edit the file /mnt/hda9/etc/fstab. Change the entries for /dev/hdb5 & /dev/hdb7 to /dev/hda7 & /dev/hda9. Check for other entries that need attention (e.g. swap from /dev/hdb6 to /dev/hda8).
    2. If you are using grub instead of lilo, do whatever is necessary to allow grub to boot the new EMERGENCY system. I don't use grub, so I can't help you with that.
    3. Edit the /etc/lilo.conf and when done copy it to /mnt/hda9/etc/lilo.conf. Add an entry to allow the new partition to be booted. My lilo.conf follows, but yours will differ (I put lilo on floppy).
      	boot = /dev/fd0
      	install = /boot/boot.b
      	vga = normal
      	timeout = 100
      	# default entry
      	image = /boot/vmlinuz-2.2.17-pre1
      	label = linux
      	root = /dev/hdb7
      	image = /boot/vmlinuz-pc97-2.2.14-modular
      	label = linuxorig
      	root = /dev/hdb7
      	image = /boot/vmlinuz-2.2.17-pre1
      	label = emerga1
      	root = /dev/hda9
      	image = /boot/vmlinuz-pc97-2.2.14-modular
      	label = emerga2
      	root = /dev/hda9
    4. Write the new lilo configuration to disk.
      • /sbin/lilo
    5. Now, reboot and try out your EMERGENCY system.
    searchSearch Index