How to create and install a KVM guest

Feb 12, 2020

Download CentOS 7

# mkdir /kvm-pool/iso
# cd /kvm-pool/iso
# wget http://ftp.upcnet.ro/distros/centos/7.7.1908/isos/x86_64/CentOS-7-x86_64-DVD-1908.iso

Create the virtual machine with a local ISO image

Run osinfo-query os command to find out what to use for --os-variant

# virt-install --name vm01 \
  --ram 1024 \
  --vcpus=1 \
  --os-variant=centos7.0 \
  --cdrom=/kvm-pool/iso/CentOS-7-x86_64-DVD-1908.iso \
  --graphics vnc \
  --disk size=10

Create the virtual machine with a remote kickstart file

# virt-install --name vm02 \
  --ram 2048 \ 
  --vcpus=1 \
  --os-variant=centos7.0 \
  --location=http://ftp.upcnet.ro/distros/centos/7/os/x86_64 \
  --graphics vnc \
  --disk size=10 \
  --extra-args "ks=http://192.168.1.22/repo/kickstart/kvm/vm02.cfg"

Create the virtual machine with a local kickstart and ISO image

# virt-install --name vm02 \
  --ram 2048 \
  --vcpus=1 \
  --os-variant=centos7.0 \
  --location=/kvm-pool/iso/CentOS-7-x86_64-DVD-1908.iso \
  --graphics vnc \
  --disk size=10 \
  --initrd=/kvm-pool/ks/vm02.cfg
  --extra-args "ks=file:/vm02.cfg"
Kickstart file
# mkdir /kvm-pool/ks
# vi /kvm-pool/ks/vm02.cfg
#version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
# Use text install
text
# Run the Setup Agent on first boot
firstboot --enable
ignoredisk --only-use=vda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
lang en_US.UTF-8

# Network information
network  --bootproto=static --device=eth0 --gateway=192.168.1.1 --ip=192.168.1.41 --nameserver=192.168.1.1 --netmask=255.255.255.0 --noipv6 --activate
network  --hostname=vm02

# Root password
rootpw --iscrypted $6$8JIXoeyEi1YdMCtv$8MZ3ccZMjl4Bmf/uKIYBvlHJFOHBgVJja6ydDn4E5rUvjYcvz6Q7ZTa0nOWTqDbCgTcKhnmY3FKWlqzyEXOKS1
# System services
services --disabled="chronyd"
# System timezone
timezone Europe/Bucharest --isUtc --nontp
# System bootloader configuration
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=vda
autopart --type=lvm
# Partition clearing information
clearpart --none --initlabel

%packages
@^minimal
@core
kexec-tools

%end

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

%end

%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end

Install the OS via VNC

Find out the VNC port
# virsh dumpxml vm01 | grep vnc
    <graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1'>
Forward the port on Windows 10
C:\Users\Daniel>ssh root@192.168.1.35 -L 5900:127.0.0.1:5900

Downnload VNC Viewer and connect to 127:0.0.1:5900

Install the OS via virt-manager

Follow this tutorial

virtualizationlinuxkvm

Booting from ISO file on KVM guest

How to Install KVM on RHEL 7

comments powered by Disqus