Tuesday, February 1, 2011

Installing KVM guest using virt-install tool

These has been tested on Centos 5.5 64bit host.

1. KVM Guest installation with virt-install using default networking and storage image created automatically.

virt-install \
     --name ubuntu_server \
     --ram 256 \
     --disk path=/var/lib/libvirt/images/ubuntu_server.img,size=5 \
     --network network:default \
     --accelerate \
     --vnc \
     --cdrom FullPathTo.iso

2. KVM Guest installation with virt-install using bridging interface, and storage image file created with qemu-img

For this its assume that bridge 'br0' interface is already configured on host, refer to how to create bridge interface on Redhat/Centos.

a) To create storage image
# qemu-img create -f qcow2 /var/lib/libvirt/images/ubuntu_server.img 10G

b)
virt-install \
     --name ubuntu_server \
     --ram 256 \
     --os-type='linux' \
     --disk path=/var/lib/libvirt/images/ubuntu_server.img \
     --network bridge:br0 \
     --accelerate \
     --vnc \
     --cdrom FullPathTo.iso

3. Install a KVM in text mode from remote http server, storage image created with qemu-img. Check (a) for creating storage image

virt-install \
              --name centos2 \
              --ram 256 \
              --os-type='linux' \
              --disk path=/var/lib/libvirt/images/centos2.img \
              --network network:default \
              --nographics \
              --location http://mirror.switch.ch/ftp/mirror/centos/5.5/os/x86_64/ \
              --hvm \
              --extra-args console=ttyS0

Note: --extra-args will only work when performing a guest install from "--location", when doing install from local ISO image it should be mounted somewhere

Tips for completing the installing of guest operating system

1) To Connect from remote PC/laptop

1. install virt-viewer on your local pc

2. Upload your ssh public key to KVM host /root/.ssh/authorized_keys (For this you should allow root login in /etc/ssh/sshd_config)

3. Run the following by replace KVMHostIP with KVM host IP address and vmName with the KVM virtual machine name.

$ virt-viewer -c qemu+ssh://root@KVMHostIP/system vmName

To connect KVMs from the KVM Host

To connect using the virt-viewer tool, run the following command:
# virt-viewer vmName

To connect using the virt-manager tool, run the following command:
# virt-manager vmName

Auto start KVM VMs on Host system boot

The following command will mark the VM for auto start on system reboot

# virsh autostart vmName

1 comment:

  1. Nice tutorial for installing KVM. Thanks for providing steps of installation.

    ReplyDelete