QEMU/KVM Virtual machine Management: Difference between revisions

From WikiMLT
m (Стадий: 3 [Фаза:Разработване, Статус:Разработван]; Категория:Virtual Machines)
mNo edit summary
Line 1: Line 1:
<noinclude><!--[[Category:Virtual Machines|?]]-->{{ContentArticleHeader/Virtual Machines}}</noinclude>
<noinclude><!--[[Category:Virtual Machines|?]]-->{{ContentArticleHeader/Virtual Machines}}</noinclude>
== References ==


* ...
== 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.


* ...
View the list of all available virtual machines:
<syntaxhighlight lang="shell" line="1">
virsh list --all
</syntaxhighlight>


== Section 1 ==
Start, reboot, suspend, rename, shutdown a VM:
...
<syntaxhighlight lang="shell" line="1">
virsh (start|reboot|suspend|rename|shutdown) {vm-name|vm-Id}
</syntaxhighlight>
 
Dump a VM XML configuration file:
<syntaxhighlight lang="shell" line="1">
virsh dumpxml {vm-name} > {vm-name}.xml
</syntaxhighlight>
 
Creating or defining a VM based on XML dump configuration file. Before this step modifi {vm-name}.xml and update the values of <name>, <uuid>, <title>, <description>:
<syntaxhighlight lang="shell" line="1">
virsh create {vm-name}.xml
</syntaxhighlight>
 
<syntaxhighlight lang="shell" line="1">
virsh define {vm-name}.xml
virsh start {vm-name}
</syntaxhighlight>
 
Completely remove a VM:
<syntaxhighlight lang="shell" line="1">
sudo virsh undefine {vm-name|vm-Id}
sudo virsh destroy {vm-name|vm-Id}
</syntaxhighlight>
 
View the list of the associated virtual networks:
<syntaxhighlight lang="shell" line="1">
virsh net-list --all
</syntaxhighlight>
 
Disable an network and disable autostart:
<syntaxhighlight lang="shell" line="1">
virsh net-destroy {net-name}
virsh net-autostart --network {net-name} --disable
</syntaxhighlight>
 
Enable an network and disable autostart:
<syntaxhighlight lang="shell" line="1">
virsh net-start {net-name}
virsh net-autostart --network {net-name} --enable
</syntaxhighlight>
 
References:
* [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">
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
</syntaxhighlight>'''2.''' Enable Virtual Machine automatic start.<syntaxhighlight lang="shell" line="1">
virsh autostart {vm.name.org}
</syntaxhighlight>
 
* If <code>virsh</code> command is not available/installed, to configure austostart simply create a new symbolic link within <code>/etc/libvirt/qemu/autostart/</code> directory using <code>ln</code> command.
* Reload hyper-visor if necessary: <code>systemctl reload libvirtd</code>
 
'''3.''' Disable Virtual Machine autostart.<syntaxhighlight lang="shell" line="1">
virsh autostart --disable {vm.name.org}
</syntaxhighlight>
 
* 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==
{{Collapse/begin}}
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.
{{Collapse/div|#Refs}}
* 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://github.com/microsoft/wslg Use WSLg], that will be available in Windows 11.
{{Collapse/end}}


<noinclude>
<noinclude>

Revision as of 15:58, 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. Here are pro­vid­ed few ba­sic com­mands.

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

Ref­er­ences:

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

Re­mote GUI Man­age­ment via virt-man­ag­er

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' with user WSL2 en­abled you can use virt-man­ag­er at least three ways.

#Refs