Setup KVM on Debian

3 minute read Published:

Heading 2

This is based on Cyberciti’s post.

Install KVM

sudo apt install qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils libguestfs-tools genisoimage virtinst libosinfo-bin

Allow my normal user to manage the virtual machines

sudo adduser stefan libvirt
sudo adduser stefan libvirt-qemu

Configure the KVM bridged network

sudo vim /root/bridged.xml
<network>
  <name>br0</name>
  <forward mode="bridge"/>
  <bridge name="br0"/>
</network>

Then use that file for the configuration

sudo virsh net-define --file /root/bridged.xml
sudo virsh net-autostart br0
sudo virsh net-start br0

Then the net-list shows the following:

stefan@sulin:~$ sudo virsh net-list --all
[sudo] password for stefan: 
 Name      State      Autostart   Persistent
----------------------------------------------
 br0       active     yes         yes
 default   inactive   no          yes

stefan@sulin:~$

Step X

Download a CentOS iso.

stefan@sulin:~/download$ wget http://linux.cs.uu.nl/centos/8-stream/isos/x86_64/CentOS-Stream-8-x86_64-20191219-dvd1.iso

This stopped with the following message

Cannot write to ‘CentOS-Stream-8-x86_64-20191219-dvd1.iso’ (Read-only file system).

Investigating that, showed some issues with the hardware.

root@sulin:~# mount | grep "(ro,"
/dev/mapper/sulin-root on / type ext4 (ro,relatime,errors=remount-ro,stripe=384)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
/dev/mapper/sulin-home on /home type ext4 (ro,relatime,stripe=384)
root@sulin:~# dmesg 
-bash: /usr/bin/dmesg: Input/output error
root@sulin:~# cd /var/log
root@sulin:/var/log# cat kern.log
Dec 29 20:41:24 sulin kernel: [10552795.528666] hpsa 0000:02:00.0: scsi 0:1:0:0: resetting logical  Direct-Access     HP       LOGICAL VOLUME   RAID-6 SSDSmartPathCap- En- Exp=1
root@sulin:/var/log# cd
root@sulin:~# ssacli 
Smart Storage Administrator CLI 3.30.13.0
Detecting Controllers...Done.
Type "help" for a list of supported commands.
Type "exit" to close the console.

=> controller all show config

Smart Array P420i (Error: Not responding)


=>

So, it seems there are hardware issues. I have to look at those when I have access to the hardware. It seems that there was an issue with the RAID-controler of the hardware.

To install the downloaded CentOS 8, we use the following:

sudo virt-install \
--virt-type=kvm \
--name centos8 \
--ram 4096 \
--vcpus=2 \
--os-variant=rhel8.0 \
--hvm \
--cdrom=/home/stefan/download/CentOS-Stream-8-x86_64-20191219-dvd1.iso \
--network=bridge=br0,model=virtio \
--graphics vnc \
--disk path=/var/lib/libvirt/images/centos8.qcow2,size=40,bus=virtio,format=qcow2

This resulted in an error, because there was not enough diskspace available in /var/lib/libvirt/images

WARNING  The requested volume capacity will exceed the available pool space when the volume is fully allocated. (40960 M requested capacity > 11013 M available)
ERROR    The requested volume capacity will exceed the available pool space when the volume is fully allocated. (40960 M requested capacity > 11013 M available) (Use --check disk_size=off or --check all=off to override)

Because /home has more diskspace available, I created a new directory for the images there. And then used that directory

sudo mkdir -p /home/libvirt/images
sudo virt-install --virt-type=kvm --name centos8 --ram 4096 --vcpus=2 --os-variant=rhel8.0 --hvm --cdrom=/home/stefan/download/CentOS-Stream-8-x86_64-20191219-dvd1.iso --network=bridge=br0,model=virtio --graphics vnc --disk path=/home/libvirt/images/centos8.qcow2,size=40,bus=virtio,format=qcow2

To run the installation, I have check where the VNC is listening at.

sudo virsh dumpxml centos8 | grep vnc

This showed that my vnc is listening on port 5900. To connect to this vnc, use the following

vncviewer -via sulin 127.0.0.1

Then use the installer to finish the install.

To make it easier to manage the QEMU systems, I installed virt-manager on the host.

sudo apt install virt-manager

To make it possible to connect to the console via a text interface, a process should be listening on the “VM’s COM port”. So I ran the following command in the CentOS 8 VM.

systemctl start getty@ttyS0
systemctl enable getty@ttyS0

And then I was able to connect to the console via virsh.

stefan@sulin:~$ sudo virsh console centos8
[sudo] password for stefan: 
Connected to domain centos8
Escape character is ^]

CentOS Linux 8 (Core)
Kernel 4.18.0-151.el8.x86_64 on an x86_64

Activate the web console with: systemctl enable --now cockpit.socket

sulin-centos8 login: root
Password: 
Last login: Wed Jan  1 15:28:57 on ttyS0
[root@sulin-centos8 ~]# w
 15:35:07 up 32 min,  1 user,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     ttyS0    -                15:35    2.00s  0.06s  0.02s w
[root@sulin-centos8 ~]#

If we would like to be able to follow the boot process, We would have to do more.

Recent posts
- full list -