Sunday, July 12, 2009

Root hard disk upgrade (SATA)

Recipe to upgrade/clone an existing SATA disk. In my case I bought a new, larger SATA disk. All commands are specific for RHEL5/CentOS5.

* First, backup all files from your old disk to a safe place.

* Your original SATA disk should be on port A => /dev/sda. Attach the new disk to SATA port B and boot. If should come up as /dev/sdb.

* Now create partitions on the second disk to mirror what you have on the old disk.
# fdisk -l /dev/sda => Get information. In my case:
Cylinders 1 - 13: sda1 (/boot)
14 - 267: sda2 (swap)
268 - end: sda3 (/)
# fdisk /dev/sdb
a => Use this to make /dev/sdb1 bootable.
d => delete a partition if you made an error
n => Create new partition.
p => print list
t => Change a partition's ID..use this to create a swap partition on /dev/sdb2
w => write partition table to disk.
q => quit without saving changes

* Now create FS/swap on your new partitions:
# mkfs -V -t ext3 -c /dev/sdb1
# mkfs -V -t ext3 -c /dev/sdb3
# mkswap /dev/sdb2

* Mount your new partitions:
# mkdir /mnt/disk2_boot; mkdir /mnt/disk2_root
# mount /dev/sdb1 /mnt/disk2_boot
# mount /dev/sdb3 /mnt/disk2_root

* Dump/restore data from old to new. You may want to get to single-user to this.
# dump 0f - /boot| (cd /mnt/disk2_boot; restore rf -)
# dump 0f - /| (cd /mnt/disk2_root; restore rf -)

* Create labels on the new partitions:
# e2label /dev/sdb1 /boot2 (boot)
# e2label /dev/sdb3 /2 (root)

* Fsck both partitions, you just made a bunch of changes on them:
# umount /mnt/disk2_boot; umount /mnt/disk2_root
# fsck /dev/sdb1 ; fsck /dev/sdb3
# mount /dev/sdb1 /mnt/disk2_boot
# mount /dev/sdb3 /mnt/disk2_root

* Edit conf files with new labels
# /mnt/disk2_root/etc/fstab. Replace labels for / and /boot. Changed swap to say /dev/sda2 instead of the swap label..this probably was not necessary.
# /mnt/disk2_boot/grub/grub.conf. Replace root label from /1 to /2

* Create dev files, check /proc:
# /dev/MAKEDEV -d /mnt/disk2_root/dev -v
Making devices is pretty involved and manual. Check your /dev directory to ensure you have at least whats there. Options to remember:
(*) "-x" makes the exact device, ie ppp creates ppp and ppp0 etc.
(*) "generic" creates a bunch of devices which may be useful to you.
(*) Or you could write a script that says:
/dev/MAKEDEV -d /mnt/disk2_root/dev -v -x file for every file in /dev
# ls -l /mnt/disk2_root/proc (should be empty).

* Copy over the MBR
dd if=/dev/sda of=/dev/sdb bs=446 count=1
If you change 446 to 512, you copy over the whole block, which includes the partition table you just created. You really don't want that, you have a new disk now.

* Shutdown, connect your new disk to SATA port A. This tells the system to boot from the new disk. Leave your old root disk unconnected, if there's a problem you don't want it to be trashed.

* When you power back up, you may see an error that SATA port B is unavailable. Ignore it. Your system is looking at the partition table in your MBR and guessing there should be another disk.

* On bootup, check to make sure everything is OK. If so, power down again, connect the old disk to SATA port B, and power back up. The previous error about SATA port B being unavailable should go away. When you're back up, your old disk is visible as /dev/sdb (because its now on port B). Mount your old root partition:
# mkdir /oldroot
# mount /dev/sdb3 /oldroot

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home