Ghost your Suse installation with dd
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 -lThis 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/hdaor/dev/sdaand not/dev/hda1or/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:
dduses an input file (if) and output file (of) to operate, soof=/mnt/image.ddmeans to create a single block image encompassing the entire backed-up drive on the disk mounted at/mnt. - IDE Drives:
- Figure out which device your hard drive is. (as root) Run
- Restore your image.
- Once again use
fdisk -lto 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
- IDE Drives:
- Once again use
- 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/hdaor/dev/sda. If you are running an older version of SUSE simply change the/dev/hdaor/dev/sdato the appropriate value. - You will also have to edit your
/etc/fstabfile in a similar fashion to the way you edited yourmenu.lstfile.
- Edit
- 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.conffile. 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 3and then runsax2 -rorsax2 -ra(this will automatically take the defaults). Oncesax2has finished running you can switch back to runlevel 5 by runninginit 5














Post a comment