Make a full hard disk image in Linux

To make a full hard disk image in linux we will use several small programs and a livecd.

Next to this we need a place to store the image (external hard disk?). Which livecd you use is not that important. Just make sure that you access the place where you want to store the image and that you have access to gzip, dd and swapoff (if there is a swap partition).

So let us see the steps to take:

  1. Boot into the livecd
  2. Make sure you can access the place where you want to store the image
  3. (1) Disable the swap partition on the hard disk you want to image
  4. (2) Start the image-making process
  5. Check if the image is stored on the requested locations without errors

So let us see which commands we have to use to perform actions (1) and (2):

(1)# sudo swapoff -a
(2)# sudo dd if=/dev/hd_ | gzip > /mnt/hd__/image_name.dd.gz

Restoring the image is as easy as making it. Let us see these steps as well

  1. Boot into the livecd
  2. Make sure you can access the place where your image is stored
  3. (3) Disable the swap partition on the hard disk you want to image
  4. (4) Start the image-restoring process
  5. Check if the image is restored on the requested location without errors

So let us see which commands we have to use to perform actions (3) and (4):

(3)# sudo swapoff -a
(4)# sudo gzip -dc /mnt/hd__/image_name.dd.gz | dd of=/dev/hd_

That is it. I hope it is/was helpful.

Comments

Anonymous (not verified)

.), February 24th, 2009

Why do we have to swapoff? 

patrick

. March 4th, 2009

Well, if(!) the swap partition is on the harddrive you want to make the image from, then it should be off. We do not want to change anything on that harddisk anymore.

As some people do not realise where their swap partition is located, it is safer to just switch the swap space off.

If you are shure that your swap partition is on an other harddrive you can leave it on, otherwise I recommend you to switch it off.

Furthermore, for a livecd session, swapoff will not have a lot of influence. The session might become a bit slower, but as it is a temporary session anyway, we should not care.

I hope that answers your question.

Anonymous (not verified)

. February 8th, 2011

Maybe I don’t get it, but why would you want to do this? What is the practical use?   Anyway, too bad that your spam filter does not accept this. God knows why. I thought that is what you have yr captcha for

patrick

. February 9th, 2011

Well, this is a good question actually: What is the use? The use is diverse, but let me give you some examples: 1) You did something stupid to your hard-disk like formatting it with a new filesystem. Before attempting to recover the data, this type of backup is useful. If you try a crappy tool that changes anything on your disk, you at least have a backup to try again. 3) You have tweaked, changed, and fixed your OS to bring you the best experience. Then there is this update. Before the update you make this type of backup. If, after the update, you don’t like what the update did… or you need some details from the old system… Then can recover that old system without any difficulty. 2) Some visualization solutions accept binary images as virtual machine disks.   I hope that this answers your question, but if not… I am sure you know how to contact me.   PS. About my spam settings: see the “Home” page (left-top menu).

Ken (not verified)

. August 9th, 2011

I usually use utilities like CloneZIlla, but with this operation, I can use a DamnSmallLinux disc to go into the terminal and do these easy steps. Also, you can still install packages on a temporary basis in livecd environments (Ubuntu I know for sure) so you can write the image file to a SSH, SMB, or FTP server if you want. For example, I am using these steps to write an image to an SSH mountpoint:

  > % sudo apt-get insall sshfs > > % sudo passwd > > (this allows you to do operations as root, so change the password) > > % su > > % sshfs user@server:/path/of/directory /mount/point

Then I followed the steps above, just using the SSH mountpoint I created and so far I have 3.3G of the disk image created.

 

Thanks for the info!!