LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   how do make an exact copy of my Linux drive? (https://www.linuxquestions.org/questions/linux-hardware-18/how-do-make-an-exact-copy-of-my-linux-drive-728118/)

joseph2020 05-24-2009 12:54 AM

how do make an exact copy of my Linux drive?
 
My old faithful 40 gig hard drive (sda1) is starting to make some bad noises and I am afraid it will die soon. I have a 80 gig drive (sdb1) already formated as ext2 with gparted, mounted and accessible on my Ubuntu desktop. I have all permissions for it.

What is an easy way to clone the 40 gig to the 80 gig? I want an exact copy so I can boot from it.

Looking around I found a command named "ddrescue"... here's the plan:
(/media/backdrive is mount point for sdb1)
Quote:

1) type in the console
Code:

sudo ddrescue /dev/sda1 /media/backdrive
2) when finished, turn off the PC, swap the drives/master/slave jumpers.
3) now the drives are exchanged; sda1 is now sdb1, etc.
3) start PC and hope it reboots from the cloned drive, and hope the partitions are read correctly. (do this step about 50 times, until I'm absolutely sure it works)
4) reformat 40 gig with gparted and try to repair
5) continue existence as a Ubuntu user
This just seems too easy! I must be missing something. Nothing is this easy in Linux.

I am concerned if all the devices will exchange positions without too much serious intervention. Will this work? Is there a better way of doing it? Anyone have any good ideas?. (.tar is not an option).

Thanks in advance

Nikosis 05-24-2009 01:08 AM

what about rsync

SqdnGuns 05-24-2009 01:14 AM

Quote:

Originally Posted by Nikosis (Post 3550798)
what about rsync

rsync won't copy the blocks correctly nor the boot sector, If he wants to use this as the new bootable drive, use dd rescue, I use it at least a 1/2 a dozen times a week at work to rescue customers critical data that they FAILED to have a back up of.

Get a USB stick to save the log file to, then mount it.

I use ddrescue /dev/"SRC_DRIVE" /dev/"DEST_DRIVE" /dev/"USB_STICK"/logfile_name.txt -b -1 4096

It's late and I am forgetting all the switches. Search the LQWiki for ddrescue, that shuld point you in the right direction.

Nikosis 05-24-2009 02:01 AM

Quote:

As a backup administrator, I would have to say that dd should never be used for backups. It's more of a utility to create disk image files, not intended for long term storage and or disaster recovery.
But in this case I think ddrescue can be a solution.

rsync can be used to make a bootable clone as well. In addition to basic file copying, rsync also offers the ability to synchronize the source and target volumes -- it can copy only the items that have changed, thus subsequent clones, or backups, are much faster. The syntax is pretty easy:

rsync -xrlptgoEv --progress --delete / /Volumes/Backup

That will backup your entire drive, deleting anything from the target that is not on the source drive (synchronizing, that is). Rsync also preserves resource forks (that's what the "E" argument is for) and will give you a bootable backup. You might want to learn more about using rsync to regularly backup your drive.

syg00 05-24-2009 02:31 AM

Any number of tools will do the job - including those mentioned.
Personally I have to agree with Nikosis. I prefer a filesystem aware copy ("cp -a ...", rsync ..., whatever) so that faults in the filesystem itself are exposed immediately. Imaging tools I use for recovery scenarios only.
But this is Linux - lots of choices.

Nikosis 05-24-2009 03:46 AM

As for MBR you can always make sure that you'll have the MBR by backing it up using dd

Back up the MBR
Code:

dd if=/dev/sda of=/home/sda.boot.mbr bs=512 count=1
Copy MBR to another disk
Code:

dd if=/home/sda.boot.mbr of=/dev/sdb bs=512 count=1
It probably can be done using one command
Code:

dd if=/dev/sda of=/dev/sdb bs=512 count=1
Once again, the choice is yours
You may want to take a look at this also

joseph2020 05-25-2009 12:37 AM

Nikosis, thanks much for your helpful reply

Quote:

Once again, the choice is yours
You may want to take a look at this also
I appreciate that link, I have bookmarked it and will be reading it as soon as I can. The drive might fail at any time, I need to clone it ASAP.

Quote:

As for MBR you can always make sure that you'll have the MBR by backing it up using dd
Please tell me I don't have to backup the MBR separately....won't rsync take care of that for me?

For now it seems rsync is the quickest and easiest solution. I have downloaded and installed a GUI for rsync (grsync) and will be trying that tonight.
Quote:

rsync can be used to make a bootable clone as well. In addition to basic file copying, rsync also offers the ability to synchronize the source and target volumes -- it can copy only the items that have changed, thus subsequent clones, or backups, are much faster. The syntax is pretty easy:

Code:

rsync -xrlptgoEv --progress --delete / /Volumes/Backup

You call that easy syntax?? I'd hate to see what you consider difficult.

Please explain the code if you can...where in the command is the source and destination drives for example? (source is /dev/sda and dest is /dev/sdb).... I guess the / is the source, but what is /volumes/backup? is that the dest? and what do all those letters (xrlptgoEv) mean? What does --progress --delete mean? I tried to read the man pages, but as usual not completely understood by me.

Lastly I want to clone the drive completely, including the extended/swap partition...in other words I want an exact copy of the source drive, including the MBR.

one last thought...if I clone a 40 gig to a 80 gig will it just not allocate 40 gigs or will that be part of the new drive useful space.

Thank you for putting up with all the questions and my lack of knowledge. I'm really lost on this one, running out of time, and getting a little worried. please help. Thank you.

AwesomeMachine 05-25-2009 02:32 AM

If you use dd, the resulting 80 GB drive will only be formatted for 40 GB, and it will be reported as full. So, you need to make a partition on the 80 GB about the same size as the whole 40 GB drive, and dd partitions at a time. You can't use dd to copy a MBR of a smaller drive to a larger drive, because the partition table data will be skewered.

You can use rsync, and copy files, then boot from any linux installation disk, choose 'rescue', or some similar thing from the boot prompt, and install the grub bootloader. Then the disk will boot.

joseph2020 05-25-2009 04:14 PM

Well, i tried rsync and it almost worked. It went on for over 12 hours and was still going when I forced it to stop. The cloned drive (sdb) only has the main partition ( no swap) and it is almost exactly twice the size of the original (11.77 GB vs 22.56 GB).

If anyone has any idea what's going on please explain. Otherwise I guess I will just wait until drive failure and rebuild the entire Ubuntu system from the ground up...how frustrating.

Thanks for the help

syg00 05-25-2009 04:37 PM

Are you doing this from the running system ?. If so, do it from a liveCD instead.

joseph2020 05-25-2009 08:24 PM

syg00

Quote:

Are you doing this from the running system ?. If so, do it from a liveCD instead.
Please explain...do you mean run rsync from the liveCD? What difference would that make?

Please show me the command to do what you mean, I am willing to try anything at this point.

thank you

syg00 05-26-2009 01:32 AM

Yes, do the rsync from a liveCD - the reason is that it avoids having to exclude the pseudo filesystems (like /dev and /proc) that can cause problems.
Just mount the target and source, and use the command above adjusted for mountpoint(s).

Nikosis 05-26-2009 01:39 AM

How many partition do you have, how big they are, and what file system do you use.
Since your disks are different sized (80GB and 40GB), you should make new partitions on a new one, by using fdisk or parted, then format it with any file system that you prefer. Then rsync all the files. Everything will be much faster now
Quote:

Please explain...do you mean run rsync from the liveCD? What difference would that make?
faster transfer, you can try slax or any other livecd

wabbalee 05-27-2009 09:34 PM

Just a suggestion, but why don't you use clonezilla live cd and gparted (live cd). I do this kind of thing (migrating from one drive to another) regularly and successfully using these two tools, and mostly within minutes rather then hours.

joseph2020 05-27-2009 10:03 PM

wabbalee

Quote:

Just a suggestion, but why don't you use clonezilla live cd and gparted (live cd)
Thank you for your reply. I have the clonezilla site bookmarked for possible later download (I use a dialup connection, so the download takes about 3.5 hours), and I already have Gparted liveCD.

Please tell me step by step how you would use these two utilities to transfer my Ububtu linux system to a different hard drive. It has to be a COMPLETE image, exactly the same as the source. Try to keep it super simple as I am still at beginner level with Linux.

Thanks again


All times are GMT -5. The time now is 12:47 AM.