Question Locked

Linux Drive Clone Question

0 helpful
27 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Ok, here is the deal, and I think this would be good to know for all of those looking into learning Linux as well.
Currently at work I have a system (desktop) with 2 IDE based drives, master (OS -- WinXP) and slave (for data recovery, images for testing, etc.). I had an internal drive bay for the second, but I need the storage now.
Anyway, I have started using USB drive bays to recover data. But I just ran into a problem.
On Thursday, I had an ER recovery, and my manager requested the disk to be cloned. No Problem I say because I have done it many times. Usually it will take a few hours. But this time, it is cloning from a USB 2 drive. After an hour (Using Ghost 2003) I noticed that the speed was running at 17MB/Min. That translates to 1020MB/Hr. There is 36 GB on this drive.
Friday morning it was still running, and the user is asking why her system is not ready.
Then, another user comes in with a system that BSOD's on boot. It is easily tracked to the SW reg hive being corrupt. I could not use my machine for another 14 hours so, I setup a new desktop system with XP, 2 Hdd's and Ghost. Borrowed a USB drive bay, and started it. It ran at 112MB/Min.. Great, I thought about taking the first drive and using it on the new system. But after 5 min, it was running at 17MB/min.
Ok, this is too slow, in Windows, it works fast like it should, from the Ghost boot it runs like molasses.

Is there a solution in Linux that can clone a drive to an image file to be extracted on another drive where both the source and destination are a USB drive bay.
And, will it keep Linux open where the USB will work better, or will it close out to the command line or perform like ghost? Later Friday, I had another users drive go out and I had to tell them I could not get to it until Monday.
I was reading a bit on DD, but it looks like it just clones the drive to another, but I did not see anything that said it worked on USB drives, or that it creates a file to be extracted.

Any help would be appreciated, and I do mark as helpful. I just want to get the clone time down to a reasonable time frame. Cause 36+ hours for 36GB is just way too much.

27 replies

by saurondor

Linux (at least the ones I've worked with) creates a /dev/sdaX for the USB drives. Pretty much like /dev/hdaX is for your hard drives. So using dd with 'if' and/or 'of' as /dev/sdaX (where X should be replaced with the proper identifier) should work. For example:

dd if=all.img of=/dev/sda1

Would mirror the all.img file to whatever is connected on /dev/sda1 (namely your USB drive)

You can read more here:

http://wiki.mandriva.com/en/Docs/Installing_Mandriva_Linux

by w2ktechman

but what about to create the image? I will look more into DD in a bit, thanks so far.
Do you know if DD has the ability to create image files, or just clone and extract?

by saurondor

I believe that if you reverse the parameters then the image file would be created from the contents of /dev/sda1

by stephenmollett

If you wanted to show off (or just save
disk space), you could even compress the
image as you create it with:

dd if=/dev/sdx | gzip -9 > disk.img.gz

(I'm guessing you're a Linux command-line
newbie so I'll explain: If you don't
specify an output file for dd, it'll write
to standard output - normally the console.
The "|" pipes the standard output to gzip
instead, which reads from standard input
and writes to standard output if you don't
give it a file to compress. The ">" sends
gzip's standard output to the file
disk.img.gz.)

Then you can decompress on the fly as you
restore it:

gzip -dc disk.img.gz | dd of=/dev/sdx

Of course, you can always compress existing
uncompressed images with:

gzip -v9 disk.img

or decompress them with:

gunzip disk.img.gz

It'll take rather longer to create the
compressed image, of course, but restoring
it shouldn't be that much slower (if at
all) if you've got a reasonably fast
system. It may even be faster because
you'll be reading less from the source disk
so there'll be more bandwidth available for
writing to the destination.

If you're going to compress the image, it's
worth using some kind of wiping utility on
the source disk first to zero out all the
free space - you'll save quite a bit of
space that way.

On the subject of USB disks going slowly,
maybe the slowness is something to with the
USB bandwidth allocation. I often get odd
results when I've got two fast USB disks on
the go at once, such as one stalling while
the other is being accessed. Where
possible, I try to connect one disk to my
FireWire port and the other to USB if I've
got to use two external drives, but
obviously that depends on having a choice
of interfaces on at least one of the
drives.

by dumphrey

on the 2 usb disks. The issue is probably a low budget usb controller on the mobo. I would be willing to bet most consumer boards have this same problem. Ill have to test it out and see, I have never tried to move larg data chunks from one usb disk to another. If it is the case, adding a pci USB 2 card could solve a lot of problems.

by revdarkman

I too have recently needed to create images of new systems, I ended up using partimage from the system rescue CD (www.sysresccd.org) I did not use USB disks but created a samba share on another machine, and on a gigabit LAn it created images in 30 mins or so. The CD is worth a look for the other tools as well.

by mc_hendriks

You can download and install mondo-archive this backups a complete drive to another medium cd/dvd and problably also usb-drives. Afterwords you can boot from the new image and do a mondo-restore.

by dumphrey

is a good program I have used several times in the past. It is nice in that it can (and prefers) to send and receive images to and from a tftp server over the network. But it can also do local disk clone jobs. As for your ghost clone, I have no idea why its so slow, it should not be. I get at least 98MB/min on mine when booting off the ghost cd and cloning to a usb 2 drive. I would double check that your port is usb2, and or make a custom boot disk with the usb drivers for your machine. Ghost 2003/Corp 8 was the last good Ghost product from THEM.

by w2ktechman

Thank You all for replying. I will consider this question closed now. I have lots of things to try, but I ran into a new problem, as on 2 Linux Distros, they will not recognise the external USB drive (tried 5 drives) and Win finds them all. Some have data, some do not. The USB flash drives are all found just fine. So I need to get by this stump before I can continue with the image part.

Once again, thank you all for the help and support.

by dumphrey

removing them from the Win machine, use the safely remove hardware option. This is sometimes needed if NTFS does not "shut down cleanly" linux will not mount it. But, if its fat32 file systems linux is not seeing, im not sure. When you plug the device in, do you get any messages in dmesg?

by w2ktechman

the drive spins up.
When reading about DD it states to only have the drive on "free space" so I removed everything including the partition on one of them.
Then I tried mounting it and it stated that there was no entry in /etc/fstab. I browsed around google for a bit and found what needed to be changed. After the change and a command to mount it, I lost the ability to read usb flash drives, and the HDD still could not be mounted.
I can pull up what I did later.

I am going to try it on a SUSE 10.2 system today. Also though, I might be avoiding the USB drive anyway (for now) as I have downloaded a few images for boot cd's and read up on running it through the network. This way I will not need to pull the HDD from the system to clone it.
More testing, little time. But this is the fun part.

by w2ktechman

In PClinuxOS I just could not get it to detect the USB drive, but I plugged it into SUSE 10.2, and it came up no problem.

But I have found several times in the past that what does not work in some distros, seems to work in SUSE. Except some common command line instructions (such as ifconfig).

by dumphrey

should not be needed for either a usb hard disk or a usb flash drive. I stick mine in the slot, and it loads, mounts, and puts an icon on the desktop (Ubuntu 6.10). But, it will also do this in fedora and gentoo (tested them in the past). It sounds like maybe you need to set your removable media access in the system preferences. In linux, as in windows and mac, USB just works. Linux is a little more picky about clean mount and unmount though.

by w2ktechman

until I tried getting it to read the HDD via USB. That is when I ran into problems. After searching through a dozen links from google, I had found several articles stating that problems with HDD's over 8GB can happen via USB and that extra config was needed. That is why I changed the file. But now I need to 'undo' the change so that my flash drive can work again.
no biggie, it took only a few minutes for the edit

by w2ktechman

In SUSE, it is mostly stock, I have not fiddled too much with it. In PCLinuxOS, I have changed around many things, mainly to test out or learn. I could have screwed something up without realizing it. I just got my disk back, so maybe it is time for a reload...
And, before you ask it, yes, I tweaked everything from being logged in as root (and I do know better). But it was a 'test' machine, so I thought it easier this way.

Thanks for everything so far.

by dumphrey

But its odd that PCLinux didnt detect it right away. Its the only distro that gives me WPA and a wireless driver on my laptop right off the install. Anyway, it did seem odd to be having problems with USB disks, I have a 500GB and a 400GB that I use back and forth between Ubuntu and Windows with no issues at all.

by w2ktechman

and that is not a double D as in bra size either, although those can be impressive as well.

Ok, what I meant to do was clone USB disk 1 to USB disk 2. Easy enough. The command should have been
dd if=dev/sda of=sdb
for a full clone. But, since I had not had coffee yet, and I was busy I had mis-typed and did not notice it. Here was the command
dd if=/dev/hda of=/dev/sdb
oops, see where it is going?
Instead of copying USB1 to USB2, I was copying my notebook HDD (SUSE install) to USB2. I continued to use the OS all day. Then I looked and the clone was done, that is when I noticed the mistake. Oops, it could not have cloned the OS while I was using it (I told myself). But out of curiosity, I decided to swap the drive and to my amazement, it booted up to my desktop....
Although it seemed slow, it booted to my desktop...
Ok, I would have assumed (incorrectly) that it would not have been able to mount the disk, or that it would not have been able to copy some obscure OS file or something while the OS was in use. How wrong was that (too many years of Windows I guess).
Ok, it was starting to really dog on me though, so something was wrong. I assumed that since it also cloned the swap partition, that I needed to clear it out or something, but how....lets try a reboot...
It worked.
I am using the cloned drive right now, and stowed the original for now. How cool is that, low performance hit, clone drive while using OS, and so far everything is working...

I am truly amazed at the dd command. Sometime by next week I will need to start creating and extracting image tests with it.

by dumphrey

Now if only we could find a way to make DD do differential backups to an existing image =) It would be a source for consistant backups off of a live machine.

by dumphrey

in as root occasionaly. I use to do it all the time, but as I made some serious blunders and learned from them, I started using su and sudo more and more. I managed to override some warnings in a gentoo emerge that created a situation where the login and session deamons were "gone". I had to boot from a rescue cd and basicly rebuild the base system =\ If I had not been root, it would have been more difficult to over ridethat warning. But, as they say, the best way to learn a new town is to get lost. The best way to learn a new OS is to break it and fix it.

by stephenmollett

... that they wouldn't be strictly
consistent. While the drive clone from the
live system worked, the filesystems were
not "frozen" so data was changing on the
disk as it was being cloned.

The fact that the cloned copy worked at all
is a testament to the robustness of the
filesystems that were in use.

There is a snapshot function for doing this
properly in Device Mapper, although I have
never used it. (See the LVM HOWTO for more
information.)

Stephen

by dumphrey

Thats some good info. I was very suprised that it worked at all, only thing I can think is that its was using a spapshot function to image the open files. Being linux, it may have used the system calls to initiate snapshot on the DD command....no idea really, but I will be looking into how to make use of the snapshots.

by stephenmollett

Don't forget that dd works by simply
copying the device (disk, partition, image
file, tape, etc.) one block at a time, and
has no concept of the filesystems or files
that reside on the device. It's just binary
data as far as dd is concerned. (It's quite
happy to let you do 'dd if=/dev/zero
of=/dev/null', which will run until you
stop it, copying never-ending zeroes into
the never-full bit-bucket! /dev/zero is
handy for wiping a disk reasonably
securely - I defy anyone to retrieve any
data afterwards without cracking open the
drive and using special equipment.)

So what it did was to copy each sector as
it went, and whatever happened to be in
that sector at the moment at which dd read
it in was what got saved in the clone. If a
file was added to a directory _after_ the
filesystem structure describing that
directory had been copied, the file would
not show up in the clone. The inode tables
would also be inconsistent with the disk
contents.

If you're feeling silly, you can even start
dd'ing then, a few minutes later, run mkfs
("format" in Windows parlance) on the drive
and dd will probably continue cloning it as
if nothing had happened. You might even be
able to mount the old filesystem in the
clone and see some of the files.

This is why you should really remount live
filesystems read-only if you're going to
image them with dd - it will ensure that
the filesystem stays consistent while it's
being cloned.

Also - *BEWARE* - the same works in
reverse: if you accidentally type something
like 'dd if=disk.img of=/dev/hda' instead
of, say, '... of=/dev/sda', you'll
overwrite your primary master IDE hard
drive, even if it's in use at the time!
(There are ways you can make this less
likely to happen, such as by using udev
rules to assign permissions for USB disks
that allow your regular user account to
access them directly instead of having to
be root. That way, you'll just get
an "access denied"-type error if you try to
overwrite your main drive.)

by w2ktechman

when I plug in a drive, it is automatically mounted. would I have to dismount it and then re-mount it as read-only?
If so, how would I add the read only part? Looking at the 'mount' command, it does not list this option.

by stephenmollett

The easiest way to remount a drive
read-only is to do:

mount -o remount,ro

where is the place where the
drive is mounted. (You can give the device
name instead of the mountpoint if you
prefer.) I don't use an automounter for
this very reason - I don't always want a
disk mounted when I attach/insert it (a
CD-RW or DVD-RW that I'm about to erase,
for example) and, if I do, I may not want
the default mount options.

If you're just going to image the drive,
you could simply unmount it from its icon
on your desktop (I'm assuming that these
fancy modern distributions all create
icons 'on the fly' for removable drives; my
homebrew system certainly did until I
disabled that feature).

by dumphrey

I can see how DD in and of its self is a very powerful tool. There is no need for a commercial product like ghost when DD will do this for free. A good multi disk VM seems just the thing to play with this.

Once again Stephen, good info and good descriptions of what DD is doing. Thanks again.

This discussion is closed to new replies.