QEMU/KVM Virtual machine Management: Difference between revisions

From WikiMLT
(Стадий: 1 [Фаза:Идентифициране, Статус:Създаване]; Категория:Virtual Machines; { The page is created via DevStage })
 
m (Стадий: 6 [Фаза:Утвърждаване, Статус:Утвърден]; Категория:Virtual Machines)
 
(7 intermediate revisions by the same user not shown)
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.  


* ...
=== Basic operations ===
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>
=== Configuring Virtual machine automatic start ===
'''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>
=== References ===
*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.
* [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.
<noinclude>
<noinclude>
<div id='devStage'>
<div id='devStage'>
{{devStage  
{{devStage  
  | Прндл  = Virtual Machines
  | Прндл  = Virtual Machines
  | Стадий = 1
  | Стадий = 6
  | Фаза  = Идентифициране
  | Фаза  = Утвърждаване
  | Статус = Създаване
  | Статус = Утвърден
  | ИдтПт  = {{REVISIONUSER}}
  | ИдтПт = Spas
  | ИдтДт  = {{Today}}
| РзбПт  = Spas
  | ИдтРв  = {{REVISIONID}}
| АвтПт  = Spas
| УтвПт = {{REVISIONUSER}}
  | ИдтДт = 2.09.2022
| РзбДт  = 2.09.2022
| АвтДт  = 2.09.2022
| УтвДт = {{Today}}
  | ИдтРв = [[Special:Permalink/31026|31026]]
| РзбРв  = [[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: