
Introduction
This guide provides a comprehensive walkthrough for installing and configuring KVM on Fedora 40, utilizing the 5W1H approach (What, Who, Where, When, Why, How), followed by an analysis of the consequences and a conclusion.
Overview
What
KVM (Kernel-based Virtual Machine) is a virtualization solution for the Linux kernel that turns it into a hypervisor. In this guide, we will cover the steps to install KVM on Fedora 40.
Who
This guide is intended for system administrators, developers, and Linux enthusiasts who want to set up virtualization on their Fedora 40 systems.
Where
The installation process should be performed on a Fedora 40 system with administrative privileges.
When
You should consider installing KVM when you need to create and manage virtual machines on your Fedora 40 system. It is also useful for development, testing, and running multiple operating systems simultaneously.
Why
The advantages and disadvantages of using KVM for virtualization on Fedora 40 are summarized in the table below.
Pros | Cons |
---|---|
Open-source and free to use | Requires hardware virtualization support (VT-x/AMD-V) |
High performance and efficiency | Can be complex to set up and configure |
Integration with the Linux kernel | Limited support for non-Linux operating systems |
Scalable and flexible | Potential compatibility issues with some hardware |
How
Follow these steps to install and configure KVM on Fedora 40:
Step 1 | Update your Fedora 40 system: sudo dnf update |
Step 2 | Install KVM and related packages: sudo dnf install @virtualization |
Step 3 | Enable and start the libvirtd service: sudo systemctl enable --now libvirtd |
Step 4 | Verify KVM installation: virsh list --all |
Step 5 | Create a virtual machine using virt-manager or virsh commands. |
Consequences
The successful installation and configuration of KVM on Fedora 40 will allow you to create and manage multiple virtual machines efficiently. However, improper setup or configuration might lead to performance issues or system instability.
Positive |
|
Negative |
|
Conclusion
Installing KVM on Fedora 40 provides a powerful and flexible virtualization solution. By following the outlined steps and understanding the pros and cons, you can effectively manage virtual environments tailored to your needs.
Install KVM
This is the Virtualization configuration with KVM ( Kernel-based Virtual Machine ) + QEMU. It requires that the CPU on your computer that has a feature Intel VT or AMD-V.
Step [1]Install required packages.
[root@bizantum ~]# dnf -y install qemu-kvm libvirt virt-install
# confirm modules are loaded
[root@bizantum ~]# lsmod | grep kvm
kvm_intel 425984 0
kvm 1404928 1 kvm_intel
irqbypass 12288 1 kvm
[root@bizantum ~]# systemctl enable --now libvirtd
Step [2]Configure Bridge networking for KVM virtual machines. Replace the interface name [enp1s0] for your own environment.
# add bridge [br0]
[root@bizantum ~]# nmcli connection add type bridge autoconnect yes con-name br0 ifname br0
Connection 'br0' (d5bdefd2-3761-48fb-84ff-3746c2f32e0b) successfully added.
# set IP address for [br0]
[root@bizantum ~]# nmcli connection modify br0 ipv4.addresses 10.0.0.30/24 ipv4.method manual
# set Gateway for [br0]
[root@bizantum ~]# nmcli connection modify br0 ipv4.gateway 10.0.0.1
# set DNS for [br0]
[root@bizantum ~]# nmcli connection modify br0 ipv4.dns 10.0.0.10
# set DNS search base for [br0]
[root@bizantum ~]# nmcli connection modify br0 ipv4.dns-search bizantum.lab
# remove the current interface
[root@bizantum ~]# nmcli connection del enp1s0
# add the removed interface again as a member of [br0]
[root@bizantum ~]# nmcli connection add type bridge-slave autoconnect yes con-name enp1s0 ifname enp1s0 master br0
# restart
[root@bizantum ~]# reboot
[root@bizantum ~]# ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
link/ether 52:54:00:f8:e3:e0 brd ff:ff:ff:ff:ff:ff
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 52:54:00:f8:e3:e0 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.30/24 brd 10.0.0.255 scope global noprefixroute br0
valid_lft forever preferred_lft forever
inet6 fe80::8129:a2e9:7138:c5c7/64 scope link
Create Virtual Machines
Install GuestOS and Create a Virtual Machine. This example shows to create VM with installing Fedora 40.
Step [1] On this example, Download an ISO file of Fedora on a directory first and Install GuestOS from the ISO on the text mode. It's OK on the console or remote connection via SSH and so on. Furthermore, Virtual Machine images are placed at [/var/lib/libvirt/images] by default as a Storage Pool, but this example shows to create and use a new Storage Pool.(use any place you like)
# create a Storage Pool directory
[root@bizantum ~]# mkdir -p /var/kvm/images
[root@bizantum ~]# virt-install \
--name fedora40 \
--ram 4096 \
--disk path=/var/kvm/images/fedora40.img,size=20 \
--vcpus 2 \
--os-variant fedora39 \
--network bridge=br0 \
--graphics none \
--console pty,target_type=serial \
--location /home/Fedora-Server-dvd-x86_64-40-1.14.iso \
--extra-args 'console=ttyS0,115200n8'
Starting install... # installation starts
.....
.....
# after that, installation proceeds with the common procedure
The example of options above means like follows. There are many options for others, make sure with [man virt-install].
--name | specify the name of Virtual Machine |
--ram | specify the amount of memory of Virtual Machine |
--disk path=xxx,size=xxx | [path=xxx] : specify the location of disks of Virtual Machine (default is [/var/lib/libvirt/images]) [size=xxx] : specify the amount of disk of Virtual Machine |
--vcpus | specify the virtual CPUs. |
--os-variant | specify the kind of GuestOS possible to show the list of available OS with the command below [# osinfo-query os] |
--network | specify network type of Virtual Machine |
--graphics | specify the kind of graphics possible to specify vnc, spice, none and so on |
--console | specify the console type |
--location | specify the location of installation source where from |
--extra-args | specify parameters that are set in Kernel |
Step [2]After finishing installation, restart computer and then login prompt is shown like follows.
Fedora Linux 40 (Server Edition)
Kernel 6.8.5-301.fc40.x86_64 on an x86_64 (ttyS0)
Web console: https://localhost:9090/ or https://10.0.0.206:9090/
localhost login:
Step [3]Move to GuestOS to HostOS with Ctrl + ] key. Move to HostOS to GuestOS with a command [virsh console (name of virtual machine)].
[root@localhost ~]# # Ctrl + ] key
[root@bizantum ~]# # Host's console
[root@bizantum ~]# virsh console fedora40 # switch to Guest's console
Connected to domain fedora40
Escape character is ^] # Enter key
[root@localhost ~]# # Guest's console
Step [4]It's easy to replicate a copy VM from current VM with a command below.
[root@bizantum ~]# virt-clone --original fedora40 --name template --file /var/kvm/images/template.img
Allocating 'template.img' | 1.4 GB 00:00 ...
Clone 'template' created successfully.
# disk image
[root@bizantum ~]# ll /var/kvm/images/template.img
-rw-------. 1 root root 2140340224 May 9 13:51 /var/kvm/images/template.img
# configuration file
[root@bizantum ~]# ll /etc/libvirt/qemu/template.xml
-rw-------. 1 root root 6736 May 9 13:51 /etc/libvirt/qemu/template.xml
Create Virtual Machines (GUI)
If you installed Desktop Environment, it's possible to create a Virtual machine on GUI. This example shows to install Windows Server 2022 on GUI.
Step [1]Install required packages.
[root@bizantum ~]# dnf -y install virt-manager
Step [2]Start Desktop and run [Virtual Machine Manager] with root privilege.

Step [3] Click [New] button (it's just the PC-icon on upper-left) and open a wizard to create a new Virtual Machine.

Step [4]Specify the installation source.

Step [5]Select Installation media or ISO image, and specify OS type and version. Generally OS type and version are specified automatically from Installation media, but if not, specify it manually.

Step [6]Specify the amount of memory and number of virtual CPUs.

Step [7]Specify the amount of disk, and also its' Path if you set custom Path. (default is [/var/lib/libvirt/images])

Step [8]Input Virtual Machine's name and also confirm selections.

Step [9]Windows installer starts.

Step [10]Installation finished and Windows Server 2022 is running.

Basic Operation for VM
This is the Basic Operation for Virtual Machines.
Step [1]Start Virtual Machine.
# Start Virtual Machine [fedora40]
[root@bizantum ~]# virsh start fedora40
Domain fedora40 started
# start and connect to console of [fedora40]
[root@bizantum ~]# virsh start fedora40 --console
Domain fedora40 started
Connected to domain fedora40
Step [2]Stop Virtual Machine.
# Stop Virtual Machine [fedora40]
[root@bizantum ~]# virsh shutdown fedora40
Domain fedora40 is being shutdown
# Stop Virtual Machine [fedora40] forcely
[root@bizantum ~]# virsh destroy fedora40
Domain fedora40 destroyed
Step [3]Set auto-start for Virtual Machines.
# Enable auto-start for [fedora40]
[root@bizantum ~]# virsh autostart fedora40
Domain fedora40 marked as autostarted
# Disable auto-start for [fedora40]
[root@bizantum ~]# virsh autostart --disable fedora40
Domain fedora40 unmarked as autostarted
Step [4]List all Virtual Machines.
# List all active Virtual Machines
[root@bizantum ~]# virsh list
Id Name State
----------------------------------------
2 fedora40 running
# List all Virtual Machines included inactives
[root@bizantum ~]# virsh list --all
Id Name State
----------------------------------------
- fedora40 shut off
- template shut off
- Win2k22 shut off
Step [5]Switch console, Move to GuestOS to HostOS with Ctrl + ] key. Move to HostOS to GuestOS with a command [virsh console (name of virtual machine)].
# connect to [fedora40]
[root@bizantum ~]# virsh console fedora40
Connected to domain fedora40
Escape character is ^] # Enter key
Fedora Linux 40 (Server Edition)
Kernel 6.8.5-301.fc40.x86_64 on an x86_64 (ttyS0)
Web console: https://localhost:9090/ or https://10.0.0.206:9090/
localhost login: # just switched on Guest
Password:
[root@localhost ~]# # Ctrl + ] key
[root@bizantum ~]# # just switched on Host
Step [6]For Other options below, there are many options, try to verify them.
[root@bizantum ~]# virsh --help
virsh [options]... [<command_string>]
virsh [options]... <command> [args...]
options:
-c | --connect=URI hypervisor connection URI
-d | --debug=NUM debug level [0-4]
-e | --escape <char> set escape sequence for console
-h | --help this help
-k | --keepalive-interval=NUM
keepalive interval in seconds, 0 for disable
-K | --keepalive-count=NUM
number of possible missed keepalive messages
-l | --log=FILE output logging to file
-q | --quiet quiet mode
-r | --readonly connect readonly
-t | --timing print timing information
-v short version
-V long version
--version[=TYPE] version, TYPE is short or long (default short)
commands (non interactive mode):
Domain Management (help keyword 'domain')
attach-device attach device from an XML file
attach-disk attach disk device
attach-interface attach network interface
autostart autostart a domain
blkdeviotune Set or query a block device I/O tuning parameters.
blkiotune Get or set blkio parameters
blockcommit Start a block commit operation.
blockcopy Start a block copy operation.
blockjob Manage active block operations
blockpull Populate a disk from its backing image.
blockresize Resize block device of domain.
change-media Change media of CD or floppy drive
console connect to the guest console
cpu-stats show domain cpu statistics
create create a domain from an XML file
define define (but don't start) a domain from an XML file
desc show or set domain's description or title
destroy destroy (stop) a domain
detach-device detach device from an XML file
detach-device-alias detach device from an alias
detach-disk detach disk device
detach-interface detach network interface
domdisplay domain display connection URI
domfsfreeze Freeze domain's mounted filesystems.
domfsthaw Thaw domain's mounted filesystems.
domfsinfo Get information of domain's mounted filesystems.
domfstrim Invoke fstrim on domain's mounted filesystems.
domhostname print the domain's hostname
domid convert a domain name or UUID to domain id
domif-setlink set link state of a virtual interface
domiftune get/set parameters of a virtual interface
domjobabort abort active domain job
domjobinfo domain job information
domname convert a domain id or UUID to domain name
domrename rename a domain
dompmsuspend suspend a domain gracefully using power management functions
dompmwakeup wakeup a domain from pmsuspended state
domuuid convert a domain name or id to domain UUID
domxml-from-native Convert native config to domain XML
domxml-to-native Convert domain XML to native config
dump dump the core of a domain to a file for analysis
dumpxml domain information in XML
edit edit XML configuration for a domain
event Domain Events
inject-nmi Inject NMI to the guest
iothreadinfo view domain IOThreads
iothreadpin control domain IOThread affinity
iothreadadd add an IOThread to the guest domain
iothreaddel delete an IOThread from the guest domain
send-key Send keycodes to the guest
send-process-signal Send signals to processes
lxc-enter-namespace LXC Guest Enter Namespace
managedsave managed save of a domain state
managedsave-remove Remove managed save of a domain
managedsave-edit edit XML for a domain's managed save state file
managedsave-dumpxml Domain information of managed save state file in XML
managedsave-define redefine the XML for a domain's managed save state file
memtune Get or set memory parameters
perf Get or set perf event
metadata show or set domain's custom XML metadata
migrate migrate domain to another host
migrate-setmaxdowntime set maximum tolerable downtime
migrate-getmaxdowntime get maximum tolerable downtime
migrate-compcache get/set compression cache size
migrate-setspeed Set the maximum migration bandwidth
migrate-getspeed Get the maximum migration bandwidth
migrate-postcopy Switch running migration from pre-copy to post-copy
numatune Get or set numa parameters
qemu-attach QEMU Attach
qemu-monitor-command QEMU Monitor Command
qemu-monitor-event QEMU Monitor Events
qemu-agent-command QEMU Guest Agent Command
reboot reboot a domain
reset reset a domain
restore restore a domain from a saved state in a file
resume resume a domain
save save a domain state to a file
save-image-define redefine the XML for a domain's saved state file
save-image-dumpxml saved state domain information in XML
save-image-edit edit XML for a domain's saved state file
schedinfo show/set scheduler parameters
screenshot take a screenshot of a current domain console and store it into a file
set-lifecycle-action change lifecycle actions
set-user-password set the user password inside the domain
setmaxmem change maximum memory limit
setmem change memory allocation
setvcpus change number of virtual CPUs
shutdown gracefully shutdown a domain
start start a (previously defined) inactive domain
suspend suspend a domain
ttyconsole tty console
undefine undefine a domain
update-device update device from an XML file
vcpucount domain vcpu counts
vcpuinfo detailed domain vcpu information
vcpupin control or query domain vcpu affinity
emulatorpin control or query domain emulator affinity
vncdisplay vnc display
guestvcpus query or modify state of vcpu in the guest (via agent)
setvcpu attach/detach vcpu or groups of threads
domblkthreshold set the threshold for block-threshold event for a given block device or it's backing chain element
Domain Monitoring (help keyword 'monitor')
domblkerror Show errors on block devices
domblkinfo domain block device size information
domblklist list all domain blocks
domblkstat get device block stats for a domain
domcontrol domain control interface state
domif-getlink get link state of a virtual interface
domifaddr Get network interfaces' addresses for a running domain
domiflist list all domain virtual interfaces
domifstat get network interface stats for a domain
dominfo domain information
dommemstat get memory statistics for a domain
domstate domain state
domstats get statistics about one or multiple domains
domtime domain time
list list domains
Host and Hypervisor (help keyword 'host')
allocpages Manipulate pages pool size
capabilities capabilities
cpu-baseline compute baseline CPU
cpu-compare compare host CPU with a CPU described by an XML file
cpu-models CPU models
domcapabilities domain capabilities
freecell NUMA free memory
freepages NUMA free pages
hostname print the hypervisor hostname
hypervisor-cpu-baseline compute baseline CPU usable by a specific hypervisor
hypervisor-cpu-compare compare a CPU with the CPU created by a hypervisor on the host
maxvcpus connection vcpu maximum
node-memory-tune Get or set node memory parameters
nodecpumap node cpu map
nodecpustats Prints cpu stats of the node.
nodeinfo node information
nodememstats Prints memory stats of the node.
nodesuspend suspend the host node for a given time duration
sysinfo print the hypervisor sysinfo
uri print the hypervisor canonical URI
version show version
Interface (help keyword 'interface')
iface-begin create a snapshot of current interfaces settings, which can be later committed (iface-commit) or restored (iface-rollback)
iface-bridge create a bridge device and attach an existing network device to it
iface-commit commit changes made since iface-begin and free restore point
iface-define define an inactive persistent physical host interface or modify an existing persistent one from an XML file
iface-destroy destroy a physical host interface (disable it / "if-down")
iface-dumpxml interface information in XML
iface-edit edit XML configuration for a physical host interface
iface-list list physical host interfaces
iface-mac convert an interface name to interface MAC address
iface-name convert an interface MAC address to interface name
iface-rollback rollback to previous saved configuration created via iface-begin
iface-start start a physical host interface (enable it / "if-up")
iface-unbridge undefine a bridge device after detaching its slave device
iface-undefine undefine a physical host interface (remove it from configuration)
Network Filter (help keyword 'filter')
nwfilter-define define or update a network filter from an XML file
nwfilter-dumpxml network filter information in XML
nwfilter-edit edit XML configuration for a network filter
nwfilter-list list network filters
nwfilter-undefine undefine a network filter
nwfilter-binding-create create a network filter binding from an XML file
nwfilter-binding-delete delete a network filter binding
nwfilter-binding-dumpxml network filter information in XML
nwfilter-binding-list list network filter bindings
Networking (help keyword 'network')
net-autostart autostart a network
net-create create a network from an XML file
net-define define an inactive persistent virtual network or modify an existing persistent one from an XML file
net-destroy destroy (stop) a network
net-dhcp-leases print lease info for a given network
net-dumpxml network information in XML
net-edit edit XML configuration for a network
net-event Network Events
net-info network information
net-list list networks
net-name convert a network UUID to network name
net-start start a (previously defined) inactive network
net-undefine undefine a persistent network
net-update update parts of an existing network's configuration
net-uuid convert a network name to network UUID
Node Device (help keyword 'nodedev')
nodedev-create create a device defined by an XML file on the node
nodedev-destroy destroy (stop) a device on the node
nodedev-detach detach node device from its device driver
nodedev-dumpxml node device details in XML
nodedev-list enumerate devices on this host
nodedev-reattach reattach node device to its device driver
nodedev-reset reset node device
nodedev-event Node Device Events
Secret (help keyword 'secret')
secret-define define or modify a secret from an XML file
secret-dumpxml secret attributes in XML
secret-event Secret Events
secret-get-value Output a secret value
secret-list list secrets
secret-set-value set a secret value
secret-undefine undefine a secret
Snapshot (help keyword 'snapshot')
snapshot-create Create a snapshot from XML
snapshot-create-as Create a snapshot from a set of args
snapshot-current Get or set the current snapshot
snapshot-delete Delete a domain snapshot
snapshot-dumpxml Dump XML for a domain snapshot
snapshot-edit edit XML for a snapshot
snapshot-info snapshot information
snapshot-list List snapshots for a domain
snapshot-parent Get the name of the parent of a snapshot
snapshot-revert Revert a domain to a snapshot
Storage Pool (help keyword 'pool')
find-storage-pool-sources-as find potential storage pool sources
find-storage-pool-sources discover potential storage pool sources
pool-autostart autostart a pool
pool-build build a pool
pool-create-as create a pool from a set of args
pool-create create a pool from an XML file
pool-define-as define a pool from a set of args
pool-define define an inactive persistent storage pool or modify an existing persistent one from an XML file
pool-delete delete a pool
pool-destroy destroy (stop) a pool
pool-dumpxml pool information in XML
pool-edit edit XML configuration for a storage pool
pool-info storage pool information
pool-list list pools
pool-name convert a pool UUID to pool name
pool-refresh refresh a pool
pool-start start a (previously defined) inactive pool
pool-undefine undefine an inactive pool
pool-uuid convert a pool name to pool UUID
pool-event Storage Pool Events
Storage Volume (help keyword 'volume')
vol-clone clone a volume.
vol-create-as create a volume from a set of args
vol-create create a vol from an XML file
vol-create-from create a vol, using another volume as input
vol-delete delete a vol
vol-download download volume contents to a file
vol-dumpxml vol information in XML
vol-info storage vol information
vol-key returns the volume key for a given volume name or path
vol-list list vols
vol-name returns the volume name for a given volume key or path
vol-path returns the volume path for a given volume name or key
vol-pool returns the storage pool for a given volume key or path
vol-resize resize a vol
vol-upload upload file contents to a volume
vol-wipe wipe a vol
Virsh itself (help keyword 'virsh')
cd change the current directory
echo echo arguments
exit quit this interactive terminal
help print help
pwd print the current directory
quit quit this interactive terminal
connect (re)connect to hypervisor
(specify help <group> for details about the commands in the group)
(specify help <command> for details about the command)
Install VM Management Tools
Install useful tools for virtual machine management.
Step [1]Install required packages.
[root@bizantum ~]# dnf -y install guestfs-tools virt-top
Step [2][ls] a directory in a virtual machine.
[root@bizantum ~]# virt-ls -l -d fedora40 /root
total 32
dr-xr-x---. 3 root root 163 May 9 04:51 .
dr-xr-xr-x. 18 root root 235 May 9 04:42 ..
-rw-------. 1 root root 191 May 9 04:51 .bash_history
-rw-r--r--. 1 root root 18 Jan 26 00:00 .bash_logout
-rw-r--r--. 1 root root 141 Jan 26 00:00 .bash_profile
-rw-r--r--. 1 root root 429 Jan 26 00:00 .bashrc
-rw-r--r--. 1 root root 100 Jan 26 00:00 .cshrc
-rw-------. 1 root root 20 May 9 04:50 .lesshst
drwx------. 2 root root 6 May 9 04:43 .ssh
-rw-r--r--. 1 root root 129 Jan 26 00:00 .tcshrc
-rw-------. 1 root root 903 May 9 04:46 anaconda-ks.cfg
Step [3][cat] a file in a virtual machine.
[root@bizantum ~]# virt-cat -d fedora40 /etc/passwd
root:x:0:0:Super User:/root:/bin/bash
bin:x:1:1:bin:/bin:/usr/sbin/nologin
daemon:x:2:2:daemon:/sbin:/usr/sbin/nologin
adm:x:3:4:adm:/var/adm:/usr/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/usr/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/usr/sbin/nologin
operator:x:11:0:operator:/root:/usr/sbin/nologin
.....
.....
Step [4]Edit a file in a virtual machine.
[root@bizantum ~]# virt-edit -d fedora40 /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Nov 14 00:07:21 2023
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=61c79c7e-7c97-419d-9354-1d1d5ae9a825 / xfs defaults 0 0
UUID=2f6bd45e-26f3-4b5b-bc34-5d9e7859d72a /boot xfs defaults 0 0
Step [5]Display disk usage in a virtual machine.
[root@bizantum ~]# virt-df -d fedora40
Filesystem 1K-blocks Used Available Use%
fedora40:/dev/sda2 983040 239952 743088 25%
fedora40:/dev/fedora/root 15663104 1611960 14051144 11%
Step [6]Mount a disk for a virtual machine.
[root@bizantum ~]# guestmount -d fedora40 -i /media
[root@bizantum ~]# ll /media
total 20
dr-xr-xr-x. 2 root root 6 Jan 24 09:00 afs
lrwxrwxrwx. 1 root root 7 Jan 24 09:00 bin -> usr/bin
dr-xr-xr-x. 5 root root 4096 May 9 13:45 boot
drwxr-xr-x. 2 root root 6 May 9 13:42 dev
drwxr-xr-x. 107 root root 8192 May 9 13:50 etc
drwxr-xr-x. 3 root root 20 May 9 13:46 home
.....
.....
Step [7]Display the status of virtual machines.
[root@bizantum ~]# virt-top
virt-top 14:41:51 - x86_64 8/8CPU 2399MHz 15985MB
2 domains, 0 active, 0 running, 0 sleeping, 0 paused, 2 inactive D:0 O:0 X:0
CPU: 0.0% Mem: 0 MB (0 MB by guests)
ID S RDRQ WRRQ RXBY TXBY %CPU %MEM TIME NAME
- (fedora40)
- (win2k22)
.....
.....
Set VNC Connection
Set VNC connection to connect to virtual machines with VNC.
Step [1]Edit existing virtual machine's configuration and start virtual machine with VNC like follows. The example on this site shows to create a virtual machine without graphics, so it's OK to change settings like follows, but if you created virtual machine with graphics, Remove [<graphics>***] and [<video>***] sections in configuration file.
# edit the configuration of [fedora40]
[root@bizantum ~]# virsh edit fedora40
<domain type='kvm'>
<name>fedora40</name>
<uuid>b08033ca-ab65-4883-a7b0-751342abf9e5</uuid>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://fedoraproject.org/fedora/38"/>
</libosinfo:libosinfo>
</metadata>
.....
.....
# add like follows
# set any password for [passwd=***] section
# specify a unique number for [slot='0x**']
<graphics type='vnc' port='5900' autoport='no' listen='0.0.0.0' passwd='password'>
<listen type='address' address='0.0.0.0'/>
</graphics>
<video>
<model type='virtio' heads='1' primary='yes'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</video>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
</memballoon>
<rng model='virtio'>
<backend model='random'>/dev/urandom</backend>
<address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/>
</rng>
</devices>
</domain>
Domain fedora40 XML configuration edited.
[root@bizantum ~]# virsh start fedora40
Domain fedora40 started
Step [2]If Firewalld is running, allow ports you use for VNC.
[root@bizantum ~]# firewall-cmd --add-port=5900-5910/tcp
[root@bizantum ~]# firewall-cmd --runtime-to-permanent
Step [3]That's OK all. Refer to the next section to connect to VNC server from VNC client.
Step [4] If you'd like to enable VNC on initial creating of virtual machine, specify like follows. Then, it's possible to install Systems with VNC that requires GUI Installation like Windows without installing Desktop Environment on KVM Host computer.
[root@bizantum ~]# virt-install \
--name Win2k22 \
--ram 6144 \
--disk path=/var/kvm/images/Win2k22.img,size=100 \
--vcpus=4 \
--os-variant=win2k22 \
--network bridge=br0 \
--graphics vnc,listen=0.0.0.0,password=password \
--video vga \
--cdrom /home/Win2022_EN-US_20348.169.210806-2348.fe.iso \
--boot uefi
VNC Client : Fedora And Windows
Connect to a Virtual machine that is running with enabling VNC.
Step [1]On Fedora client with Desktop Environment, Run [dnf install virt-viewer] to install Virt Viewer and start [Remote Viewer] like follows

Step [2]Input [vnc://(server's hostname or IP address):(port)] and click [Connect] button.

Step [3]Input password you set and Click [OK] button.

Step [4]After successful authentication, it's possible to connect like follows.

VNC Client : Windows
It's possible to connect to VMs with VNC from Windows clients.
Step [5] Install any VNC Viewer on Windows client. This example is based on UltraVNC viewer. ⇒ http://www.uvnc.com/downloads/ultravnc.html After installing application, Input [(server's hostname or IP address):(port you set)] like follows and connect.

Step [6]VNC password is required to input for authentication.

Step [7]If successfully passed authentication, it's possible to connect to VM with VNC like follows.

Nested KVM
Configure Nested KVM. It's possible to install KVM Hypervisor and Create virtual machines as nested KVM on KVM host.
Step [1]Enable Nested KVM setting. (enabled by default)
# confirm current setting
[root@bizantum ~]# cat /sys/module/kvm_intel/parameters/nested
N # disabled
[root@bizantum ~]# vi /etc/modprobe.d/kvm.conf
# uncomment either of the line
# for Intel CPU, select [kvm_intel]
# for AMD CPU, select [kvm_amd]
options kvm_intel nested=1
#options kvm_amd nested=1
# unload
[root@bizantum ~]# modprobe -r kvm_intel
# reload
[root@bizantum ~]# modprobe kvm_intel
[root@bizantum ~]# cat /sys/module/kvm_intel/parameters/nested
Y # just enabled
Step [2]Edit the configuration of a virtual machine you'd like to set nested like follows. It's OK to configure nested KVM and you can create virtual machines on the virtual machine nested. ( for details of CPU mode ⇒ libvirt.org/formatdomain.html#elementsCPU )
# edit the settings of a VM [fedora40]
[root@bizantum ~]# virsh edit fedora40
# specify [host-passthrough] or [host-model] for [cpu mode] section
# on Fedora 40, [host-passthrough] is set by default
<cpu mode='host-passthrough' check='none' migratable='on'/>
- Get link
- X
- Other Apps
Comments
Post a Comment
Thank you for your comment! We appreciate your feedback, feel free to check out more of our articles.
Best regards, Bizantum Blog Team.