Home/Blog/KVM Installation Guide | Linux Virtualization Setup
Virtualization

KVM Installation Guide | Linux Virtualization Setup

Master KVM virtualization with this comprehensive step-by-step installation and configuration guide for enterprise environments.

KVM Installation Guide | Linux Virtualization Setup

This comprehensive guide will walk you through setting up a production-ready two-node KVM farm using OpenFiler for storage and Fedora Core 14 as your KVM hosts. By the end of this tutorial, you’ll master KVM installation, virtual machine creation, and live migration between hosts—all using the essential KVM toolset.

Install Essential Components

Begin by installing the core virtualization components. First, identify and install the appropriate NFS client for your system architecture:

yum list | grep nfs

Install the NFS client for your architecture (example for i686):

yum install nfs-utils.i686

Next, install the essential virtualization components with a single command:

yum install virt-manager virt-viewer libvirt qemu-kvm
  • virt-manager: Virtual machine management utility
  • virt-viewer: Console access for virtual machines
  • libvirt: Core hypervisor infrastructure
  • qemu-kvm: KVM enablement package

Best Practice: Restart your system after installation to ensure all components load properly and hardware virtualization features are activated.

Configure DNS and Network Settings

Proper DNS configuration is critical for KVM cluster functionality. If you lack a dedicated DNS server, configure host file entries manually:

gedit /etc/hosts

Add entries for each KVM host using this format:

192.168.1.10    kvm-host1.local
192.168.1.11    kvm-host2.local

Setup NFS Shared Storage

Create a dedicated mount point for shared VM storage and configure the NFS share:

mkdir /var/lib/libvirt/images/kvmshared
mount -t nfs 10.0.0.28:/mnt/volgroup1/volume1/Share1/ /var/lib/libvirt/images/kvmshared

Make the mount persistent by adding it to /etc/fstab:

echo "10.0.0.28:/mnt/volgroup1/volume1/share1/ /var/lib/libvirt/images/kvmshared nfs defaults 0 0" >> /etc/fstab

Set proper permissions and configure SELinux for NFS usage:

chmod 755 -R /var/lib/libvirt/images
setsebool -P virt_use_nfs on

Configure Firewall for Live Migration

Open essential ports for remote management and live migration functionality:

  • Port 22: SSH access for remote management
  • Ports 49152-49261: Live migration traffic

Configure firewall rules using the system firewall utility:

/usr/bin/system-config-firewall

Add TCP port range 49152-49261 for migration traffic and apply the configuration.

Configure the Hypervisor

Start the libvirt daemon and initialize the virtual machine manager:

service libvirtd start
virt-manager

Update the default storage pool to use your NFS shared storage:

gedit /etc/libvirt/storage/default.xml

Change the path from /var/lib/libvirt/images to /var/lib/libvirt/images/kvmshared and restart the hypervisor:

service libvirtd restart

Creating Virtual Machines

Follow these steps to create your first virtual machine using virt-manager:

  1. Launch virt-manager and click the “New” button
  2. Enter a descriptive name for your virtual machine
  3. Select “Local Media (ISO Image or CDROM)” as the installation source
  4. Browse and select your ISO file from the shared storage location
  5. Allocate appropriate memory and CPU resources
  6. Configure virtual disk size (consider unchecking “Allocate Entire Disk Now” for space efficiency)
  7. Review settings and click “Finish” to create the VM

Pro Tip: To release mouse and keyboard control from a VM, press Ctrl+Alt on the left side of your keyboard.

Live Migration Setup

Enable seamless VM migration between hosts by registering remote systems in virt-manager:

Register Remote Hosts

  1. Open virt-manager and go to File → Add Connection
  2. Check “Connect to remote Host”
  3. Select “QEMU/KVM” from the hypervisor dropdown
  4. Choose “SSH” as the connection method
  5. Set username to “root”
  6. Enter the remote hostname
  7. Accept SSH certificates and provide credentials

Perform Migration

To migrate a running VM:

  1. Right-click the virtual machine
  2. Select “Migrate”
  3. Choose the destination host from the dropdown
  4. Click “Migrate” to begin the process

Important: After migration, delete the VM entry from the original host (but DO NOT delete storage files) to prevent conflicts with future migrations.

Troubleshooting and Useful Commands

Keep these essential commands and troubleshooting tips handy:

Fix Migration Issues

iptables -I INPUT -j ACCEPT

List Running VMs

virsh -c qemu:///system list

Direct VM Boot

qemu-kvm -m 1024 -cdrom /path/to/image.iso -boot d

Configuration files are stored in /etc/libvirt and logs can be found in /var/log/libvirt.

Frequently Asked Questions

Find answers to common questions

To optimize KVM performance on Fedora, particularly concerning CPU and memory management, several key configurations and best practices must be implemented. First, ensure that your host system supports hardware virtualization (Intel VT-x or AMD-V) and that it is enabled in the BIOS. This can significantly enhance KVM performance by allowing the hypervisor to run virtual machines more efficiently.

Next, consider configuring CPU pinning, which binds virtual CPUs (vCPUs) of your virtual machines to specific physical CPUs on the host. This reduces context switching and can enhance performance, especially for CPU-intensive workloads. You can achieve this by editing the XML configuration of your VM using virsh edit <vm-name> and setting the <vcpu> section to specify the CPU cores allocated to the VM.

Memory management is also crucial. It’s advisable to use huge pages, which can improve memory performance by reducing the overhead associated with managing large amounts of memory. You can enable huge pages in Fedora by adding the following line to your /etc/sysctl.conf:

mmap_min_addr = 65536

Then, allocate huge pages by adding the following to your /etc/default/grub:

GRUB_CMDLINE_LINUX="... hugepages=4G"

After updating the grub configuration, run grub2-mkconfig -o /boot/grub2/grub.cfg and reboot your system.

Additionally, consider configuring the balloon driver (virtio-balloon) for dynamic memory management in your VMs. This allows the hypervisor to adjust the memory allocated to a VM based on demand, which can prevent resource starvation and improve overall system performance.

Finally, regularly monitor your KVM environment using tools like virt-top or htop to track resource usage and identify any bottlenecks in CPU or memory allocation. By applying these optimizations, you can significantly enhance the performance of your KVM host and the virtual machines running on it.

Need Expert IT & Security Guidance?

Our team is ready to help protect and optimize your business technology infrastructure.