LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   Transfer data from one HD to the other?? (https://www.linuxquestions.org/questions/linux-hardware-18/transfer-data-from-one-hd-to-the-other-542416/)

Biggen 04-01-2007 01:27 PM

Transfer data from one HD to the other??
 
Ok, first some background on what I have. Currently I have a 20GB hard drive that was used to install SuSe 10.2 on. SuSe created (at installation time) three partitions that are:

1. /dev/hda1 (swap ~600MB)
2. /dev/hda2 (/ 7.3GB)
3. /dev/hda3 (/home 10.7GB)

Now I have an 80GB hard drive that I would like to have replace the 20GB. Basically I want to copy all the files from my 20GB onto my 80GB, have it set as bootable and get rid of the 20GB completely. The reason for doing this is I am going to begin running Hardware RAID here soon (Level 1) and want to get rid of the smaller drive and then buy another 80GB drive so that I will have to 80's in the system.

So here are the questions:

1. Do I create the exact same three partitions on my 80GB drive but (obviously) have them created to use the extra space on the 80GB? How big should I make the /home, /, and swap partitions on the 80GB drive??

2. Is it really as easy as copying everything from the 20GB drive over to the 80GB once the three partitions are created? If this is so, do I simply mark the 80GB as bootable after this is done?? Would this work? What copy command would I use to make sure that EVERY file and copied to the 80GB and that all directories and recursive's are intact?

And, finally, does any of this make sense or is there an easier way to transfer files to a new drive than what I am suggesting?

Thanks!!

Rodman

Quakeboy02 04-01-2007 02:05 PM

Here's a thread that's relevant to your question. It's about Debian, so you'll have to take that into consideration. But, the general issue of copying from one disk to another is basically the same. I've learned that it's best to do this copy, while booted from a liveCD.

http://www.linuxquestions.org/questi...15#post2663415

Biggen 04-01-2007 02:14 PM

Quote:

Originally Posted by Quakeboy02
Here's a thread that's relevant to your question. It's about Debian, so you'll have to take that into consideration. But, the general issue of copying from one disk to another is basically the same. I've learned that it's best to do this copy, while booted from a liveCD.

http://www.linuxquestions.org/questi...15#post2663415

Just read over it. I wonder if it would be easier to just use Ghost Linux to create a clone. And then tell GRUB to boot from the new Hard drive?

Quakeboy02 04-01-2007 02:23 PM

If your "from" partition is the same size as your "to" partition, then you can even use "dd". AwsomeMachine has an excellent thread on the use of "dd" here:

http://www.linuxquestions.org/questi...d.php?t=362506

Biggen 04-01-2007 02:37 PM

Quote:

Originally Posted by Quakeboy02
If your "from" partition is the same size as your "to" partition, then you can even use "dd". AwsomeMachine has an excellent thread on the use of "dd" here:

http://www.linuxquestions.org/questi...d.php?t=362506

Well the source is smaller than the target. It appears that dd will still work. If that is the case I just have to figure out how to resize the paritions after dd moves them over to the bigger drive...

Quakeboy02 04-01-2007 02:45 PM

Quote:

Well the source is smaller than the target. It appears that dd will still work. If that is the case I just have to figure out how to resize the paritions after dd moves them over to the bigger drive...
If it's ext2/ext3, then you can try the resize2fs command.

Biggen 04-01-2007 03:15 PM

Quote:

Originally Posted by Quakeboy02
If it's ext2/ext3, then you can try the resize2fs command.

Ok, I think this is what I am going to do. I am going to use Ghost or G4U (haven't decided), then am going to try and resize the partitions with resize2fs. Currently, my 80GB hard drive (the target) does not have any partitions defined. Do I need define the three partitions on the 80GB drive or just leave it empty and let Ghost or G4U do the work?

Quakeboy02 04-01-2007 03:33 PM

I've never used them. It would be very helpful, though, if you would report what you did after you get it doing. There is always the next guy who's gonna have the same question.

jiml8 04-01-2007 03:44 PM

dd if=/dev/hda of=/dev/hdb

will copy the entire contents of the older and smaller drive to the new drive, with the exact same structure. The result will be that the new drive is bootable and has the same partition structure as the old drive.

As a consequence of this, you will have a lot of empty space on the back end of the new drive, which you then can partition.

Resize2fs won't help you because this will resize the filesystem, not the partition, and it won't enlarge a filesystem to be larger than the partition.

You won't be able to enlarge hda1 or hda2 because the end of these partitions leads immediately to the start of the subsequent partition, hence there is no space available to enlarge into. You would be able to enlarge hda3 since nothing is at the end of it.

If you wish to enlarge the partitions, your best choice is to just partition the new drive with the partition sizes that you want to have, then use the cp command recursively (or use a window manager's click and drag facility, which turns out to be much faster) to copy all the contents of the old partition to the new partition. You can even do this with the active system partition so long as you block any cron jobs from running and just sit and watch while the copy occurs.

When you have finished all of this copying, copy the bootblock from the old HD to the new HD using dd, exactly like this:

dd if=/dev/hda of=/dev/hdb bs=446 count=1

Pay particular attention to the bs=446; you want to copy exactly the first 446 bytes of the HD, not one less and not one more.

Once you have done this, your new drive will be completely bootable, and will contain the exact information of the old HD except on your new resized partitions.

jiml8 04-01-2007 03:53 PM

Oh, and as an aside...

I generally place swap someplace in the middle of the drive, not at the end. Reason is to minimize average head travel to reach it. Thus, with your organization, I would put it between / and /home.

Biggen 04-01-2007 04:09 PM

Quote:

Originally Posted by jiml8
Oh, and as an aside...

I generally place swap someplace in the middle of the drive, not at the end. Reason is to minimize average head travel to reach it. Thus, with your organization, I would put it between / and /home.

Wow, Jim, great info!! What is the exact "cp" to use? Something like "cp -arx /dev/hda1 /dev/hdb1"? Then the exact same thing for "/dev/hda2 /dev/hdb2", and "dev/hda3/hdb3"? Or can I use a generic command like "cp -arx /dev/hda /dev/hdb"?

So basically I need go ahead and create three partitions on my new drive with the partition sizes I want (I need mount points correct? Same as those on the old 20GB drive?). I read somewhere that swap should be approx double your ram or so. I have around 300MB of RAM so the swap should be around 600MB? What about the sizes for "/" and "/home"? Any suggestions?

After I create those partitions, I format them, and then I can use a live-cd distro to boot with. I can then cp from hda to hdd. Then, when the copying is finished, I issue
dd if=/dev/hda of=/dev/hdb bs=446 count=1 which will copy the MBR (I'm assuming) to the new drive. Then instead of playing around with GRUB, I can just move the 80GB hard drive to the same connector the 20GB was on so that the system can still boot to /dev/hda without me having to change it to /dev/hdd which is what it is now (Slave on the Secondary IDE channel).

Quakeboy02 04-01-2007 04:16 PM

Do you actually run processes that use the swap space? If not, it doesn't matter where you put it. If you do, then you might consider spending a few bucks and getting more RAM.

jiml8 04-01-2007 05:14 PM

Quote:

Originally Posted by Biggen
Wow, Jim, great info!! What is the exact "cp" to use? Something like "cp -arx /dev/hda1 /dev/hdb1"? Then the exact same thing for "/dev/hda2 /dev/hdb2", and "dev/hda3/hdb3"?

Not exactly. You have to have the partitions mounted and refer to them via their mountpoints. I would choose options that clone the files, keeping datestamps and permissions. Don't know offhand which options those are; I'd have to look it up, but you can do that too.

It actually would go quicker to use KDE click and drag for the copies, including the copy of /, because as it turns out KDE does it much faster than cp does.

Quote:

Or can I use a generic command like "cp -arx /dev/hda /dev/hdb"?
no

Quote:

So basically I need go ahead and create three partitions on my new drive with the partition sizes I want (I need mount points correct? Same as those on the old 20GB drive?).
Yes, and yes.

Quote:

I read somewhere that swap should be approx double your ram or so. I have around 300MB of RAM so the swap should be around 600MB?
Just make sure you have enough to keep you out of trouble regardless of what you are doing.

Quote:

What about the sizes for "/" and "/home"? Any suggestions?
As much as you want, and more than you think you need.

Quote:

After I create those partitions, I format them, and then I can use a live-cd distro to boot with. I can then cp from hda to hdd. Then, when the copying is finished, I issue
dd if=/dev/hda of=/dev/hdb bs=446 count=1 which will copy the MBR (I'm assuming) to the new drive. Then instead of playing around with GRUB, I can just move the 80GB hard drive to the same connector the 20GB was on so that the system can still boot to /dev/hda without me having to change it to /dev/hdd which is what it is now (Slave on the Secondary IDE channel).
Skip the live CD distro; you can do it from your running installation on hda2. When you then shut down the machine and move the HDs around, don't forget to change the jumper on the 80 Gig drive.

jiml8 04-01-2007 05:17 PM

Quote:

Originally Posted by Quakeboy02
Do you actually run processes that use the swap space? If not, it doesn't matter where you put it. If you do, then you might consider spending a few bucks and getting more RAM.

I have 1 Gig RAM and 1 Gig swap. I run a linux workstation with a lot of servers running since I use those in my development work. I also run VMWare Workstation with at least one copy and often two or three copies of Windows 2000 up and running.

I can fill any system, and I use a lot of swap. Occasionally, I will close out some apps and disable swap to force everything back into main memory, then reenable swap.

Biggen 04-01-2007 06:19 PM

Ok, I fired up Yast2 and went to the partitioner. But there is a problem. I can't have the exact same mount points on a system. When I try to create "/" and "/home" on the second hard drive, Yast tells me "The Mount point is already in use, select another one". This makes since since the linux system uses a filesystem tree rather than drive letters. So I can't create two "/" or two anything elses... Right??

This is becoming more cumbersome than I had hoped. Am I doing something wrong?

I appreciate your help on this, btw. Networking is my thing, not linux file systems... :-(

jiml8 04-01-2007 07:25 PM

You are doing something wrong, indeed.

On your new HD, just build the partitions. Then, in your current /mnt, make the mountpoints for the new HD, such as /mnt/hdb2 and so forth.

Then copy the contents from your current / to the appropriate partition on the new HD; for instance cp / /mnt/hdb2.

Don't worry about /home, /, /sys, /mnt, or anything else; just copy the entire contents of one partition to the appropriate replacement on the other drive.

After you have done this and copied the MBR, then shut off the machine, move the HD, and everything will take care of itself. Your new drive which was hdb will be recognized as hda, your mountpoints will all be right, and the system will just boot.

Just make sure that, if you are booting off the second partition on your current boot drive, you copy / to the second partition on the new drive. If you copy / to some other partition on the new drive, then you'll have to edit your copied grub menu.lst to point to the proper partition before moving the drive.

It really does work that way. Think about it.

Biggen 04-02-2007 08:45 AM

Quote:

Originally Posted by jiml8
You are doing something wrong, indeed.

On your new HD, just build the partitions. Then, in your current /mnt, make the mountpoints for the new HD, such as /mnt/hdb2 and so forth.

Then copy the contents from your current / to the appropriate partition on the new HD; for instance cp / /mnt/hdb2.

Don't worry about /home, /, /sys, /mnt, or anything else; just copy the entire contents of one partition to the appropriate replacement on the other drive.

After you have done this and copied the MBR, then shut off the machine, move the HD, and everything will take care of itself. Your new drive which was hdb will be recognized as hda, your mountpoints will all be right, and the system will just boot.

Just make sure that, if you are booting off the second partition on your current boot drive, you copy / to the second partition on the new drive. If you copy / to some other partition on the new drive, then you'll have to edit your copied grub menu.lst to point to the proper partition before moving the drive.

It really does work that way. Think about it.

Ok, I think I have a little better understanding of what I am doing now. I created three partitions on hdd (my new drive) to mirror the partitions on hda. hda1 -> hdd1 (swap), hda2 -> hdd2 (/), and finally hda3 -> hdd3 (/home). I was going to put swap in the middle, but for right now I don't want to have to mess with GRUB. I need to get this figured out first.

Mount points were created as follows - hdd1 -> (just swap of course), hdd2 -> (/mnt/hdd2), and hdd3 -> (/mnt/hdd3).

I won't be able to use KDE as I have a video card problem in this machine so I'll have to stick with command line. So I'll have to use the "cp" command. I am pretty sure I want to use "cp -a" as that looks like it preserves time stamps and such.

So when I get to the office this morning I will do a "cp -a / /mnt/hdd2" and then "cp -a /home /mnt/hdd3". Finally I use dd to copy the MBR to the new drive with "dd if=/dev/hda of=/dev/hdb bs=446 count=1".

Shut down the machine, move the drives around so that hdd is now hda and boot up. Everything should work!! I'll report back if all went well! I appreciate your help! If you don't mind looking over this to make sure it all looks good.

Rodman

jiml8 04-02-2007 09:03 AM

that should work. Just be sure you are doing the copy as root. Also don't forget the -r option on the cp so that it will recursively copy directories.

Biggen 04-02-2007 09:11 AM

Quote:

Originally Posted by jiml8
that should work. Just be sure you are doing the copy as root. Also don't forget the -r option on the cp so that it will recursively copy directories.

One more thing, Jim, before I start it. I know you said that I don't need to use a live distro to boot up and do the copy with. But if anything is written to a directory behind and after cp has copyied it over to hdd, won't I be missing that info? Should I kill crond at least to make sure that isn' running?? Anything else should I kill to try and make sure that I'm not missing anything??

Oh, and it isn't the "-a" option I want, I re-read the man page and it looks like I want "cp -rp". That should do it.

jiml8 04-02-2007 09:38 AM

In my first post on this thread I stated that killing cron would be a good plan. Not strictly necessary, but if a cron job runs and changes things while you are copying, you will indeed have an inconsistency between copies. Usually this won't matter, but then, it depends on what the cron is doing, now doesn't it.

You can, of course, just use a live CD distro. Me, I usually don't bother.

I commonly backup my / using the dd command to make a partition image. All I ever do is start the backup then go drink a cup of coffee (in other words, I don't touch the mouse or keyboard, stop all multimedia, etc). I never have any trouble, and I usually mount and browse the iso before gzipping it just to be sure it is OK.

Biggen 04-02-2007 09:55 AM

Quote:

Originally Posted by jiml8
In my first post on this thread I stated that killing cron would be a good plan. Not strictly necessary, but if a cron job runs and changes things while you are copying, you will indeed have an inconsistency between copies. Usually this won't matter, but then, it depends on what the cron is doing, now doesn't it.

You can, of course, just use a live CD distro. Me, I usually don't bother.

I commonly backup my / using the dd command to make a partition image. All I ever do is start the backup then go drink a cup of coffee (in other words, I don't touch the mouse or keyboard, stop all multimedia, etc). I never have any trouble, and I usually mount and browse the iso before gzipping it just to be sure it is OK.

Excellent! I'm downloading a live distro now. Using cp didn't work to well as it gave me errors on some files (i.e. resource busy or permission denied) even running as root. I'm guessing this is becuase those files are currently in use perhaps?? Dunno... I'll report back when I fire it up with the live CD and give it the cp commands then...

jiml8 04-02-2007 10:35 AM

Actually, I was just reading up on grub (if that is your bootloader) and I think that probably you'll need to reinstall grub on the new drive after copying it if you use the cp command.

Turns out that the MBR for grub has the absolute physical address of the second stage grub program hardcoded into it. When you use cp to copy the /boot sector from / to the new HD, it seems unlikely that the stage 2 program will wind up in the exact same physical location on the new HD as the old one.

To reinstall grub, after swapping your hard drives boot into either a rescue CD or into a live CD distro. From a shell command line, as root, enter the command: grub

This will give you a command line in the grub program. Enter the command: "root (hd0,1)" (with no quotes). Grub will respond telling you what the file system on the partition is.

Then enter the command "setup (hd0)" . This will cause grub to rewrite the MBR with the proper information.

Then enter the command "exit" to exit grub.

Biggen 04-02-2007 10:57 AM

Quote:

Originally Posted by jiml8
Actually, I was just reading up on grub (if that is your bootloader) and I think that probably you'll need to reinstall grub on the new drive after copying it if you use the cp command.

Turns out that the MBR for grub has the absolute physical address of the second stage grub program hardcoded into it. When you use cp to copy the /boot sector from / to the new HD, it seems unlikely that the stage 2 program will wind up in the exact same physical location on the new HD as the old one.

To reinstall grub, after swapping your hard drives boot into either a rescue CD or into a live CD distro. From a shell command line, as root, enter the command: grub

This will give you a command line in the grub program. Enter the command: "root (hd0,1)" (with no quotes). Grub will respond telling you what the file system on the partition is.

Then enter the command "setup (hd0)" . This will cause grub to rewrite the MBR with the proper information.

Then enter the command "exit" to exit grub.

Interesting. Ok, here is where I am now. I am finishing up copying "/" to hdd2. Taking a while but that is normal since its a few gigs in size.

I'm still going to need to use dd correct? As in dd if=/dev/hda of=/dev/hdb bs=446 count=1? Or will re-installing grub override this so this isn't necessary?

w_r_cromwell 04-02-2007 11:05 AM

Your running system can only have one / and etc just as you said except that you can have more than one swap partition. I have never used ore than one swap partition but it is supposed top be okay (something i found while looking up something else). While the new drive is recognized as hdb you can mount the partitions as anything you like as long as you can remember which partition will be used for each of the original partitions and then copy your files there. After you have done all of your copying and taken care of mbr and moved the jumper on the new drive and plugged it into the appropriate cable the system will recognize it as hda and will mount the partitions according to the instructions it copied over from your first drive (now resting on the shelf). The partitions will be mounted on the same mount points that were used for them in the original system. The mount points are determined by the running system and not by what was used when the drive was recognized as hdb.

Bill

PS: Do I feel silly or what! I missed the whole second page of replies before I posted this. I'll leave it here anyway.

jiml8 04-02-2007 12:06 PM

reinstalling grub will write the proper MBR. Hence you won't have to copy the old one using dd.

Biggen 04-02-2007 01:33 PM

Quote:

Originally Posted by jiml8
reinstalling grub will write the proper MBR. Hence you won't have to copy the old one using dd.

Ok, I reinstalled GRUB and everything seemed to go just fine. I Then rebooted and everything looked like it was going well until I got to:

Quote:

fsck.ext3: No such file or directory while trying to open /dev/hdd3
fsck.ext3 /dev/hdd3 failed (status 0x8) Run manually
fsck failed for at least one filesystem (not /)
Please repair manually and reboot
It looks as if something is trying to access a hard drive at hdd. Now when I partioned the drive using Yast2, it automatically added mount points in FSTAB I believe (/mnt/hdd2) and (/mnt/hdd3). I wonder if this is causing the problem. I wonder if removing any entries to hdd from FSTAB would fix this...

Biggen 04-02-2007 01:48 PM

It worked!!!

Jiml8, if you were close by I'd take you out for a beer!! :-)

I had to end up deleting the entries in the fstab as Yast2 added them automatically when it formatted the drive. Went just as easily as you said, re-installing GRUB was a breeze with your instructions.

Thanks a lot man. Now as soon as my other 80GB drive comes in I can setup RAID 1 in the system. I'm going to be doing hardware RAID so it should be farily simple to set that up (I hope anyway!).

Thanks again, bud!

Quakeboy02 04-02-2007 01:52 PM

Quote:

Now as soon as my other 80GB drive comes in I can setup RAID 1 in the system. I'm going to be doing hardware RAID so it should be farily simple to set that up (I hope anyway!).
Are you buying a RAID controller? The one on your motherboard is a sofware raid.

Biggen 04-02-2007 02:06 PM

Quote:

Originally Posted by Quakeboy02
Are you buying a RAID controller? The one on your motherboard is a sofware raid.

I bought one from 3Ware. From all the research I've done, setting up software RAID looked like a total pain in the ass. From what I have read, hardware RAID is much easier as it is transparent to Linux...

jiml8 04-02-2007 02:52 PM

I am in phoenix az and I love beer.

Quakeboy02 04-02-2007 03:07 PM

"I bought one from 3Ware. From all the research I've done, setting up software RAID looked like a total pain in the ass. From what I have read, hardware RAID is much easier as it is transparent to Linux..."

Good man! Good luck and have fun! :)

Biggen 04-02-2007 03:24 PM

Quote:

Originally Posted by jiml8
I am in phoenix az and I love beer.

If you ever get down to Panama City Beach I'll buy you a few. Great advice man!!


All times are GMT -5. The time now is 05:37 PM.