Backup of drive

Asked by David Vincent-Jones

I am running a XP/Ubuntu dual boot

Is it possible to boot from the install disk and then copy my entire hard drive with all partitions over to an equal sized external drive?

Thanks;

David

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu yelp Edit question
Assignee:
No assignee Edit question
Solved by:
Allen Chemist
Solved:
Last query:
Last reply:

This question was reopened

Revision history for this message
Allen Chemist (alchemist) said :
#1

Hi David,

Yes you can do a number of things, easiest is to use the command line (I find). Once you have booted off the liveCD (the install disk), start up a terminal.

First you will need to know your hard drives identifier. You can do a:
sudo fdisk -l

It will probably be called /dev/sda or /dev/hda, depending if it is a sata drive or eide.

From there, you can do individual partitions, or the entire drive using a tool called dd.

To do the entire drive, to an IMAGE on your spare drive, do the following:
sudo dd if=/dev/sda of=/media/usbdisk/drivebackup.img

where /media/usbdisk/ is the path to your external drive you wish to backup to.

You can also do individual partitions, using:
sudo dd if=/dev/sda1 of=/media/usbdisk/partition1.img

Also, if you want to "clone" the hard drive, you can set the of= to the drive you wish to write it to, such as

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

One of my favourite features of doing it this way, is you can modify the image using the mount command.
sudo mount -o loop /media/usbdisk/partition1.img /media/drivebackup/

There is further information found on this site:
http://wiki.linuxquestions.org/wiki/Dd

Let me know if you need further explanation on any of this :)

-Allen

Revision history for this message
David Vincent-Jones (davidvj) said :
#2

Thank you for the very comprehensive reply; this has been most useful.

David

Revision history for this message
David Vincent-Jones (davidvj) said :
#3

Allen;

Still some questions:

I appear to have a problem addressing my external hard drive.
First I checked all drive addresses as follows:

ubuntu@ubuntu:~$ sudo fdisk -l

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xd5e5d5e5

   Device Boot Start End Blocks Id System
/dev/sda1 * 1 8286 66557263+ b W95 FAT32
/dev/sda2 8547 19119 84927622+ 83 Linux
/dev/sda3 19120 19457 2714985 5 Extended
/dev/sda5 19120 19457 2714953+ 82 Linux swap / Solaris

Disk /dev/sdb: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x28f12a69

   Device Boot Start End Blocks Id System
/dev/sdb1 1 19457 156288321 83 Linux

.... then I tried your proposed all disk backup in several 'flavors' ....

ubuntu@ubuntu:~$ sudo dd if=/dev/sdal of=/dev/sbd1/drivebackup.img
dd: opening `/dev/sdal': No such file or directory
ubuntu@ubuntu:~$ sudo dd if=/dev/sdal of=/dev/sbd1
dd: opening `/dev/sdal': No such file or directory
ubuntu@ubuntu:~$ sudo dd if=/dev/sda of=/dev/sbd1/drivebackup.img
dd: opening `/dev/sbd1/drivebackup.img': No such file or directory
ubuntu@ubuntu:~$ sudo dd if=/dev/sda of=/dev/sdb1/drivebackup.img
dd: opening `/dev/sdb1/drivebackup.img': Not a directory

I then (I think incorrectly) thought that I may not need an output file name

ubuntu@ubuntu:~$ sudo dd if=/dev/sda of=/dev/sdb1
dd: writing to `/dev/sdb1': Input/output error
312576641+0 records in
312576640+0 records out
160039239680 bytes (160 GB) copied, 28796.3 seconds, 5.6 MB/s
ubuntu@ubuntu:~$

I just finished up with a blank disk ... after a long wait.

Final test was using an example from the reference that you provided to work on a single partition ...

david@david-laptop:~$ sudo dd if=/dev/sda1 | gzip > /dev/sdb1/w95_partition_backup.img.gz
bash: /dev/sdb1/w95_partition_backup.img.gz: Not a directory

I now conclude that my fo address must be incorrect
How do I correctly address my external drive ... if that is the problem!

David

Revision history for this message
Best Allen Chemist (alchemist) said :
#4

Sure, here are some examples of what you did above, and the mistakes in them.

Note that "/media/sdb1" is only my guess on a name when referring to the /media/ folder. If you plug in a usb disk, sometimes they are named 'usbdisk' or 'corsair' (my Corsair flash drive names itself corsair when I plug it in), while other times they are assigned the device name (sdb). In the case of my usb stick, it would be dd if=/dev/sda1 of=/media/corsair/drivebackup.img

sudo dd if=/dev/sdal of=/dev/sbd1/drivebackup.img
1. It's sda1 not sdaL (the number one, not the letter L)
2. If you want to create an image, you need to put it on the filesystem, not directly on the device.

Note that /dev/ is for device (as in if you are copying the entire device, or writing an image onto an entire device)
then /media/ is the location where that device is mounted. Putting something on /media is like saving an image for you to later edit/copy/etc.

I think your intended operation should have been:
sudo dd if=/dev/sda1 of=/media/sdb1/drivebackup.img
(create the image and save it on the hard drive, so it is one big file on the hard drive, and you are free to copy it/move it to another drive)
OR
sudo dd if=/dev/sda1 of=/dev/sdb1
(clone the first partition of sda onto sdb. Now you would have two windows installations, one on each hard drive. Note this does not copy the master boot record (MBR), so you couldn't 'boot' off the second drive... but if you could boot off it, windows would load just fine. Read on below for copying the MBR as well).

ubuntu@ubuntu:~$ sudo dd if=/dev/sdal of=/dev/sbd1
This would have worked (except for the sda1 sdaL thing from the first one above), copying your entire windows partition to the first partition of the second drive (creating a mirror image of windows. I use this to have a backup drive, should the first one fail.

sudo dd if=/dev/sda of=/dev/sbd1/drivebackup.img
This you meant:
sudo dd if=/dev/sda of=/media/sdb1/drivebackup.img
If you are trying to save an image, it needs to go to the filesystem, not the device (so put it in /media/sdb1/drivebackup.img). Also, using sda means you are copying everything, including the master boot record, windows and linux.

This one is darn close:
ubuntu@ubuntu:~$ sudo dd if=/dev/sda of=/dev/sdb1
dd: writing to `/dev/sdb1': Input/output error
312576641+0 records in
312576640+0 records out
160039239680 bytes (160 GB) copied, 28796.3 seconds, 5.6 MB/s

This managed to copy 160gb of the ENTIRE Drive (partition tables, MBR, etc) into the FIRST PARTITION of sdb. This means, if you look at your USB drive, you would see this:
MBR, Partition table, First partition _MBR_Partition_table_First_Partition_your_backed_up_data

This has confused all the file access, since the drive seemingly restarts itself in the middle (What? A master boot record as the first thing in the partition?!)

... There are two things which you might mean here:
sudo dd if=/dev/sda of=/dev/sdb
This copies your entire drive (windows, linux, swap, etc) onto the second drive
sudo dd if=/dev/sda1 of=/dev/sdb1
This copies your windows drive onto the second drive (note you would need to setup the partition tables first)

I forgot to mention in my first post, you can do this over the network. I use this all the time with my laptop and my desktop. The desktop has a ton of storage on it, which i periodically back an image of my laptop up to.
Desktop IP is 192.168.1.100
On the desktop, I do:
nc -l -p 9000 | dd of=laptop.image

Then, on a livecd on the laptop, I do:
dd if=/dev/sda | nc 192.168.1.100 9000

As you can tell, I rather like dd ;)

-Allen

Revision history for this message
David Vincent-Jones (davidvj) said :
#5

Thank you Allen for a most comprehensive response .... it will probably take me some time to experiment with all of the options.

My only difficulty is in being able to monitor the process ... it would be wonderful if some sort of 'progress bar was possible.

Yes dd is rather neat ....

David