Ghost/Image your Suse installation with dd

February 21, 2008

Source

While in the process of creating SUSE Linux Enterprise Desktop or Server systems for customers I often have a need to create an image of a system so that when I mess up, I can at least get back to a working state. Listed below are the steps to creating an image and then deploying that same image using dd.

WARNING: if you are not careful DD can erase your whole hard drive. Make sure you understand what the dd command is going to do before you run it.

  • Boot the system that you want to create an image of off of something other than the hard drive.
    • CD/DVD: If you have a SLED/S installation disk, boot off of it and choose rescue system. After the system is done loading login as root (no password required)
    • PXE: Often times people have a TFTP/PXE server setup to push down new installations. You can boot off of this (don’t worry we’re not going to re-install the OS). Once the part of the installer comes up that asks for your language you can hit Ctrl+Alt+f2 to get to a terminal
  • Attach storage.
    • You are going to need a place to store the image. The image will be the same size as the drive you’re using. If you have a 20G drive you’ll need 20G of space to store the image.
    • You can also mount some sort of a file share to store your image over the network
  • Create your image.
    • Figure out which device your hard drive is. (as root) Run fdisk -l This will show you all of the block devices attached to your system. Make sure you know which device is associated with which drive. If you are unsure unplug drives so that only the disk you want to image and the disk you want the image to be stored on remain. Most of the time the disk you want will be either /dev/hda (for ide) or /dev/sda (for sata). If you have a flash drive plugged in it will most likely be /dev/sda (if your main hard disk is ide) or /dev/sdb (if your main hard disk is sata)
    • For this article I will assume that you have mounted your storage device on /mnt. For example, you could mount /dev/sdb on /mnt with the command:# mount /dev/sdb/ mnt
    • Run run one of these commands:
      • IDE Drives: dd if=/dev/hda of=/mnt/image.dd
      • Sata Drives: dd if=/dev/sda of=/mnt/image.dd
      • This will create an image named “image.dd” in /mnt.
      • Notice that I am creating an image of /dev/hda or /dev/sda and not /dev/hda1 or /dev/sda1. Creating an image this way will allow you to image the master boot record so that the image is bootable when you restore it.

      Note: dd uses an input file (if) and output file (of) to operate, so of=/mnt/image.dd means to create a single block image encompassing the entire backed-up drive on the disk mounted at /mnt.

  • Restore your image.
    • Once again use fdisk -l to make sure that you are applying the image to the right disk.  Applying the image will blow away EVERYTHING that’s currently on the disk so be careful.
    • Run one of these commands:
      • IDE Drives: dd if=/mnt/image.dd of=/dev/hda
      • Sata Drives: dd if=/mnt/image.dd of=/dev/sda
  • Advanced Restoration (optional).
    • The image that you just created will work fine if it it applied to the same hardware that you used to create the image. Here are a few of the things that you will have to configure if you are applying the image to different hardware
    • Hard Drive type: If you created the image on a SATA drive but are applying it to an IDE drive there are a few files you need to edit before the system can even boot. This will require you to edit the files while booted from a CD/DVD/PXE etc.
      • Edit /boot/grub/menu.lst. Inside of this file (if you’re running a newer version of SUSE) you’ll find references to /dev/disk/by-id
        Such as:root=/dev/disk/by-id/scsi-SATA_ST980811AS_5LY1R323-part5. Change this to /dev/hda or /dev/sda. If you are running an older version of SUSE simply change the /dev/hda or /dev/sda to the appropriate value.
      • You will also have to edit your /etc/fstab file in a similar fashion to the way you edited your menu.lst file.
    • Networking: Each machine’s NIC has unique MAC address. Either before you create your image, or after remove the last line(s) from /etc/udev/rules.d/30-net_persistent_names.rules. Each NIC will have its own line. Remove all of the lines. When your system first boots it will recreate these lines with the appropriate values
    • Video: If you have a different video card or monitor then you will have to re-configure your /etc/X11/xorg.conf file. You will know if this file is mis-configured on your new machine because a charming blue screen with red lettering will pop up rather than your soothing GDM login screen. The easiest way to re-configure this file is to switch to runlevel 3 by running: init 3 and then run sax2 -r or sax2 -ra (this will automatically take the defaults). Once sax2 has finished running you can switch back to runlevel 5 by running init 5

Entry Filed under: dd. .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Blog Stats

Categories