Replacement of a System HDD for CentOS-5.2 to a Smaller One

The HDD used for my home server was getting out of order. Access speed became slow gradually. And finally journaling recovery of ext3 got needed always. A bad sector seemed to be a problem somehow or other. Data was being lost as it was. So I decided to change the disk to a newer one.

However a new disk which has a Parallel ATA Interface owned by me now is 40GB, which is smaller than the current disk 60GB. Because the sizes are different, it isn't useful to copy data simply.

In fact there is a step to copy entire disk data after shortening data partition. But it would have taken so much time to copy whole disk. This time, I did it as below.

  1. At first, boot the system in the rescue mode with the CentOS-5.2 installer. Put an install DVD/CD of CentOS into your PC drive, and then turn on the power. When you see the boot loader prompt, type:
    • linux rescue
    If you see any errors, you can ignore them. Then you will use a shell.
  2. Next, copy a boot partition which locates at the top of disk. The size including the boot loader(446Bytes) and the partition table(66Bytes) is 512Bytes. The copy command is:
    • dd if=/dev/hda of=/dev/hdb bs=512 count=1
  3. After that, make partitions on the new disk with /sbin/fdisk. This fdisk operation rewrites the partition table on the top of disk. If you want to make swap partitions, create them with:
    • /sbin/mkswap [-L <label>] <device>
  4. Next to copy all of files in the old disk, mount two hda1 partitions on old and new disks. For example:
    • mkdir /mnt/old_hda1 || mount -t [<fs_type>|auto] -o ro /dev/hda1 /mnt/old_hda1
    • mkdir /mnt/new_hda1 || mount -t [<fs_type>|auto] -o rw /dev/hdb1 /mnt/new_hda1
  5. Then copy files in the old disk to the new one by cp command with -dpR options:
    • cp -dpR /mnt/old_hda1/* /mnt/new_hda1
  6. Finally shut down the system, remove the old disk, replace the new disk as the default disk, and then start the system. If you have a trouble that you can't reboot with the error which says "GRUB Error", you must rewrite boot sector by re-install grub as follows.
  7. Boot the system in the rescue mode with Linux Install DVD/CD as you did before.
  8. For the grub installation you must mount the new hda1 and create a symbolic link if the rescue system doesn't have grub-install command in /sbin:
    • su
    • mount -t [<fs_type>|auto] -o rw /dev/hda1 /mnt/sysimage
    • mount --bind /dev /mnt/sysimage/dev
    • ln -s /mnt/sysimage/sbin/grub-install /sbin/grub-install
  9. Then, change root directory as:
    • chroot /mnt/sysimage
  10. After that, install grub with grub-install:
    • /sbin/grub-install /dev/hda
    • /sbin/grub # if you can use grub commands properly.
  11. Then, unmount all:
    • exit # for chroot
    • umount /mnt/sysimage/dev
    • umount /mnt/sysimage
    • exit # for su
  12. Finally, reboot the system.

0 件のコメント: