LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   hard disk duplication (https://www.linuxquestions.org/questions/linux-software-2/hard-disk-duplication-284857/)

sharkzf6 02-01-2005 07:25 AM

hard disk duplication
 
Are there any good hard disk duplicators/copiers available for Linux? I plan on transferring this install to a larger drive now that I got all the hardware working. Thanks.

jiml8 02-01-2005 07:28 AM

Just use the dd command. Enter "man dd" at a shell prompt to get information.

sharkzf6 02-01-2005 08:32 AM

Quote:

Originally posted by jiml8
Just use the dd command. Enter "man dd" at a shell prompt to get information.
I checked it out. It seems more like a glorified copy command. I need a bit by bit duplication so that everything remains the same, including the MBR. Sorry, I've been brainwashed by Redmond so cut me some slack if I missed something in the manual... ;)

wpn146 02-01-2005 01:03 PM

Quote:

Originally posted by sharkzf6
I checked it out. It seems more like a glorified copy command. I need a bit by bit duplication so that everything remains the same, including the MBR. Sorry, I've been brainwashed by Redmond so cut me some slack if I missed something in the manual... ;)
See: http://www.rajeevnet.com/hacks_hints...s_cloning.html

sharkzf6 02-01-2005 02:03 PM

Quote:

Originally posted by wpn146
See: http://www.rajeevnet.com/hacks_hints...s_cloning.html
Thanks. I see your point. ;)

jiml8 02-01-2005 05:13 PM

A few months back, I posted a complete session at The Motley Fool on using Knoppix and dd to scroll an entire XP system off of a failing HD in a laptop, then replace the laptop HD and scroll the image back. This session had me saving a complete Windows HD onto a series of files on a Linux box with ext3 file system, then put it all back.

Subsequently, a friend of mine picked up on that session and with my permission reposted it on his website, which is a Windows help site. Here is the link; you might find it interesting.

http://www.williamaford.com/CloningaHDD.php

Also, as a matter of routine, I use dd (in a cron job) to scroll my entire Linux system off to another HD as a backup. Here is the command string I use for that:

Code:

dd if=/dev/sdc of=/mnt/sdb1/sysimg.img bs=512 skip=4193028 count=19824147
gzip /mnt/sdb1/sysimg.img

Note that in this latter example, I first did an fdisk -lu /dev/sdc to determine the start and end blocks of the system partition.

dd can do pretty much anything.

Tinkster 02-01-2005 05:27 PM

Quote:

Originally posted by jiml8
Code:

dd if=/dev/sdc of=/mnt/sdb1/sysimg.img bs=512 skip=4193028 count=19824147
gzip /mnt/sdb1/sysimg.img


What was the offset (skip=) for in your case?


Cheers,
Tink

sharkzf6 02-01-2005 05:32 PM

jiml8, how do you deal with size changing say from 6 gig to 80 gig? I'm a Linux newb, use to Win/DOS dups that do all the work for you when you upgrade to a bigger drive. Thanks.

jiml8 02-01-2005 09:06 PM

Quote:

What was the offset (skip=) for in your case?
My Linux system is on sdc2. I am imaging the entire partition, including the partition boot record. If I specify that I just want /dev/sdc2 using dd I don't get the partition boot record and if I try to do a restore - and the partition structure is damaged - the restore fails.

By specifying the entire disk, then specifying the skip and the number of blocks, I pick up every byte of the partition, including its boot record. I can then restore the whole thing if something happens.

jiml8 02-01-2005 09:19 PM

Quote:

jiml8, how do you deal with size changing say from 6 gig to 80 gig? I'm a Linux newb, use to Win/DOS dups that do all the work for you when you upgrade to a bigger drive. Thanks.
Depends on the file system. In the case of an ext2/ext3 file system, there are many choices.

The easiest way is to mount the new HD in the same box as the old HD, partition it, and just copy the stuff from the old drive and partition(s) to the new drive and partition(s). Then change the boot loader, change the fstab, and reboot.

Another way (much harder) is to make an image of each partition as I showed (setting the right skip for the beginning of each one), then copy the partitions one by one to the new HD, starting with the MBR, then the first partition. After copying each partition on the drive, before placing the next partition on, you resize the partition you just copied using parted or fdisk, then you use a tool such as resize2fs to resize the file system on that partition.

When you have completed this, you copy on the next partition, again resize using fdisk or parted, again resize the file system, and just keep on truckin'. This method is a lot harder because you have to keep track manually of where you are putting the partitions as you lay them down, and you have to make sure that you don't fdisk into overlapping partitions.

sharkzf6 02-02-2005 09:57 AM

Quote:

Originally posted by jiml8
Depends on the file system. In the case of an ext2/ext3 file system, there are many choices.

The easiest way is to mount the new HD in the same box as the old HD, partition it, and just copy the stuff from the old drive and partition(s) to the new drive and partition(s). Then change the boot loader, change the fstab, and reboot.

Let me make sure I have this straight. I partition the new drive using fdisk after it's installed in the box along with the old. Will that make the new drive hdb1, hdb5? What about hda0/hdb0 (MBR?)? Copy hda1and hda5 to the new disk partitions (hdb1, hdb5). Then change the boot loader, in my case grub (why? won't the new drives become hda1/hda5 once I put the 80 gig in by itself?). I'm not questioning your instructions by any means, just trying to understand all this, it'll help me pull this off without borking the drive and having to repeat. Then change fstab. Again, why? Won't the fstab that gets copied to the new drive have the correct info (mount point, type, options assuming the new partitions become hda1 and 5 after installing the 80 gig by itself)? Another thing. When I do an fdisk -l it shows 3 partitions - hda1, hda2 & hda5? Is that because 2 and 5 are the same physical partition, 2 being "e" (extended?) and 5 being inside 2? It's my swap file partition (you probably realize that). Do I even need that with 1 gig of RAM? It's always 0% used when I check it.

What I'd like to be able to do is, install the 2 drives at the same time on the same ide channel (as you said), duplicate the 6 to the 80. Then connect the 80 by itself and boot off that. I don't ever intend on having the 2 drives in at the same time other than during the duplication process. In this case, I would also create a third partition (or second if no swap) on the 80 free space for use.

Sorry about all the questions, I'm use to doing this in DOS/Windows where it's basically a no-brainer.

jiml8 02-02-2005 10:46 AM

Quote:

Sorry about all the questions, I'm use to doing this in DOS/Windows where it's basically a no-brainer.
I don't think I would call it a no brainer in Windows, but it isn't difficult. It is no more difficult in Linux, just a bit different.

Since you wish to remove the old HD when you are done, it is simple enough. Insert the 80 Gig drive and format/partition it as it suits you. Whether you need a swap file is a matter of considerable debate on this site; I personally would always use a swap file. Presently my system, which has 1 Gig of RAM, has all RAM in use and 394 Megs of Swap as well.

Anyway, after formatting and partitioning the new drive, just copy everything from the old drive to the new drive. After you have done that, copy the MBR over using this command:

Code:

dd if=/dev/hda of=/dev/hdb bs=512 count=1
Then shut the system down, remove the old drive, restart the computer, and that should be it.

Because you want to remove the old drive, you don't have to modify fstab or the boot loader.

One comment; To avoid any troubles with an old BIOS in the computer you are upgrading, I think I might make a separate /boot/ partition at the very front of your new HD, then copy all the contents of /boot/ into it. I then would modify menu.lst in the /boot/grub directory to enable the system to transfer control to your root partition after booting.

Specifically, with both drives in the system and hdb your big new drive, partition hdb1 to be maybe 30 Megs, and copy all of /boot/ into it. Then make a new partition hdb2 for swap. You pick the size; I would use 1 Gig. Then make another new partition hdb3 which fills the rest of the drive.

Go to /hdb1/boot/grub/menu.lst and change it so that it says, for instance,

Code:

kernel (hd0,1)/boot/vmlinuz root=/dev/hda3 ...
Then shut down, remove the old HD, and restart. Should be fine.

You can determine how big /boot really needs to be by entering this command:

Code:

du --max-depth=1 /boot
from which you will get the size of the current /boot directory.

If you are sure your BIOS is recent enough to handle large hard drives without trouble, then you don't have to worry about doing this.

jiml8 02-02-2005 10:54 AM

Oh, one further comment.

Since you are running mandrake, you don't have to fdisk everything. Just do it with diskdrake.

sharkzf6 02-02-2005 01:24 PM

jiml8, First of all, thank you for the info, the steps you described are exactly what I'm looking for, should be rather easy. As for my BIOS, currently, I have an 80 gig drive on this box that is a WinXP boot drive. My hardware, including motherboard is pretty new so there's no reason to be concerned about drive size. See, right now I have the 80 gig disconnected and the little 6 gig hooked up. I did this so I could play with Linux without messing up my WinXP boot (much data, games, bookmarks...you get the picture). Ultimately, I'm going to rig a hard switch so I can manually switch between the two drives. Yes, I know all about programs like boot commander, even Lilo or grub could handle a dual boot system if I'm not mistaken. I choose not to do it that way for reasons that shall remain out of this discussion. Anyway, thanks again for your help. I think I can pull this off with no problems. If I have anymore questions, I'll post back. BTW - I'm using the unbuntu Hoary distro, not Mandrake. Cheers.


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