Service Hosting - KVM documentation

Host System Requirements:

Minimum host system requirements

  • 6 GB free disk space.
  • 2 GB RAM.

Recommended system requirements
One core or thread for each virtualized CPU and one for the host.

  • 2 GB of RAM, plus additional RAM for virtual machines.
  • 6 GB disk space for the host, plus the required disk space for the virtual machine(s).

KVM Hypervisor Requirements:

  • an Intel processor with the Intel VT-x and Intel 64 virtualization extensions for x86-based systems; or
  • an AMD processor with the AMD-V and the AMD64 virtualization extensions.

Installing the Virtualization Packages:

To use virtualization on OL7, at minimum, you need to install the following packages:

# yum install qemu-kvm libvirt

  • qemu-kvm: This package provides the user-level KVM emulator and facilitates communication between hosts and guest virtual machines.
  • qemu-img: This package provides disk management for guest virtual machines.

The qemu-img package is installed as a dependency of the qemu-kvm package.

  • libvirt: This package provides the server and host-side libraries for interacting with hypervisors and host systems, and the libvirtd daemon that handles the library calls, manages virtual machines, and controls the hypervisor.

Several additional virtualization management packages are also available and are recommended when using virtualization:

# yum install virt-install libvirt-python virt-manager virt-install libvirt-client

  • virt-install: This package provides the virt-install command for creating virtual machines from the command line.
  • libvirt-python: This package contains a module that permits applications written in the Python programming language to use the interface supplied by the libvirt API.
  • virt-manager: This package provides the virt-manager tool, also known as Virtual Machine Manager. This is a graphical tool for administering virtual machines. It uses the libvirt-client library as the management API.
  • libvirt-client: This package provides the client-side APIs and libraries for accessing libvirt servers. The libvirt-client package includes the virsh command-line tool to manage and control virtual machines and hypervisors from the command line or a special virtualization shell.

Creating a VM:

After you have installed the virtualization packages on your OL 7 host system, you can create virtual machines and install guest operating systems using the virt-manager interface. Alternatively, you can use the virt-install command-line utility by a list of parameters or with a script.

Creating Guests with virt-install from ISO:

 #virt-install --connect qemu:///system \
-n test-vm -r 4096 --vcpus=2 \
--disk /data/vm/test-vm.qcow2,bus=virtio \
--graphics vnc,listen= --noautoconsole \
--os-variant oracle linux7 --accelerate \
--network=bridge:br0,model=virtio \
--hvm \
--cdrom /data/iso/OracleLinux-R7-U8-Server-x86_64-dvd.iso

Creating qcow2 disk img for VM :

 #qemu-img create -f qcow2 /data/vm/test-vm.qcow2 500G

Attaching new 'qcow2 or img' to running vm: 

#virsh attach-disk test-vm --source /data/vm/test-vm-d.qcow2 --target vdb --driver qemu --targetbus virtio --persistent --live 
Importing a virtual machine image: 

#virt-install --connect qemu:///system \
-n test-vm -r 4096 --vcpus=2 \
--disk /data/vm/test-vm.qcow2,bus=virtio \
--graphics vnc,listen= --noautoconsole \
--os-variant oracle linux7 --accelerate \
--network=bridge:br0,model=virtio \

Installing a virtual machine with Kickstart: 

#virt-install --connect qemu:///system \
-n test-vm -r 4096 --vcpus=2 \
--disk /data/vm/test-vm.qcow2,bus=virtio \
--graphics vnc,listen= --noautoconsole \
--os-variant oracle linux7 --accelerate \
--network=bridge:br0,model=virtio \
--hvm \
--cdrom /data/iso/OracleLinux-R7-U8-Server-x86_64-dvd.iso \
--initrd-inject /path/to/ks.cfg \
--extra-args="ks=file:/ks.cfg console=tty0 console=ttyS0,115200n8"

Conf guest VM network during guest creation:

--network default (NAT)

--network br0 (Bridged netwok with DHCP)

--network br0 \

--extra-args "ip= \" (Bridged network with a static IP address

--network=none (no network)

Kickstart file example:
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
# Use graphical install
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=vda,vdb
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network --bootproto=static --device=eth0 --gateway=x.x.x.x --ip=x.x.x.x
7 --nameserver=x.x.x.x --netmask=x.x.x.x --noipv6 --activate
network --hostname=test-vm

# Root password
rootpw --iscrypted $6$3YGgU2zJuOLiQCZE$ptIpyc/ge5nSS8L3o6y3flpqFn8Xz/KkTmfheLmv5URoBBFgpCxRFp8.D/0qpnYyZioxEp.1eFZ6Z3lDriHbK1
# System services
services --enabled="chronyd"
# System timezone
timezone America/New_York --isUtc,,,
# System bootloader configuration
bootloader --location=mbr --boot-drive=vda
# Partition clearing information
clearpart --all --initlabel --drives=vda
# Disk partitioning information
part pv.520 --fstype="lvmpv" --ondisk=vda --size=510975
part /boot --fstype="xfs" --ondisk=vda --size=1024
volgroup centos_restore-test --pesize=4096 pv.520
logvol /home --fstype="xfs" --size=4768 --name=home --vgname=centos_restore-test
logvol / --fstype="xfs" --size=493795 --name=root --vgname=centos_restore-test
logvol swap --fstype="swap" --size=12397 --name=swap --vgname=centos_restore-test




%addon com_redhat_kdump --disable --reserve-mb='auto'



Popular posts from this blog

Docker basic commands (podman)

Install Cisco AnyConnect on Ubuntu

First week in new Job