VM with libvirt


    apt-get install qemu qemu-kvm libvirt-clients libvirt-daemon-system virtinst bridge-utils

    Note: on debian12, qemu becomes qemu-sytem

    And vmx compatibility: grep -E --color 'vmx|svm' /proc/cpuinfo

    Build an image

    with Virt-builder

    Debian package: libguestfs-tools

    virt-builder debian-11 -o test.img --size 100G --root-password password:XXX --hostname test.parmentier.io --install "net-tools" --append-line '/etc/resolv.conf:nameserver'


    • you can use --firstboot-command 'apt-get install -y ...'
    • --append-line '/etc/hosts: server.ostechnix.local'


    Install an image

    Debian package: virtinst

    virt-install \
    --name test.parmentier.io \
    --ram 4096 \
    --disk path=/var/lib/libvirt/images/test.img \
    --vcpus 2 \
    --os-variant debian10 \
    --network bridge=br0,mac=xxx \
    --graphics none \
    --noautoconsole \
    --boot hd \


    • there is no --os-variant debian11 yet, but debian10 should be fine?
    • if you use a bridge network, ensure it is configured on host, and you might have to specify a virutal mac address (its the case for ovh vm within dedicated).
    • If you are trying to install an iso from scratch, you will certainly need --cdrom=/path/to/file.iso and --graphics vnc see example


    Start vm

    virsh --connect qemu:///system start test.parmentier.io

    Auto start

    virsh autostart test.parmentier.io

    Get into vm

    virsh console test.parmentier.io

    Edit configuration

    virsh edit test.parmentier.io

    Note: in some configuration (e.g. cpu) you will have to shutdown/start. See also examples


    virsh shutdown test.parmentier.io
    virsh undefine test.parmentier.io

    Reboot safely

    virsh reboot test.parmentier.io

    Hard reboot

    virsh reset test.parmentier.io

    Other useful commands

    • suspend: froze on memoryy
    • shutdown
    • destroy: do uninstall first
    • dominfo: get info such as cpu, memory

    Network (host)

    On debian 11, ensure apt-get install -y bridge-utils:

    iface eno3 inet manual
    auto br0
    iface br0 inet static
        address xx/24
        gateway yyy
        bridge-ports eno3
        bridge-stp off
        bridge-fd 0
        hwaddress 0a:xx:00


    • on debian 11, without mac address, it did not work. You can check available bridges with brctl show
    • on debian 12 (ovh template) I was not able to make it works. I played with source 1 and source 2 unsucessfully. It was like if interfaces was not taken in consideration, as well as cloud.cfg in networksection. I will try it when I have dedicated time.

    Also, ensure you have ip_forward=1, you cna check value with sysctl net.ipv4.ip_forward, and edit with sysctl net.ipv4.ip_forward=1. To make it persistant: edit /etc/sysctl.conf, find the line ip_forward=, then run sysctl -p /etc/sysctl.conf.

    Network (vm)

    auto enp1s0
    iface enp1s0 inet static
            address xx
            broadcast xx
            post-up ip route add yy/32 dev enp1s0
            post-up ip route add default via yy
            pre-down ip route del yy/32 dev enp1s0
            pre-down ip route del default via yy

    Note: replace xx and yy

    Export/Import VM


    # virsh configuration file
    virsh dumpxml test.parmentier.io >test.parmentier.io.xml
    # list of image(s) 
    virsh domblklist test.parmentier.io


    virsh define test.parmentier.io.xml

    Note: you will certainly need to update network (post-up ip route add rule) in order to use the host bridge ip.

    Web UI