A Sample Bare-Metal Recovery

This example uses pax (emulating tar), gzip, fdisk, lilo, and tomsrtbt to back up and recover a complete Linux system on an (Intel) Toshiba Satellite Pro laptop.

Performing the Backup

As mentioned earlier, I backed up the metadata by running the command:

# fdisk -l >/etc/fdisk-l.txt

We then backed up the operating system using pax (emulating tar) to a Zip drive mounted on /backup:

# cd / ; tar cf - . |gzip -c >/backup/root.tar.gz

Now it’s time to blow it up! The following dd command blows away both the lilo boot block and the disk’s partition information. Although the root filesystem is still there, we couldn’t find it if we wanted to!

# dd if=/dev/zero of=/dev/hda bs=512 count=1
# reboot
Insert system disk in drive
Press any key when ready.

Perform the Recovery

As mentioned in the preceding explanation, we will need to boot the system, partition its drives, create the root filesystem, restore the system, and reinstall the boot image.

Boot the system

The first step in recovering this system is to place the tomsrtbt floppy into the floppy drive and press any key. Here’s what it displays while it is booting:

Welcome to tomsrtbt-1.7.134

http://www.toms.net/rb
        #####
       #######
       ##O#O##
       #VVVVV#
     ##  VVV  ##
    #          ##
   #           ##          ~      
   #           ###        . . 
  QQ#          ##Q        /V
QQQQQQ#       #QQQQQQ    // \
QQQQQQQ#     #QQQQQQ    /(   )
  QQQQQ#######QQQQ       ^`~'^

 Other distributions    tomsrtbt
 (15 seconds...)

boot:

Loading zImage..............
Press <RETURN> to see video modes available, <SPACE> to continue or wait 30 secs

Uncompressing Linux..............

...<extra messages deleted>...
ppa: Communication established with ID 6 using PS/2
ppa: Probing port 0278
scsi0 : Iomega parport ZIP drive
scsi : 1 host.
  Vendor: IOMEGA    Model: ZIP 100           Rev: J.03
  Type:   Direct-Access                      ANSI SCSI revision: 02
Detected scsi removable disk sda at scsi0, channel 0, id 6, lun 0
SCSI device sda: hdwr sector= 512 bytes. Sectors= 196608 [96 MB] [0.1 GB]

...<extra messages deleted>...
...Login as root.  Remove the floppy.  AltF1-AltF4 for consoles.

tty1 tomsrtbt login: root

The default "root" password is "xxxx",
edit /etc/passwd ro change it, or edit
settings.s to change it permanently

Password:

Today is Pungenday, the 19th day of Bureaucracy in the YOLD 3165
#

Restore the partition information

Since we need to repartition the root disk, we need to know what it looked like. In order to do that, we need to mount the Zip drive and restore the files that contain this information. (The Zip drive shows up as /dev/sda4.)

# mount /dev/sda4 /mnt

# ls -l /mnt
# ls -lt /mnt/*gz
-rw-r--r--   1 root     root     41393598 Aug 24 00:21 /mnt/root.tar.gz
# gzip -dc /mnt/root.tar.gz|tar xvf - ./etc/fstab ./etc/fdisk-l.txt
Tar: blocksize = 20
./etc/fstab
./etc/fdisk-l.txt

# cat /etc/fdisk-l.txt

Disk /dev/hda: 64 heads, 63 sectors, 658 cylinders
Units = cylinders of 4032 * 512 bytes

   Device Boot    Start      End   Blocks   Id  System
/dev/hda1   *         1      225   453568+  83  Linux native
/dev/hda2           226      658   872928    5  Extended
/dev/hda5           226      308   167296+  82  Linux swap

Partition the new root drive

Now that we know what the old disk looked like, we will partition the new disk. To demonstrate that the label is gone, I will display the current partition table, which is empty. Then I will add a primary partition, an extended partition, and a logical partition inside the extended partition.

# dd if=/dev/zero of=/dev/hda1 bs=1024 count=1

# fdisk /dev/hda

Command (m for help): p

Disk /dev/hda: 64 heads, 63 sectors, 658 cylinders
Units = cylinders of 4032 * 512 bytes

   Device Boot    Start      End   Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-658): 1
Last cylinder or +size or +sizeM or +sizeK ([1]-658): 225

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 2
First cylinder (226-658): 226
Last cylinder or +size or +sizeM or +sizeK ([226]-658): 658

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (226-658): 226
Last cylinder or +size or +sizeM or +sizeK ([226]-658): 608

Command (m for help): p

Disk /dev/hda: 64 heads, 63 sectors, 658 cylinders
Units = cylinders of 4032 * 512 bytes

   Device Boot    Start      End   Blocks   Id  System
/dev/hda1             1      225   453568+  83  Linux native
/dev/hda2           226      658   872928    5  Extended
/dev/hda5           226      608   772096+  82  Linux native

Change the partition types

Now that we have correctly sized the partitions, there are two remaining issues. First, we must change the partition type of /dev/hda5 to “Linux Swap” (with the t option) and set the bootable flag on /dev/hda1 (with the a option):

Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 82
Changed system type of partition 5 to 82 (Linux swap)

Command (m for help): a
Partition number (1-5): 1

Command (m for help): p

Disk /dev/hda: 64 heads, 63 sectors, 658 cylinders
Units = cylinders of 4032 * 512 bytes

   Device Boot    Start      End   Blocks   Id  System
/dev/hda1   *         1      225   453568+  83  Linux native
/dev/hda2           226      658   872928    5  Extended
/dev/hda5           226      608   772096+  82  Linux swap

You can see in the preceding that the bootable flag is now set, and partition five is configured as Linux Swap. Now that we have correctly sized and configured the partitions, we need to write the disk label to the disk:

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

WARNING: If you have created or modified any DOS 6.x
partitions, please see the fdisk manual page for additional
information.

Make a filesystem on the root drive

Now that the disk has been properly partitioned and labeled, we need to create a filesystem on it with the mke2fs command. When we are done, we can mount the new root filesystem.

# mke2fs /dev/hda1
mke2fs 1.10, 24-Apr-97 for EXT2 FS 0.5b, 95/08/09
Linux ext2 filesystem format
Filesystem label=
113792 inodes, 453568 blocks
22678 blocks (5.00%) reserved for the super user
First data block=1
Block size=1024 (log=0)
Fragment size=1024 (log=0)
56 block groups
8192 blocks per group, 8192 fragments per group
2032 inodes per group
Superblock backups stored on blocks: 
        8193, 16385, 24577, 32769, 40961, 49153, 57345, 65537, 73729, 
        81921, 90113, 98305, 106497, 114689, 122881, 131073, 139265, 147457, 
        155649, 163841, 172033, 180225, 188417, 196609, 204801, 212993, 221185, 
        229377, 237569, 245761, 253953, 262145, 270337, 278529, 286721, 294913, 
        303105, 311297, 319489, 327681, 335873, 344065, 352257, 360449, 368641, 
        376833, 385025, 393217, 401409, 409601, 417793, 425985, 434177, 442369, 
        450561

Writing inode tables:
Writing superblocks and filesystem accounting information: done

# mkdir /root

# mount /dev/hda1 /root

# mount /dev/hda1 /root
# df -k
Filesystem         1024-blocks  Used Available Capacity Mounted on
/dev/ram0                798     776       22     97%   /
/dev/ram1               2546    2440      106     96%   /usr
/dev/ram3               4049       3     4046      0%   /tmp
/dev/sda4              95167   41094    49159     46%   /mnt
/dev/hda1             439063      13   416372      0%   /root

Restore the operating system

We are now ready to actually restore the operating system. We will cd to /root and use gzip and pax (emulating tar) to restore from the backup file on the Zip disk.

# cd /root
# ls -lt /mnt/*gz
-rw-r--r--   1 root     root     41393598 Aug 24 00:21 /mnt/root.tar.gz
# gzip -dc /mnt/root.tar.gz|tar xf -
Tar: blocksize = 20

Restore the master boot record

Now that the root filesystem is restored, we need to restore the lilo boot block. Making this work was tricky. We cannot use the lilo command on tomsrtbt, and we cannot run the lilo command on the root file system directly without it complaining. It needs to run it inside an environment where it thinks /root is actually /. The way to do this is to run the command chroot /root prior to running the lilo command:

# chroot /root /sbin/lilo
Added linux *

# reboot

We’re done! Remember, make sure that you test this procedure before you need it.



[51] The Principia is in the public domain.

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

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