How to create and install a KVM guest

Download CentOS 7

1
2
3
# 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

1
2
3
4
5
6
7
# 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

1
2
3
4
5
6
7
8
# 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

1
2
3
4
5
6
7
8
9
# 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
1
2
# mkdir /kvm-pool/ks
# vi /kvm-pool/ks/vm02.cfg
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#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
1
2
# virsh dumpxml vm01 | grep vnc
    <graphics type='vnc' port='5900' autoport='yes' listen='127.0.0.1'>
Forward the port on Windows 10
1
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