Drive images are great to have, but hard to store if you don’t have a big external hard drive. We’ll show you how to create and transfer a drive image to another computer in one step.
The Ubuntu Live CD includes both utilities that we need for the source and destination computers out of the box – dd and ssh.
We’re fans of dd, having used it to clone hard drives and make drive images locally in the past. However, putting an image on an external drive and then transferring that to a different computer is a pain. Using a combination of dd and ssh lets us transfer a drive image from one computer to another in one step, requiring no local storage in between.
To set this up, you will need two computers, both running Linux. Of course, you can boot both computers up with an Ubuntu Live CD and this method will work great – you will need two separate Live CDs or USB drives, however. Ideally, both computers would be on the same local network, as transfer speeds will be much faster, but you can do this for most computers that you have ssh access to.
The first step is to boot up the computer you want to store the drive image on – the destination computer – and find its IP address. We’ve described several methods previously, but the most direct way is to open up a terminal and enter the command ifconfig.
Make a note of the computer’s IP address – if it’s on your local network, it should start with 192.168.
While you’re on that computer, also make sure that you have a place to store the drive image. Make sure that location is mounted, and make a note of its full path (for example, a newly mounted hard drive may have the path /media/HD-LABEL/).
Boot up the computer that has the drive you want to image using an Ubuntu Live CD.
First, ensure that you can ssh into the destination computer by opening a terminal window (Applications > Accessories > Terminal) and entering the command:
ssh <username>@<destination IP address>
If you’re doing this on the local network, and the destination computer is also running off of an Ubuntu Live CD, then the command should look something like
In our case, we’re accessing a remote Linux machine.
If you can ssh in with no problems, then type in “exit” to return to the normal terminal window on your source computer.
Now, we need to find the hard drive or hard drive partition that you want to make an image of. In the terminal window, enter in the command
sudo fdisk –l
In our case, we want to make an image of a small Linux partition, /dev/sda1. We’ll make a note of this device name.
Now the complicated part: the dd invocation. Here’s a generic version…
sudo dd if=<input device> | ssh <user>@<destination IP address> “dd of=<destination path>”
It looks complicated, but if you look piece-by-piece it should make sense. What may be new to you is the “|” character, which in Linux terms is called a “pipe”. It takes the output from the first half of the line (the dd if=<input> part) and sends it to the second half of the line (the ssh part) – or, it “pipes” the result of the left part to the right part.
In our example, we’ll be storing the drive image on a remote Linux machine, so our terminal command is:
sudo dd if=/dev/sda1 | ssh email@example.com “dd of=/home/tbekolay/LinuxPart.image”
If you’re doing this over the local network, and your destination computer is running an Ubuntu Live CD, the command will be something like:
sudo dd if=/dev/sda1 | ssh firstname.lastname@example.org “dd of=/media/HD-LABEL/LinuxPart.image”
Since we did this over the internet rather than on the local network, the speed is quite slow, but it did finish eventually. Doing this over a local network will go much faster.
Just to make sure, we accessed the destination computer again using ssh to make sure that the drive image was indeed created and transferred successfully.
With only one line typed into a terminal window, we were able to create an image of a partition on our local computer, and store that image on a computer miles away. Of course, this was a small partition; a much larger partition or a whole hard drive would be difficult to send over the internet, but this method will work great over a local network too!