Порядок установки системы виртуализации QEMU/KVM см. в статье Виртуализация QEMU/KVM в Astra Linux.
Для создания локальной виртуальной машины с помощью описания XML в системе виртуализации QEMU/KVM Astra Linux Special Edition:
1. Описать конфигурацию виртуальной машины в XML формате согласно XML Scheme (схемы расположены в /usr/share/libvirt/schemas). Подробное описание формата XML можно найти на официальном web-сайте libvirt: https://libvirt.org/formatdomain.html. В данном примере создается ВМ под названием «generic»:
- с использованием виртуального диска размером 12 GB (/var/lib/libvirt/images/generic.qcow2)
- с использованием ISO-образа для установки ОС (/opt/os_install.iso).
Пример используемого XML-описания конфигурации - приведен в файле generic.xml:
Click here to expand...
<domain type='kvm'>
<name>generic</name>
<uuid>38b4f179-3653-46e1-aaeb-70562869680e</uuid>
<memory unit='KiB'>1048576</memory>
<currentMemory unit='KiB'>1048576</currentMemory>
<vcpu placement='static'>1</vcpu>
<os>
<type arch='x86_64' machine='pc-i440fx-2.8'>hvm</type>
<bootmenu enable='yes'/>
</os>
<features>
<acpi/>
<apic/>
<vmport state='off'/>
</features>
<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>restart</on_crash>
<pm>
<suspend-to-mem enabled='no'/>
<suspend-to-disk enabled='no'/>
</pm>
<devices>
<emulator>/usr/bin/kvm</emulator>
<disk type='file' device='disk'>
<driver name='qemu' type='qcow2'/>
<source file='/var/lib/libvirt/images/generic.qcow2'/>
<target dev='sda' bus='sata'/>
<boot order='1'/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='/opt/os_install.iso'/>
<target dev='hdb' bus='ide'/>
<readonly/>
<boot order='2'/>
<address type='drive' controller='0' bus='0' target='0' unit='1'/>
</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>
<controller type='sata' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
</controller>
<controller type='virtio-serial' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
</controller>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
<channel type='spicevmc'>
<target type='virtio' name='com.redhat.spice.0'/>
<address type='virtio-serial' controller='0' bus='0' port='1'/>
</channel>
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
<graphics type='vnc' port='5900' autoport='no' listen='0.0.0.0'>
<listen type='address' address='0.0.0.0'/>
<image compression='off'/>
</graphics>
<sound model='ich6'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</sound>
<video>
<model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
</video>
<redirdev bus='usb' type='spicevmc'>
<address type='usb' bus='0' port='1'/>
</redirdev>
<redirdev bus='usb' type='spicevmc'>
<address type='usb' bus='0' port='2'/>
</redirdev>
<memballoon model='virtio'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</memballoon>
</devices>
</domain>
2. От имени учетной записи администратора создать виртуальный диск размером 12Gb, описанный в конфигурации (секция <disk type='file' device='disk'>...</disk>):
sudo qemu-img create -f qcow2 /var/lib/libvirt/images/generic.qcow2 12G
3. Указать свой установочный образ ОС вместо образа /opt/os_install.iso в секции
<disk type='file' device='cdrom'>...</disk>;
4. Зарегистрировать виртуальную машину с помощью команды:
virsh -c qemu:///system define XML_ВМ
заменив XML_ВМ на путь к xml-конфигурации создаваемой виртуальной машины.
7. Запустить виртуальную машину:
virsh -c qemu:///system start generic
где generic — имя виртуальной машины.5.Подключится к виртуальной машине с помощью одной из команд:
а) Для виртуальных машин с графическим сервером Spice (требуется установка пакета spice-client-gtk):
sudo apt install spice-client-gtk
spicy -h localhost -p 5900
б) Для виртуальных машин с графическим сервером VNC (требуется установка пакета gvncviewer или tigervnc-viewer):
vncviewer localhost:5900