1. Information

2. Installation

  • Install Debian 10 with desktop environment.

  • Enter the following commands at command line.

    sudo apt install --yes bridge-utils libvirt-daemon-system qemu-kvm virtinst
    sudo systemctl enable libvirtd
    sudo systemctl start libvirtd
    sudo systemctl status libvirtd
    sudo adduser smru libvirt
    sudo adduser smru libvirt-qemu
    sudo virsh
    quit
    sudo apt install virt-manager -y
    
    sudo virsh net-autostart default
    
    sudo ls -al /var/lib/libvirt/images
    sudo ls -al /etc/libvirt/qemu/networks
    
    virt-manager

2.1. Bridging

  • Create a /etc/systemd/network/br0.netdev file with the following contents.

    [NetDev]
    Name=br0
    Kind=bridge
    # Prevent systemd-networkd assigning a different MAC-Address.
    # Assign MAC-address of phyical interface to bridge.
    MACAddress=xx:xx:xx:xx:xx:xx
  • Create a /etc/systemd/network/br0.network file with the following contents.

    [Match]
    Name=eth0
    
    [Network]
    Bridge=br0
  • Rename eth0 to br0 in the /etc/systemd/network/eth0.network file.

  • Enter the following commands at command line.

    networkctl
    sudo brctl show

2.2. Xrdp

  • Enter the following commands at command line.

    sudo apt install xfce4 xfce4-goodies xorg dbus-x11 x11-xserver-utils
    sudo apt install xrdp
    sudo systemctl status xrdp
    sudo adduser smru ssl-cert
    sudo systemctl restart xrdp

3. Configuration

  • Todo:.

  • Enter the following commands at command line.

*

3.1. NIC Teaming

  • Enter the following commands at command line.

    sudo apt-get install ifenslave-2.6
    sudo cp -a /etc/modules /etc/modules.org
    sudo modprobe bonding
    sudo echo 'bonding' >> /etc/modules
    sudo cp -a  /etc/network/interfaces /etc/network/interfaces.org
  • Append the following lines in the /etc/network/interfaces file.

    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # enp3s0 configuration
    auto enp3s0
    iface enp3s0 inet manual
    bond-master bond0
    bond-primary enp3s0
    
    # enp4s0 configuration
    auto enp4s0
    iface enp4s0 inet manual
    bond-master bond0
    
    # Bonding enp3s0 & enp4s0 to create bond0 NIC
    auto bond0
    iface bond0 inet static
    address 10.20.1.20
    gateway 10.20.1.170
    netmask 255.255.255.0
    bond-mode active-backup
    bond-miimon 100
    bond-slaves none
  • NIC Teaming with Bridge: Append the following lines in the /etc/network/interfaces file.

    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # enp3s0 configuration
    auto enp3s0
    iface enp3s0 inet manual
    bond-master bond0
    bond-primary enp3s0
    
    # enp4s0 configuration
    auto enp4s0
    iface enp4s0 inet manual
    bond-master bond0
    
    # Bonding enp3s0 & enp4s0 to create bond0 NIC
    auto bond0
    iface bond0 inet manual
    bond-mode active-backup
    bond-miimon 100
    bond-slaves none
    
    # br0 configuration with bond0
    auto br0
    iface br0 inet static
    address 10.20.1.20
    netmask 255.255.255.0
    gateway 10.20.1.170
    bridge_ports bond0
    bridge_stp off
    bridge_waitport 0
    bridge_fd 0
  • Restart the network service or the computer.

  • Enter the following commands at command line.

    cat /proc/net/bonding/bond0
    sudo ifconfig
  • Note: You will see the two NIC has the same MAC address.

4. Virtual Machine Creation

4.1. Command Line

  • Enter the following commands at command line.

    sudo virt-install --name=debian11-2 \
    --os-variant=debian10 \
    --ram=1024 \
    --vcpus=1 \
    --network bridge:br0 \
    --graphics none \
    --location=/home/delta/Downloads/debian-11.0.0-amd64-xfce-DVD-1.iso \
    --disk size=20 \
    --extra-args="console=tty0 console=ttyS0,115200" \
    --check all=off
  • Do the installation process.

  • Press Ctrl + ] to quit the KVM guest console.

  • Enter the following commands at command line.

    systemctl status serial-getty@ttyS0.service
    systemctl enable serial-getty@ttyS0.service
    systemctl status serial-getty@ttyS0.service
    
    systemctl status serial-getty@ttyS0.service
    systemctl start serial-getty@ttyS0.service
    systemctl status serial-getty@ttyS0.service
  • Connect to KVM guest.

    • Type sudo virsh console --domain debian11-2.

    • Press Enter to login the KVM guest.

    • Do your thing.

  • Press Ctrl + ] to quit the KVM guest console.

  • Useful commands

    # Start the VM
    sudo virsh list --all
    sudo virsh start --domain debian11-2
    sudo virsh list --all
    
    # Pause the VM
    sudo virsh list --all
    sudo virsh suspend --domain debian11-2
    sudo virsh list --all
    
    # Resume the VM
    sudo virsh list --all
    sudo virsh resume --domain debian11-2
    sudo virsh list --all
    
    # Force shutoff the VM
    sudo virsh list --all
    sudo virsh shutdown --domain debian11-2
    sudo virsh list --all
    
    # Make sure the libvirtd service is started on boot
    systemctl status libvirtd
    systemctl enable libvirtd
    systemctl status libvirtd
    
    # List auto start VM
    sudo virsh list --all --autostart
    
    # List no auto start VM
    sudo virsh list --all --no-autostart
    
    # Make the VM autostart
    sudo virsh autostart --domain debian11-2
    
    # Make the VM not autostart
    sudo virsh autostart --disable --domain debian11-2
    
    # Clone the VM when the VM is shutoff
    # The clone will not include the snapshots
    sudo virt-clone --original debian11-2 --name debian11-3 --file /var/lib/libvirt/images/debian11-3.qcow2
    
    # Delete the VM with no snapshots
    sudo virsh list --all
    sudo virsh domblklist --domain debian11-2
    sudo virsh undefine --domain debian11-2
    sudo virsh list --all
    sudo vdir /var/lib/libvirt/images
    sudo rm -f /var/lib/libvirt/images/debian11-2.qcow2
    sudo vdir /var/lib/libvirt/images
    
    sudo virsh list --all
    sudo virsh domblklist --domain debian11-2
    sudo vdir /var/lib/libvirt/images
    sudo vdir /etc/libvirt/qemu
    sudo virsh undefine --domain debian11-2 --remove-all-storage
    sudo virsh list --all
    sudo vdir /var/lib/libvirt/images
    sudo vdir /etc/libvirt/qemu
    
    # Snapshot
    sudo virsh snapshot-list --domain debian11-2
    sudo virsh snapshot-create-as --domain debian11-2 --name "test"
    sudo virsh snapshot-list --domain debian11-2
    sudo virsh snapshot-info --domain debian11-2 --snapshotname "test"
    
    # Revert to a snapshot when the VM is shutoff or running
    sudo virsh list --all
    sudo virsh snapshot-list --domain debian11-2
    sudo virsh snapshot-revert --domain debian11-2 --snapshotname "test"
    sudo virsh snapshot-revert --domain debian11-2 --snapshotname "test" --running
    sudo virsh snapshot-list --domain debian11-2
    sudo virsh list --all
    
    # Delete the VM snapshots
    sudo virsh snapshot-list --domain debian11-2
    sudo virsh snapshot-delete --domain debian11-2 --snapshotname "test"
    sudo virsh snapshot-list --domain debian11-2
    
    # Backup the VM when the VM is shutoff or running
    sudo vdir /var/lib/libvirt/images
    sudo vdir /etc/libvirt/qemu
    sudo cp -p /var/lib/libvirt/images/debian11-3.qcow2 /tmp
    sudo cp -p /etc/libvirt/qemu/debian11-3.xml /tmp
    sudo vdir /tmp
    
    # Restore the VM from the backup
    sudo virsh list --all
    sudo virsh undefine --domain debian11-3 --remove-all-storage
    sudo virsh list --all
    sudo vdir /var/lib/libvirt/images
    sudo cp -p /tmp/debian11-3.qcow2 /var/lib/libvirt/images
    sudo vdir /var/lib/libvirt/images
    sudo vdir /etc/libvirt/qemu
    sudo cp -p /tmp/debian11-3.xml /etc/libvirt/qemu
    sudo vdir /etc/libvirt/qemu
    sudo virsh list --all
    sudo virsh define /etc/libvirt/qemu/debian11-3.xml
    
    # Expand the VM disk size
    sudo virsh vol-info /var/lib/libvirt/images/debian11-3.qcow2
    sudo qemu-img resize /var/lib/libvirt/images/debian11-3.qcow2 +5G
    sudo virsh vol-info /var/lib/libvirt/images/debian11-3.qcow2
    
    # Increasing resources (vCPU and Memory) of the VM
    sudo virsh shutdown --domain debian11-3
    sudo virsh edit --domain debian11-3
    
    # From
    #    <vcpu placement='static'>1</vcpu>
    #    <memory unit='KiB'>1048576</memory>
    #    <currentMemory unit='KiB'>1048576</currentMemory>
    
    # To
    #    <vcpu placement='static'>2</vcpu>
    #    <memory unit='KiB'>4048576</memory>
    #    <currentMemory unit='KiB'>4048576</currentMemory>
    
    sudo virsh start --domain debian11-3
    
    # Storage pools
    sudo mkdir /guest-images
    sudo virsh pool-define-as smru --type dir --target "/guest-images"
    sudo virsh pool-autostart smru
    sudo virsh pool-start smru
    sudo virsh pool-list --all --details
    
    sudo virsh pool-list
    sudo virsh pool-list --all --details
    sudo virsh pool-info default
    sudo virsh pool-info smru
    sudo virsh vol-list default
    sudo virsh vol-list smru
    sudo virsh pool-edit default
    sudo virsh pool-edit smru

4.2. GUI

  • Start Virtual Machine Manager.

  • Select File > New Virtual Machine.

  • Choose Local install media (ISO imange or CDROM).

  • Click Forward.

  • Click Browse.

  • Select the .iso file and click Choose Volume.

  • Check Automatically detect form the installation media / source.

  • Note: If the iso file is compatible, your will see the OS name in Choose the operating system you are installing field.

  • Click Forward.

  • Todo:. *

5. USB Key Passthrough