Source: CentOS 5.10 x64, two SATA disks (AHCI), mdraid mirror, no LVM, swap, /boot and / only, text only (no GUI)
Target: VMware ESXi 5.1 virtual machine, LSI SAS, single disk, Intel E1000
# Boot TARGET machine in rescue mode using CentOS 5.10 install ISO image ("linux rescue")
# Start networking and enter IP information when prompted
# Skip searching of existing installs
# You're now in bash shell
# Verify network connectivity to SOURCE server
ping 10.10.53.11
ssh root@10.10.53.11
# Make sure you disconnect that SSH test session so you don't destroy source server
# with following commands...
# Remember you have two ttys available, ALT+F1, ALT+F2
# Create new partitions on TARGET server
# /boot, swap, root
parted -s /dev/sda \
mklabel msdos \
mkpart primary 4MiB 200MiB \
set 1 boot on \
mkpart primary linux-swap 200MiB 6GiB \
mkpart primary 6GiB 100% \
print
# Format new filesystems and swap
mkfs.ext3 -L"boot" /dev/sda1
mkswap /dev/sda2
mkfs.ext3 -L"root" /dev/sda3
# Mount new filesystems
mkdir -p /newsys
mount /dev/sda3 /newsys
mkdir -p /newsys/boot
mount /dev/sda1 /newsys/boot
# On SOURCE: Before running rsync make sure you stop any services that may modify essential files
# If it's critical server and you need to minimize downtime do below rsync commands twice
# First to sync bulk of files and second (with SOURCE services down) to sync changes
# Rsync /boot from SOURCE to TARGET
# Be careful with use of trailing backslashes, must on source, never on target
rsync --progress -aAxXv -e ssh root@10.10.53.11:/boot/ /newsys/boot
# Rsync / from SOURCE to TARGET
# Since rsync is limited to single filesystem (lowercase x parameter)
# we don't need to exclude /proc, /sys, /dev etc.
rsync --progress -aAxXv -e ssh root@10.10.53.11:/ /newsys
# If you need to exclude some junk on old server try something like
# rsync --progress -aAxXv --exclude={"/trash/*","/nonpd/*"} -e ssh root@10.10.53.11:/ /newsys
# Before chrooting on TARGET we need few extra mountpoints
mount -t proc proc /newsys/proc
mount -t sysfs sys /newsys/sys
mount -o bind /dev /newsys/dev
mount -t devpts pts /newsys/dev/pts
# mtab needs some mangling
cat /etc/mtab | grep /newsys | sed -e's|/newsys|/|g' -e's|//|/|g' > /newsys/etc/mtab
# chroot to new system
LANG=C chroot /newsys /bin/bash
# remove old mdraid disk mounts from TARGET /etc/fstab
# edit /etc/fstab so swap, /boot and / device names are correct
#
# old:
# /dev/md1 / ext3 defaults 1 1
#
# new:
# /dev/sda3 / ext3 defaults 1 1
#
# so root is /dev/sda3, /boot is /dev/sda1 and swap /dev/sda2
#
# watch for lines getting wrapped!
#
# fix grub parameters
# edit /etc/grub.conf and change old root=/dev/md1 to root=/dev/sda3
# edit /etc/sysconfig/network-scripts/ifcfg-eth0
# and remove "HWADDR" line entirely
# fix boot sector
/sbin/grub-install --recheck --root-directory=/ /dev/sda
# redo initramdisk
# use proper kernel version (i.e. same as SOURCE used)
# this is to ensure initrd has drivers for our disk controller
# kernel running on rescue mode probably doesn't match with one
# in install we're migrating so no "uname -r" here
/sbin/mkinitrd --force-scsi-probe -f /boot/initrd-2.6.18-371.el5.img 2.6.18-371.el5
# exit chroot and reboot
exit
reboot
# Watch out for IP conflicts if you have both SOURCE and TARGET running!
No comments:
Post a Comment
Got something to say?!