Friday, March 1, 2013

HDD switch - In the Event of an HDD Upgrade

Current HDD - sda
New HDD - sdb

------------
[root@server ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 291G 245G 32G 89% /
/dev/sda1 494M 157M 312M 34% /boot
none 4.0G 0 4.0G 0% /dev/shm
/dev/sdb3 915G 245G 624G 29% /newHDD
/dev/sdb1 494M 157M 312M 34% /newHDD/boot
----------

Please follow the steps below, after the completion of Rsync(ie, / to /newHDD and /boot to /newHDD/boot).

Refer : Clone_HDD

1) Check whether the new partition have boot flag set or not, if not please set it.
Check it by using using 'fdisk -l'

----------
Device Boot Start End Blocks Id System
/dev/sdb1 * 1 65 522081 83 Linux
---------

Here boot flag is already set

If it is not set, you can do this as follows.
[root@server ~]# fdisk /dev/sdb

The number of cylinders for this disk is set to 121575.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): a
Partition number (1-4): 1

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@angel ~]#

2) Install grub on new HDD
[root@server ~]# grub-install --recheck /dev/sdb

Probing devices to guess BIOS drives. This may take a long time.
Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.

(fd0) /dev/fd0
(hd0) /dev/sda
(hd1) /dev/sdb
[root@angel ~]#
check the output of grub install, you can see hd0 is the grub on sda and hd1 is the grub on sdb

3) Edit grub.conf on both new and old HDD, change the vlaue hd0 to hd1
vi /etc/grub.conf
vi /newHDD/boot/grub/grub.conf
#boot=/dev/sda
default=1
timeout=5
splashimage=(hd1,0)/grub/splash.xpm.gz
#hiddenmenu
title CentOS (2.6.9-89.35.1.EL)
root (hd0,0)
kernel /vmlinuz-2.6.9-89.35.1.EL ro root=LABEL=/ netconsole=10000@72.34.60.162/eth0,514@173.214.165.202/00:21:A0:63:38:3F ndev=eth0,00:30:48:8e:f4:fc realip=72.34.60.162/26,eth0,72.34.60.129,0
initrd /initrd-2.6.9-89.35.1.EL.img

title CentOS (2.6.35.10-19)
root (hd1,0)
kernel /vmlinuz-2.6.35.10-19 ro root=LABEL=/ netconsole=10000@72.34.60.162/eth0,514@173.214.165.202/00:21:A0:63:38:3F ndev=eth0,00:30:48:8e:f4:fc realip=72.34.60.162/26,eth0,72.34.60.129,0

4) Label the HDD partitions as follows.
e2label /dev/sda1 /oldBoot
e2label /dev/sda3 /oldRoot
e2label /dev/sdb1 /boot
e2label /dev/sdb3 /
5) Edit fstab on both HDDs, also create the the mount points (/oldHDD/slash & /oldHDD/boot) on second HDD
mkdir -p /newHDD/oldHDD/slash
mkdir /newHDD/oldHDD/boot
vi /newHDD/etc/fstab
vi /etc/fstab

Add below lines to fstab
---------
LABEL=/oldRoot /oldHDD/slash ext3 defaults,usrquota,noatime 1 1
LABEL=/oldBoot /oldHDD/boot ext3 defaults,noatime 1 2
---------

And ensure the the labels '/' '/boot' are entered correctly as follows.

---------
LABEL=/ / ext3 defaults,usrquota,noatime 1 1
LABEL=/boot /boot ext3 defaults,noatime 1 2
--------

6) Change the root password of the box to a simple one and copy /etc/shadow to /newHDD/etc/shadow

7) Confirm whether the server is connected to KVM or not, if not request for it, then reboot the server and monitor the server through KVM.

8) Server will boot from rescue CD, it will prompt several options. You can select the option "boot from second HDD" and then can select the kernel version.

9) Once the server is live from new HDD, check the output of 'df -h' and ensure everything is fine.

[root@server ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sdb3 915G 245G 624G 29% /
/dev/sdb1 494M 157M 312M 34% /boot
none 4.0G 0 4.0G 0% /dev/shm
/dev/sda3 291G 245G 32G 89% /oldHDD/slash
/dev/sda1 494M 157M 312M 34% /oldHDD/boot
[root@angel ~]#

Note: Don't forget to change the server root password back to original

No comments:

Post a Comment