QEMU/KVM Virtual machine Management: Difference between revisions

From WikiMLT
m (Стадий: 6 [Фаза:Утвърждаване, Статус:Утвърден]; Категория:Virtual Machines)
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:


== Virsh: Command-line Management User Interface ==
== Virsh: Command-line Management User Interface ==
The '''virsh''' program is the main interface for managing virsh guest domains. The program can be used to create, pause, and shutdown domains... Libvirt (which provides virsh program) is a C toolkit to interact with the virtualization capabilities of recent versions of Linux (and other OSes)... It currently supports Xen, QEMU, KVM, LXC, OpenVZ, VirtualBox and VMware ESX. Here are provided few basic commands.
The '''virsh''' program is the main interface for managing virsh guest domains. The program can be used to create, pause, and shutdown domains... Libvirt (which provides virsh program) is a C toolkit to interact with the virtualization capabilities of recent versions of Linux (and other OSes)... It currently supports Xen, QEMU, KVM, LXC, OpenVZ, VirtualBox and VMware ESX.  


=== Basic operations ===
View the list of all available virtual machines:
View the list of all available virtual machines:
<syntaxhighlight lang="shell" line="1">
<syntaxhighlight lang="shell" line="1">
Line 52: Line 53:
</syntaxhighlight>
</syntaxhighlight>


References:
=== Configuring Virtual machine automatic start ===
* [http://manpages.ubuntu.com/manpages/xenial/man1/virsh.1.html Ubuntu Manuals: <code>virsh</code> - management user interface]
* [https://docs.openstack.org/newton/networking-guide/misc-libvirt.html OpenStack: Disable libvirt networking]
*[https://docs.fedoraproject.org/en-US/Fedora/18/html/Virtualization_Administration_Guide/form-Virtualization-Managing_guests_with_virsh-Creating_a_virtual_machine_XML_dump_configuration_file.html Fedora Documentation:  Creating a virtual machine XML dump (configuration file)]
 
'''Configuring Virtual machine automatic start.'''
 
* ''Ref: [https://linuxconfig.org/configuring-virtual-machine-automatic-start-on-redhat-linux-host LinuxConfig.org: Configuring Virtual machine automatic start on Redhat Linux host]''
 
'''1.''' First get info about the target instance.<syntaxhighlight lang="shell" line="1">
'''1.''' First get info about the target instance.<syntaxhighlight lang="shell" line="1">
virsh list --all                # list all available Virtual Machines
virsh list --all                # list all available Virtual Machines
Line 78: Line 71:
* Or simply use <code>unlink</code> command to remove virtual machine’s symbolic link from <code>/etc/libvirt/qemu/autostart/</code> directory: <code>unlink /etc&shy;/&shy;lib&shy;virt&shy;/&shy;qemu&shy;/&shy;auto&shy;start&shy;/&shy;{vm.&shy;name.&shy;org}.&shy;xml</code>
* Or simply use <code>unlink</code> command to remove virtual machine’s symbolic link from <code>/etc/libvirt/qemu/autostart/</code> directory: <code>unlink /etc&shy;/&shy;lib&shy;virt&shy;/&shy;qemu&shy;/&shy;auto&shy;start&shy;/&shy;{vm.&shy;name.&shy;org}.&shy;xml</code>


== Remote GUI Management via virt-manager==
=== References ===


For remote GUI management you can use the tool <code>virt-manager</code> on the remote machine. If there is a set SSH connection (via <code>~/.ssh/config</code>) you can use this option where you won't have to worry about extra open ports in your firewall. If you are a Windows' with user <code>WSL2</code> enabled you can use <code>virt-manager</code> at least three ways.
*Ubuntu Manuals: [http://manpages.ubuntu.com/manpages/xenial/man1/virsh.1.html <code>virsh</code> - management user interface]
* OpenStack: [https://docs.openstack.org/newton/networking-guide/misc-libvirt.html Disable libvirt networking]
*Fedora Documentation: [https://docs.fedoraproject.org/en-US/Fedora/18/html/Virtualization_Administration_Guide/form-Virtualization-Managing_guests_with_virsh-Creating_a_virtual_machine_XML_dump_configuration_file.html Creating a virtual machine XML dump (configuration file)]
*LinuxConfig.org: [https://linuxconfig.org/configuring-virtual-machine-automatic-start-on-redhat-linux-host Configuring Virtual machine automatic start on Redhat Linux host]
 
== Virt-manager: GUI Management (local and via ssh)==
 
For remote GUI management you can use the tool <code>virt-manager</code> on the remote machine. If there is a set SSH connection (via <code>~/.ssh/config</code>) you can use this option where you won't have to worry about extra open ports in your firewall. If you are a Windows' user and [[Setup WSL2|WSL2]] is enabled, you can use <code>virt-manager</code> at least three ways:


* Setup xRDP in WSL2, watch [https://youtu.be/IL7Jd9rjgrM WSL2 Ubuntu GUI by David Bombal] for more details.
* Setup xRDP in WSL2, watch [https://youtu.be/IL7Jd9rjgrM WSL2 Ubuntu GUI by David Bombal] for more details.
* [https://opticos.github.io/gwsl/tutorials/manual.html Use GWSL] available in [https://www.microsoft.com/en-us/p/gwsl/9nl6kd1h33v3?activetab=pivot:overviewtab Microsoft Store] – this is really convenient way.
* [https://opticos.github.io/gwsl/tutorials/manual.html Use GWSL] available in [https://www.microsoft.com/en-us/p/gwsl/9nl6kd1h33v3?activetab=pivot:overviewtab Microsoft Store] – this is really convenient way.
* [https://github.com/microsoft/wslg Use WSLg], that will be available in Windows 11.
* [https://github.com/microsoft/wslg Use WSLg], that will be available in Windows 11.
<noinclude>
<noinclude>
<div id='devStage'>
<div id='devStage'>
{{devStage  
{{devStage  
  | Прндл  = Virtual Machines
  | Прндл  = Virtual Machines
  | Стадий = 3
  | Стадий = 6
  | Фаза  = Разработване
  | Фаза  = Утвърждаване
  | Статус = Разработван
  | Статус = Утвърден
  | ИдтПт  = Spas
  | ИдтПт  = Spas
  | РзбПт  = {{REVISIONUSER}}
  | РзбПт = Spas
| АвтПт  = Spas
| УтвПт = {{REVISIONUSER}}
  | ИдтДт  = 2.09.2022
  | ИдтДт  = 2.09.2022
  | РзбДт  = {{Today}}
  | РзбДт = 2.09.2022
| АвтДт  = 2.09.2022
| УтвДт = {{Today}}
  | ИдтРв  = [[Special:Permalink/31026|31026]]
  | ИдтРв  = [[Special:Permalink/31026|31026]]
  | РзбРв  = {{REVISIONID}}
  | РзбРв = [[Special:Permalink/31032|31032]]
| АвтРв  = [[Special:Permalink/31033|31033]]
| УтвРв = {{REVISIONID}}
}}
}}
</div>
</div>
</noinclude>
</noinclude>

Latest revision as of 16:06, 2 September 2022

Virsh: Com­mand-line Man­age­ment User In­ter­face

The virsh pro­gram is the main in­ter­face for man­ag­ing virsh guest do­mains. The pro­gram can be used to cre­ate, pause, and shut­down do­mains… Lib­virt (which pro­vides virsh pro­gram) is a C toolk­it to in­ter­act with the vir­tu­al­iza­tion ca­pa­bil­i­ties of re­cent ver­sions of Lin­ux (and oth­er OS­es)… It cur­rent­ly sup­ports Xen, QE­MU, KVM, LXC, Open­VZ, Vir­tu­al­Box and VMware ESX.

Ba­sic op­er­a­tions

View the list of all avail­able vir­tu­al ma­chines:

virsh list --all

Start, re­boot, sus­pend, re­name, shut­down a VM:

virsh (start|reboot|suspend|rename|shutdown) {vm-name|vm-Id}

Dump a VM XML con­fig­u­ra­tion file:

virsh dumpxml {vm-name} > {vm-name}.xml

Cre­at­ing or defin­ing a VM based on XML dump con­fig­u­ra­tion file. Be­fore this step mod­i­fi {vm-name}.xml and up­date the val­ues of <name>, <uuid>, <ti­tle>, <de­scrip­tion>:

virsh create {vm-name}.xml
virsh define {vm-name}.xml
virsh start {vm-name}

Com­plete­ly re­move a VM:

sudo virsh undefine {vm-name|vm-Id}
sudo virsh destroy {vm-name|vm-Id}

View the list of the as­so­ci­at­ed vir­tu­al net­works:

virsh net-list --all

Dis­able an net­work and dis­able au­tostart:

virsh net-destroy {net-name}
virsh net-autostart --network {net-name} --disable

En­able an net­work and dis­able au­tostart:

virsh net-start {net-name}
virsh net-autostart --network {net-name} --enable

Con­fig­ur­ing Vir­tu­al ma­chine au­to­mat­ic start

1. First get in­fo about the tar­get in­stance.

virsh list --all                # list all available Virtual Machines
virsh dominfo {vm.name.org}     # check whether given virtual machine is configured to autostart
ls /etc/libvirt/qemu/autostart/ # list all virtual machines already configured to autostart

2. En­able Vir­tu­al Ma­chine au­to­mat­ic start.

virsh autostart {vm.name.org}
  • If virsh com­mand is not available/​​​installed, to con­fig­ure aus­tostart sim­ply cre­ate a new sym­bol­ic link with­in /​​​etc/​​​libvirt/​​​qemu/​​​autostart/​​​ di­rec­to­ry us­ing ln com­mand.
  • Re­load hy­per-vi­sor if nec­es­sary: sys­tem­ctl re­load lib­virtd

3. Dis­able Vir­tu­al Ma­chine au­tostart.

virsh autostart --disable {vm.name.org}
  • Or sim­ply use un­link com­mand to re­move vir­tu­al machine’s sym­bol­ic link from /​​​etc/​​​libvirt/​​​qemu/​​​autostart/​​​ di­rec­to­ry: un­link /etc­/­lib­virt­/­qemu­/­auto­start­/­{vm.­name.­org}.­xml

Ref­er­ences

Virt-man­ag­er: GUI Man­age­ment (lo­cal and via ssh)

For re­mote GUI man­age­ment you can use the tool virt-man­ag­er on the re­mote ma­chine. If there is a set SSH con­nec­tion (via ~/.ssh/config) you can use this op­tion where you won't have to wor­ry about ex­tra open ports in your fire­wall. If you are a Win­dows' user and WSL2 is en­abled, you can use virt-man­ag­er at least three ways: