From Dedicated Server to KVM Virtualized Instance
Recently we’ve had a few clients that have wanted to downsize from a dedicated server to a Private Virtual Server running a virtualized instance. In the past, that has been a very time consuming process. While it would probably be better to upgrade these clients to 64bit and take advantage of a fresh OS load, sometimes there are issues that preclude this. One potential problem is not having a recent enough kernel to work with KVM if you are using a kernel that was built specifically for your setup.
What follows is a general recipe for migrating these machines. Most of the tasks are ‘hurry up and wait’ and the actual work involved with the move is typically waiting for data to be moved. This guide starts from bare metal to migrating the first machine.
On the KVM box
- install Linux
- install kvm, virt-tools, and any base utilities (our minimal install includes libvirt-bin qemu-kvm virtinst rsync bridge-utils rsync cgroup-bin nvi)
- Download the .iso for your initial build
- Determine disk size for each instance
- Install base image to COW file or LVM partition. From this, you’ll clone it to your new instances. Make sure the COW file is created with the same size as the resulting image, or, you’ll need to resize via LVM and your underlying filesystem.
- pvcreate /dev/sda2 (or /dev/md1 if you use software rather than hardware raid)
- vgcreate -s 16M vg0 /dev/sda2
- lvcreate -L 80G -n c1 vg0
- virt-clone –original base_image –name newvirtualmachine –file=/dev/vg0/c1
On the machine being moved
- Install grub2 (if not already running grub2)
- Edit /etc/default/grub and disable UUID
- Install new kernel
- Paths changing? /etc/fstab should be modified or needs to be done via vnc. If done via VNC, note that the machine may come up in singleuser mode as it will fail the fsck on devices that may not be present.
- rsync (logs needed?)
Ready for the switch
On dedicated server
- secondary network helpful, ipv6 on primary interface works
- ifconfig primary interface to temporary IP, add default route
- restart firewall (if pinned to primary ethernet)
- log out, log back in using temporary IP
- remove ipv6
On KVM Machine
- virsh start newinstancename
- connect via vnc
- clear arp on your routers
- dpkg-reconfigure grub-pc (sometimes, grub is not recognized on QEMU hard drive)
- verify swap (double check /etc/fstab)
after grub is reinstalled, reboot just to ensure machine comes up with no issues
KVM Shell Scripts used when we migrated a number of machines.
Kernel Config Notes for KVM
If you are building your own kernels, here are some notes.
Make sure the following are installed in your KVM kernel
- High Res Timers (required for most of the virtualization options)
- CPU Task/Time accounting (if desired)
Make sure the following are installed in your guest kernel
Remember that your guest kernel is running on the underlying hardware of your KVM machine. The guest kernel should have the CPU type set based on the KVM’s CPU type to take advantage of any hardware optimizations the CPU may have.