Howto Qemu-kvm Debian 8

    In this howto, we will simply and quickly, step by step, start the Qemu-KVM hypervisor in debian 8.

    image

    We will start the virtual machine in qemu-kvm from the username user using spice, qxl and virtio.
    It is assumed that Debian 8 amd64 is installed, with standard utilities selected in tasksel and an SSH server. Install it.

    aptitude install -y firmware-linux bridge-utils etckeeper
    


    Check if our processor supports virtualization:
    egrep '(vmx|svm)' /proc/cpuinfo
    

    Enable forwarding, net.ipv4.ip_forward = 1
    vim /etc/sysctl.conf
    

    Create a bridge br0
    Example view / etc / network / interfaces
    # The loopback network interface
    auto lo
    iface lo inet loopback
    # The primary network interface
    #auto eth0
    #allow-hotplug eth0
    #iface eth0 inet dhcp
    auto br0
    iface br0 inet dhcp
            bridge_ports eth0
            bridge_stp off
            bridge_fd 0
            bridge_maxwait 0
    

    /etc/init.d/networking restart
    

    Check, it should be like “br0 8000.08608ee7dc58 no eth0”
    brctl show 
    

    Using a bridge, when starting a virtual machine, vnetX interfaces will rise
    tcpdump -i vnet0 -n
    

    Install kvm:
    aptitude install qemu-kvm libvirt-bin
    

    Add the user to the kvm groups:
    adduser username kvm
    adduser username libvirt
    

    Let's allow access for spice and change the user under whom everything will work:
    vim /etc/libvirt/qemu.conf
    

    spice_listen = "0.0.0.0"
    user = "username"
    group = "username"


    By and large everything is ready to go.
    Without running virtual machines, the host system takes ~ 150 mb ram

    You can skip - an option for advanced
    GUI manager for performing a basic series of tasks when working with kvm.
    Creating, starting / stopping, cloning is almost :) everything you need.

    On another computer, install:
    aptitude install ssh-askpass virt-manager virt-viewer spice-client-gtk
    

    We launch virt-manager.
    File -> add connection -> Hypervisor: QEMU / KVM and connect to the remote host under our username username. Authorization uses openssh-askpass.
    Edit -> connection properties - Repository
    Here you can manage repositories - for example, create qemu-iso-storage and put distributions there for further needs. For example, gparted.

    You can connect to the created virtual machine with a simple weaver with all the functionality that spice provides.
    To do this, you need to know the URI of the domain / virt.machines on kvm
    virsh domdisplay corn
    

    On the client, run:
    remote-viewer spice://10.1.1.8:5905 
    


    The same as another weaver, which is spice-client-gtk:
    spicy -h 10.1.1.8 -p 5905
    


    In an advanced version, there is a bug when creating a new virtual machine.
    In the settings where we select the spice server or vnc server, you cannot select spice without enabling TLS.
    By itself, TLS in qemu is not used by default and, therefore, is turned off.
    If TLS is not needed yet, you can temporarily start the virtual machine with the vnc server so that corn.xml is created in / etc / libvirt / qemu / and replace the section in it on spice with TLS turned off.

    How to make friends TLS is written here - habrahabr.ru/post/221693


    We continue to configure as root.

    We define pools - where everything will lie
    . Storage configurations are stored here / etc / libvirt / storage /
    default is default.xml - storage on the file system in / var / lib / libvirt / images
    Add your qemu-test-storage:
    * -as creates a repository similar to default, i.e. the configuration is the same as in default.xml
    virsh pool-define-as qemu-test-storage dir --target /home/username/qemu-test-storage/
    

    By default, the pool is not running, start:
    virsh pool-start qemu-test-storage
    

    Add the created pool to the auto start:
    virsh pool-autostart qemu-test-storage
    

    View all pools:
    virsh pool-list --all
    

    All domains:
    virsh list --all
    


    Registering a domain (virtual machine) with the configuration described in the corn.xml file
    Creating xml with the configuration (for example, for a template) is easier via virt-manager than describing each option in virt-install.
    All virtual machine configurations are stored in / etc / libvirt / qemu /
    In general, it is assumed that we have this file.
    virsh define /home/username/anyfolder/corn.xml
    

    Add domain to startup:
    virsh autostart corn
    

    Current domain configuration:
    virsh dumpxml corn
    

    Editing the domain:
    virsh edit corn
    

    We start the domain, look at the URI and connect in any way possible.
    virsh start corn
    virsh domdisplay corn
    


    To install windows on the VirtIO partition, the installer needs a driver from the viostor folder of the virtio for windows driver package.
    On linux-kvm.org there are sources, on fedoraproject.org you can find compiled virt-win.iso
    After installation, you will most likely need spice windows guest tools

    Now we will expand the domain volume.
    We will use qemu-img - QEMU disk image utility. In our case, the volume is corn.qcow2
    Observation - windows 7 is not enough 10GB to download everything from the update center at once and install them correctly.
    It can be useful to first install “Update for Windows 7 (KB2852386)” - it allows you to somehow clean up C: \ Windows \ winxsx through the standard “disk cleanup” and between reboots, and then use the update center.

    Check the section:
    cd  /home/username/qemu-qcow2-storage/
    qemu-img info corn.qcow2
    qemu-img check corn.qcow2
    

    Minimum is enough of the following:
    qemu-img resize corn.qcow2 +10GB
    

    Then we add the CD-ROM device, "insert gparted there " and everything is as usual. Russian language - 24.
    For good, you need to use libguestfs-tools or resize2fs.

    For Windows 8.1 you need a wddm driver, QXL will be very slow, it is better to forward the host video card.
    About OEM activation of Windows it is very well written here - habrahabr.ru/post/247597

    Thank you all.

    Also popular now: