OnApp KVM to KVM with virtio

Preparation

Prepare OnApp’s DB

Get the VM’s TEMPLATE_ID:

SELECT template_id FROM virtual_machines WHERE identifier="$VM_IDENTIFIER";

Create a copy of a template entry $TEMPLATE_ID in the onapp database with virtio enabled and note it’s id ( later referenced as $COPY_TEMPLATE_ID)

CREATE TEMPORARY TABLE tmptemplates SELECT * FROM templates WHERE id="$TEMPLATE_ID";
ALTER TABLE tmptemplates DROP id;
UPDATE tmptemplates SET virtualization='xen,kvm,kvm_virtio';
INSERT INTO templates SELECT 0,tmptemplates.* FROM tmptemplates;
DROP TEMPORARY TABLE templatestmp;
SELECT LAST_INSERT_ID();

Note

A new template should be created for each template without kvm_virtio. The new template is not usable for instantiating new VMs or re-building the current ones. For that to work the template image should be updated to support virtio which is out of scope of this guide.

Alter the VM’s content

Note

Currently only CentOS 5.x is researched but it should be similar for other Linux distributions as well.

CentOS 5.x

  • Replace /dev/hd with /dev/vd in

    • /boot/grub/menu.lst - the root= in the cmdline

    • /etc/fstab - all disk mounts

  • Edit /etc/modprobe.conf - add/replace alias eth0 xvnet to alias eth0 virtio_blk

  • Rebuild /boot/initrd-$(uname -r).img

# backup the initrd image
cp -v /boot/initrd-$(uname -r){,kvm}.img
# create a new initrd image
mkinitrd -v -f --with=virtio_blk --with=virtio_net --with=virtio_balloon \
               --with=virtio_pci --builtin=xenblk \
               /boot/initrd-$(uname -r)virtio.img $(uname -r)
# replace the booting initrd image
cp -v -f /boot/initrd-$(uname -r){virtio,}.img

Update the VM’s metadata in the OnApp’s DB

Replace the VM’s template with the new one:

UPDATE virtual_machines SET template_id="$COPY_TEMPLATE_ID"
                        WHERE identifier="$VM_IDENTIFIER";

Finalize

Reboot the VM via the OnApp Control Panel.