Guest mode. You can read posts without signing up. Comments, ratings, job contacts and your own posts open after you sign up and accept the rules. What is Kommit →

Редакция КоммитРедакция портала
commit 0a5276d · 18 days ago

Linux and KVM, part 3: installing KVM, the Cockpit web interface, and creating the first VMs with Linux and Windows

🌐 Machine-translated from Russian. Show original

In this part:

Step 1. Checking the processor#

egrep -c '(vmx|svm)' /proc/cpuinfo   # больше 0 — виртуализация есть
sudo apt install -y cpu-checker
kvm-ok                               # ожидаем: KVM acceleration can be used

If kvm-ok swears — return to the BIOS and enable VT-x / SVM (part 1).

Step 2. Installing KVM and libvirt#

sudo apt install -y qemu-kvm libvirt-daemon-system libvirt-clients virtinst \
  bridge-utils ovmf qemu-guest-agent
sudo usermod -aG libvirt,kvm $USER

Log out and log back in via SSH to have the groups applied. Verification:

virsh list --all          # пустой список без ошибок — все хорошо
virsh net-list --all      # сеть default должна быть active

If the network default is inactive: virsh net-start default && virsh net-autostart default.

Step 3. Cockpit web interface#

Cockpit is a free web server dashboard: uploads, logs, services, updates, and virtual machines.

sudo apt install -y cockpit cockpit-machines
sudo ufw allow from 192.168.1.0/24 to any port 9090 proto tcp

Open https://192.168.1.10:9090in your browser, accept the self-signed certificate, log in with your login and password. Click Turn on administrative access.

💡 Do not expose port 9090 to the internet. For external access, use a VPN (see the MikroTik series).

Step 4. Where to put the ISO#

cd /var/lib/libvirt/images
sudo wget https://releases.ubuntu.com/24.04/ubuntu-24.04.5-live-server-amd64.iso
sudo wget https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso

Specify the Ubuntu file name on releases.ubuntu.com/24.04 — the point release number changes. Windows Server ISO and Windows 10/11 are downloaded from Microsoft's website (trial versions of Windows Server are in the Microsoft Evaluation Center) and copied here via SFTP, for example via WinSCP or MobaXterm.

Step 5. The first VM with Linux in Cockpit#

Virtual machines → Create VM:

FieldValue
Nameweb01
Installation typeLocal install media → ISO Ubuntu
Operating systemUbuntu 24.04 LTS
StorageCreate new volume, 30 GB
Memory2 GB

Create and run → open the Console tab and install Ubuntu just as in part 2.

The same goes for the team#

virt-install \
  --name web01 \
  --memory 2048 --vcpus 2 \
  --disk size=30,format=qcow2,bus=virtio \
  --cdrom /var/lib/libvirt/images/ubuntu-24.04.5-live-server-amd64.iso \
  --os-variant ubuntu24.04 \
  --network network=default,model=virtio \
  --graphics vnc,listen=127.0.0.1 \
  --noautoconsole

List of supported --os-variant: osinfo-query os | grep -i ubuntu.

Step 6. Windows VM: Key Points — VirtIO#

Windows does not recognize VirtIO fast virtual disks and network cards, so without drivers, the installer "does not see" the disk.

virt-install \
  --name win2022 \
  --memory 8192 --vcpus 4 --cpu host-passthrough \
  --machine q35 --boot uefi \
  --disk size=80,format=qcow2,bus=virtio \
  --cdrom /var/lib/libvirt/images/Windows_Server_2022.iso \
  --disk /var/lib/libvirt/images/virtio-win.iso,device=cdrom \
  --os-variant win2k22 \
  --network network=default,model=virtio \
  --graphics vnc,listen=127.0.0.1 \
  --tpm backend.type=emulator,model=tpm-crb \
  --noautoconsole

For TPM emulation (required for Windows 11), install the swtpm-toolspackage.

During Windows installation:

  1. On the disc selection screen — Download driver → second CD (virtio-win) → viostor\2k22\amd64 (for Windows 11 — w11).
  2. The disk appears — install it.
  3. After installation, run the virtio-win-guest-tools.exe CD — it will install the network drivers, memory ballooning, and QEMU Guest Agent.

Step 7. Connecting to the console#

  • Cockpit → VM → Console — the easiest.
  • virt-manager on your Linux PC: File → Add Connection → QEMU/KVM, Connect to remote host over SSH, ivan@192.168.1.10. Website: virt-manager.org.
  • VNC via SSH tunnel: ssh -L 5900:127.0.0.1:5900 ivan@192.168.1.10, then VNC client on localhost:5900. VM port number: virsh vncdisplay win2022.

Step 8. Autostart and basic commands#

virsh autostart web01           # стартовать вместе с хостом
virsh list --all                # все ВМ
virsh start web01               # включить
virsh shutdown web01            # корректно выключить (нужен ACPI или guest agent)
virsh destroy web01             # «выдернуть шнур» — только если зависла
virsh dominfo web01             # сведения о ВМ

Currently, VMs sit in an internal NAT network 192.168.122.0/24: they access the internet, but cannot be connected from the office. How to bring them to a local network — Linux and KVM, part 4: network (NAT, bridge, VLAN) and storage (qcow2, LVM, ZFS) for virtual machines.

Comments 00 участников · 0 гостей🔒 Rate and discuss after signing up

Comments · 0

No comments yet.Sign in to comment, rate and see all comments.