[CentOS] Replacing a hard drive

John R Pierce pierce at hogranch.com
Wed Mar 14 16:17:54 UTC 2007


Bowie Bailey wrote:
> I have a CentOS 4.4 system where all of the main filesystems are on a
> single hard drive.  This drive is starting to give some errors, so I got
> a new (larger) drive to replace it with.  What is the easiest way to
> copy my filesystems over to the new drive?
>
> I considered using dd, but I lose the extra capacity of the new drive
> that way.
>
> I tried using SystemImager, but it is giving me some errors.
>
> I think the easiest way may be to boot from the LiveCD, recreate the
> partitions, copy the info with rsync and then fix the boot partition and
> grub.  Any tips or pointers to a good how-to?
>   

I'm assuming you're using straight ext3 without LVM or raid....

I'd probably boot the regular CD into rescue mode, without mounting the 
file systems, then partition the new disk to suit (making each partition 
at least as large as the original drive, and in the same order, then run 
something like....

this assumes new drive is hda, old drive is hdb

mkdir /mnt/src /mnt/dst
for f in 1 2 5 6; do
    mount /dev/hdb$f /mnt/src
    mount /dev/hda$f /mnt/dst
    dump 0f - /mnt/src | (cd /mnt/dst; restore rf - )
    umount /mnt/dst /mnt/src
end
mkswap /dev/hda3
mount /dev/hda2 /mnt/dst && mount /dev/hda1 /mnt/dst/boot
chroot /mnt/dst
grub-install /dev/hda
^z
umount /mnt/dsk/boot; umount /mnt/dsk

adjust file and device names to suit.     dump to restore like that 
creates a very accurate copy of a file system, complete with special 
files, links, ACLs, permissions, etc, etc intact.

now, swap the new drive


(where 1, 2, 5, 6 are your file system partitions, leaving out your swap 
which I'm guessing is hda3)



More information about the CentOS mailing list