Make a Drive Image Using an Ubuntu Live CD

Posted by Trevor Bekolay on How to geek See other posts from How to geek or by Trevor Bekolay
Published on Mon, 14 Jun 2010 12:00:00 +0000 Indexed on 2010/06/14 12:13 UTC
Read the original article Hit count: 655

Cloning a hard drive is useful, but what if you have to make several copies, or you just want to make a complete backup of a hard drive? Drive images let you put everything, and we mean everything, from your hard drive in one big file.

With an Ubuntu Live CD, this is a simple process – the versatile tool dd can do this for us right out of the box.

sshot-9

We’ve used dd to clone a hard drive before. Making a drive image is very similar, except instead of copying data from one hard drive to another, we copy from a hard drive to a file. Drive images are more flexible, as you can do what you please with the data once you’ve pulled it off the source drive.

Your drive image is going to be a big file, depending on the size of your source drive – dd will copy every bit of it, even if there’s only one tiny file stored on the whole hard drive. So, to start, make sure you have a device connected to your computer that will be large enough to hold the drive image.

Some ideas for places to store the drive image, and how to connect to them in an Ubuntu Live CD, can be found at this previous Live CD article. In this article, we’re going to make an image of a 1GB drive, and store it on another hard drive in the same PC.

Note: always be cautious when using dd, as it’s very easy to completely wipe out a drive, as we will show later in this article.

Creating a Drive Image

Boot up into the Ubuntu Live CD environment.

Since we’re going to store the drive image on a local hard drive, we first have to mount it. Click on Places and then the location that you want to store the image on – in our case, a 136GB internal drive.

sshot-1

Open a terminal window (Applications > Accessories > Terminal) and navigate to the newly mounted drive. All mounted drives should be in /media, so we’ll use the command

cd /media

and then type the first few letters of our difficult-to-type drive, press tab to auto-complete the name, and switch to that directory.

sshot-2

If you wish to place the drive image in a specific folder, then navigate to it now. We’ll just place our drive image in the root of our mounted drive.

The next step is to determine the identifier for the drive you want to make an image of. In the terminal window, type in the command

sudo fdisk -l

sshot-3

Our 1GB drive is /dev/sda, so we make a note of that.

Now we’ll use dd to make the image. The invocation is

sudo dd if=/dev/sda of=./OldHD.img

This means that we want to copy from the input file (“if”) /dev/sda (our source drive) to the output file (“of”) OldHD.img, which is located in the current working directory (that’s the “.” portion of the “of” string).

sshot-4

It takes some time, but our image has been created…Let’s test to make sure it works.

Drive Image Testing: Wiping the Drive

Another interesting thing that dd can do is totally wipe out the data on a drive (a process we’ve covered before). The command for that is

sudo dd if=/dev/urandom of=/dev/sda

This takes some random data as input, and outputs it to our drive, /dev/sda.

sshot-5

If we examine the drive now using sudo fdisk –l, we can see that the drive is, indeed, wiped.

sshot-6

Drive Image Testing: Restoring the Drive Image

We can restore our drive image with a call to dd that’s very similar to how we created the image. The only difference is that the image is going to be out input file, and the drive now our output file.

The exact invocation is

sudo dd if=./OldHD.img of=/dev/sda

sshot-7

It takes a while, but when it’s finished, we can confirm with sudo fdisk –l that our drive is back to the way it used to be!

sshot-8

Conclusion

There are a lots of reasons to create a drive image, with backup being the most obvious. Fortunately, with dd creating a drive image only takes one line in a terminal window – if you’ve got an Ubuntu Live CD handy!


Got an opinion to share? Click here to join the discussion

Similar Articles Productive Geek Tips
Latest Software Reviews Tinyhacker Random Tips


© How to geek or respective owner

Related posts about linux

Related posts about ubuntu