Jump to content

Changing a Hard Drive


Ixthusdan
 Share

Recommended Posts

Since I have messed this up often when changing drives, I wrote out this procedure and thought it might be useful. This best applies to situations where one is cloning data, same size partition to same size partition. If the partition sizes change, there are other tools that make it easier. dd is quick and easy for cloning. Also, be sure to follow the instructions, as dd can render a drive blank if you mistakenly clone an empty partition over a data partition. Of course, the result would be 2 empty partitions!

 

1. Install the new drive into the system. (It does not matter if this is ide or sata.)

 

2. Boot Linux and locate the drive. While you do not have to, I prefer setting up the partitions and formatting ahead of time. Do not name the partitions; simply format them in your favorite fs. Copying the information is done from a console.

For an entire drive, type

 dd if=/dev/source bs=32256 of=/dev/destination

where the source and destination are expressed as sda, sdb, hda, hdb, etc. This can take some time. I prefer to copy partition information so I can see where I am. Besides, copying swap is a waste of time. So do

 dd if=/dev/sda5 bs=32256 of=/dev/sdb4

where the content of the 5th partition on sda is copied to the 4th partition of sdb. With this nomenclature, the data of any partition can be targeted to any other partition.

 

3. After completing all copying, DO NOT REBOOT YET. First, edit the content of the new /etc/fstab to reflect the new location of the partitions. If you are replacing a drive in the exact same place in the system, this step is not necessary. Otherwise, make your edits. For example, in the above copy, I would edit the function of sda5 to become sdb4 in the new drive. If you forget this step, you'll be making edits with a live distro!

 

4. Edit the new GRUB/Lilo so that the system will boot correctly. Remember, GRUB identifies its drives and partitions starting from 0, not 1. So if sda was the first drive in the system, it would be identified in GRUB as hd0. But if you are moving everything to sdb, the second drive in the system, then GRUB sees it as hd1. The partitions are also numbered from 0, not 1. So the above sdb4 would be labled in GRUB (hd1,3) if sdb is the second drive in the system.

 

5. Now shut down and arrange your hardware as you planned. When you boot back up, all should be well.

Link to comment
Share on other sites

I believe using dd causes issues if your new partitions are a different size than your old. If I remember correctly, I once attempted to use dd like this to copy from a smaller partition to a larger, and when i booted into the new system the partitions registered as the size of the previous smaller ones, not of the new ones I had created. If the sizes of the partitions are different, I think it may be a better idea to use a cp: cp -pdR /source /destination. This may also cause issues when doing an entire drive, if they are different sizes - I've never tested that.

 

See this thread

Link to comment
Share on other sites

I think you may be right; I just used the same size partitions. My work has generally been more akin to cloning a drive, which would entail the same size partitions/data storage. dd will copy the data to a smaller place, but it is compressed, which introduces new issues with reading it only after decompressing the data. I'll add a note to the above.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...