FreeBSD VM unter kvm-qemu

FreeBSD VM erstellen mit libvirt und kvm-qemu unter Linux.

FreeBSD ISO herunterladen

cd /var/vm/
wget https://download.freebsd.org/snapshots/amd64/amd64/ISO-IMAGES/15.0/FreeBSD-15.0-CURRENT-amd64-20250801-0a3792d5c576-279199-disc1.iso

VM erstellen

virt-install --connect qemu:///system --name bsd2vm2 --osinfo freebsd14.0 --memory 2048 --vcpus=4 --accelerate --graphics vnc,password=foobar,listen=::,port=5901 --disk /var/vm/bsd2vm2/disk0.img,size=40 --cdrom /var/vm/FreeBSD-15.0-CURRENT-amd64-20250710-78935fa40eee-278643-disc1.iso --network=default

Per VNC auf Port 5901 verbinden. Passwort ist foobar
Installation von FreeBSD durchführen.

In der FreeBSD VM in /boot/loader.conf diesen Zeilen hinzufügen.

console="comconsole"
comconsole_speed="115200"

Nach einem Neustart lässt sich die FreeBSD VM über die Konsole bedienen (VNC nicht mehr notwendig).

Konsole öffnen

virsh console bsd2vm2

Laufende VMs anzeigen

virsh list

Alle VMs anzeigen

virsh list --all

VM starten

virsh start bsd2vm2

VM hart abschalten

virsh destroy bsd2vm2

VM löschen

virsh undefine bsd2vm2

VM Config bearbeiten

virsh edit bsd2vm2

Die Config-Datei enthält ein XML-Dokument mit der libvirt Syntax. Vieles was qemu kann, lässt sich damit einstellen, aber nicht alles. Der qemu Befehl, der ausgeführt wird, kann bei laufender VM mit

ps -Af | grep qemu

angezeigt werden.

Bridge in Linux erstellen und Interface für VM hinzufügen, welches mit der Bridge verbunden wird.

ip link add name bridge0 type bridge
virsh attach-interface --domain bsd2vm2 --type bridge --source bridge0 --config

qemu erstellt beim Starten der VM beim Host ein tap-Interface und fügt es der Bridge hinzu.

Um Mehrere Queues für ein Interface zu verwenden, driver Element hinzufügen (Config von bsd2vm1).

<interface type='bridge'>
  <mac address='52:54:00:b1:a0:5f'/>
  <source bridge='bridge0'/>
  <model type='virtio'/>
  <driver name='vhost' queues='3'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</interface>

Vollständige Config

<domain type='kvm'>
  <name>bsd2vm2</name>
  <uuid>ae6238ca-43fd-402d-abac-653b0f22101a</uuid>
  <metadata>
    <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
      <libosinfo:os id="http://freebsd.org/freebsd/14.0"/>
    </libosinfo:libosinfo>
  </metadata>
  <memory unit='KiB'>2097152</memory>
  <currentMemory unit='KiB'>2097152</currentMemory>
  <vcpu placement='static'>4</vcpu>
  <os>
    <type arch='x86_64' machine='pc-i440fx-noble'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <cpu mode='host-passthrough' check='none' migratable='on'/>
  <clock offset='utc'>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <pm>
    <suspend-to-mem enabled='no'/>
    <suspend-to-disk enabled='no'/>
  </pm>
  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2' discard='unmap'/>
      <source file='/var/vm/bsd2vm2/disk0.img'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </disk>
    <disk type='file' device='cdrom'>
      <driver name='qemu' type='raw'/>
      <target dev='hda' bus='ide'/>
      <readonly/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
    </disk>
    <controller type='usb' index='0' model='ich9-ehci1'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x7'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci1'>
      <master startport='0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0' multifunction='on'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci2'>
      <master startport='2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x1'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci3'>
      <master startport='4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <controller type='ide' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
    </controller>
    <interface type='network'>
      <mac address='52:54:00:a0:d1:71'/>
      <source network='default'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <interface type='bridge'>
      <mac address='52:54:00:93:06:9f'/>
      <source bridge='bridge0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </interface>
    <interface type='bridge'>
      <mac address='52:54:00:a3:d3:cb'/>
      <source bridge='bridge1'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target type='isa-serial' port='0'>
        <model name='isa-serial'/>
      </target>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <input type='tablet' bus='usb'>
      <address type='usb' bus='0' port='1'/>
    </input>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='vnc' port='5901' autoport='no' listen='::' passwd='foobar'>
      <listen type='address' address='::'/>
    </graphics>
    <audio id='1' type='none'/>
    <video>
      <model type='vga' vram='16384' heads='1' primary='yes'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </memballoon>
  </devices>
</domain>