Skip to main content

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=0.0.0.0 --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 \
--import
--graphics vnc,listen=0.0.0.0 --noautoconsole \
--os-variant oracle linux7 --accelerate \
--network=bridge:br0,model=virtio \
--hvm


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=0.0.0.0 --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=192.168.1.2::192.168.1.1:255.255.255.0: \

test.example.com:eth0:none" (Bridged network with a static IP address

--network=none (no network)


Kickstart file example:
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use CDROM installation media
cdrom
# Use graphical install
graphical
# 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 --ntpservers=0.centos.pool.ntp.org,1.centos.pool.ntp.org,2.centos.pool.ntp.org,3.centos.pool.ntp.org
# 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

%packages

@^minimal
@core
chrony

%end

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

%end


Troubleshooting:

"error: internal error: Failed to probe QEMU binary with QMP: Could not acquire pidfile: No such file or directory" :   Solution:  /var  folder out of space 



Comments

Popular posts from this blog

Salt -- cheat sheet

      The Salt system is a Python-based open-source remote execution framework for configuration management, automation, provisioning and orchestration.  A basic Salt implementation consists of a Salt master managing one or more Salt minions.

Cheat Sheet

Bash: echo $? - exit status of last command (0 no error) ' - Single quote removes meaning special meaning of special character. find /qwe -type f -iname *.js -exec cp --parents -t /tmp/ {} + -- find all js files and copy with parent directory ystemctl set-default graphical.target (ls -l /lib/systemd/system/runlevel*) -- set runlevel echo <password> | sudo -S for i in t@01 st@02 ba@sta03;do ssh -o RequestTTY=true $i "sudo -l";done -- allow tty present VIM: :r! sed -n '16,812 p' < input_file.txt -- copy line range from input_file :1,10d -- delete line from 1 to 10 :se nu -- show line numbers Apache: Redirection in Apache (By default, the Redirect directive establishes a 302, or temporary, redirect.): URL:https://www.digitalocean.com/community/tutorials/how-to-create-temporary-and-permanent-redirects-with-apache-and-nginx <VirtualHost *:80> ServerName www.domain1.com Redirect 301 /oldlocation http://www.domain2.com/newlocation </VirtualHo

Euro trip. Chapter1: Bucovice-Prague-Nuremberg-Leipzig-Dresden

    Begin to write something every time is complicated for me. Any way i should start. So this trip was somehow unplanned. Where to go, stay ... everything planned on way.    Trip started 2nd of July from Bucovice to Prague. Made reservation on "Hotel Globus" for one night. After check-inn we went to centre walk, see landmarks  of Prague. Additional we have a lunch at asian cafe.     3rd July. Next our plan was drove from Prague to Munich stay one night in camp hostel, visit Munich Zoo. But plans changed on way and we decided drove first Nuremberg to see my friend. Made reservation at "Azimut Hotel". As we arrived earlier check-inn was after 3PM, parked car and we decided not to waste time go and see Nuremberg. We have a lunch some soup and german sausage. And also for 30 euros we took city tour by bus about 2 hour. We saw almost whole city with information (recommended). Evening we meet my friend have a lunch thanks special thanks Fagani. Before driving to Leipzig