Difference between revisions of "Virsh console"

From wikieduonline
Jump to navigation Jump to search
 
(16 intermediate revisions by the same user not shown)
Line 6: Line 6:
 
* Man page: https://www.libvirt.org/manpages/virsh.html#console
 
* Man page: https://www.libvirt.org/manpages/virsh.html#console
  
== Examples ==
+
== Connection examples ==
 +
Connecting using VM name:
 
  virsh console [[YOUR_VM_NAME|MACHINE_NAME]]
 
  virsh console [[YOUR_VM_NAME|MACHINE_NAME]]
 
  Connected to domain MACHINE_NAME
 
  Connected to domain MACHINE_NAME
Line 12: Line 13:
 
  error: operation failed: Active console session exists for this domain
 
  error: operation failed: Active console session exists for this domain
  
 +
Connecting using VM id. You can obtain it with <code>[[virsh list]]</code>
 +
virsh console 3
 +
 +
Error when no argument is provided:
 
  virsh console
 
  virsh console
 
  error: command 'console' requires <[[domain]]> option
 
  error: command 'console' requires <[[domain]]> option
  
 
== [[Enable serial console]] ==
 
== [[Enable serial console]] ==
You need to enable [[serial]] console in your VM machine.<ref>https://www.cyberciti.biz/faq/how-to-enable-kvm-virsh-console-access-for-ubuntu-linux-vm/</ref>
+
{{enable serial console}}
 +
 
 +
== Configure [[KVM]] server ==
 +
 
 +
[[virsh edit]] VM_NAME
  
1) Enable serial console:
+
<serial type='pty'>
* <code>sudo [[systemctl enable]] [[serial-getty]]@[[ttyS0]].service</code>
+
  <source path='/dev/pts/0'/>
* <code>sudo [[systemctl start]] serial[email protected]</code>
+
  <target type='isa-serial' port='0'>
 +
    <model name='isa-serial'/>
 +
  </target>
 +
  <alias name='serial0'/>
 +
</serial>
 +
<console type='pty' tty='/dev/pts/0'>
 +
  <source path='/dev/pts/0'/>
 +
  <target type='serial' port='0'/>
 +
  <alias name='serial0'/>
 +
</console>
 +
Ref: https://ravada.readthedocs.io/en/latest/docs/config_console.html
  
2) Connect to VM:
+
== Quit console ==
* <code>[[virsh]] [[console]] MACHINE</code>
+
Use <code>[[CTRL + 5]]</code> to exit the console.<ref>https://ravada.readthedocs.io/en/latest/docs/config_console.html</ref>
  
 
== Kill old console ==
 
== Kill old console ==
Line 37: Line 56:
 
* <code>[[virsh vncdisplay]] VM_NAME</code>
 
* <code>[[virsh vncdisplay]] VM_NAME</code>
 
* <code>[[/var/log/libvirt/]]qemu/</code>
 
* <code>[[/var/log/libvirt/]]qemu/</code>
 +
* <code>[[virsh edit]]</code>
 
* [[Console]]
 
* [[Console]]
 +
* [[virt-manager]]
  
 
== See also ==
 
== See also ==
Line 43: Line 64:
 
* {{virsh}}
 
* {{virsh}}
  
[[Category:Linux]]
+
[[Category:virsh]]
 
[[Category:KVM]]
 
[[Category:KVM]]

Latest revision as of 18:17, 29 June 2022

virsh console YOUR_MACHINE Connect the virtual serial console for the guest

Syntax:

Connection examples[edit]

Connecting using VM name:

virsh console MACHINE_NAME
Connected to domain MACHINE_NAME
Escape character is ^]
error: operation failed: Active console session exists for this domain

Connecting using VM id. You can obtain it with virsh list

virsh console 3

Error when no argument is provided:

virsh console
error: command 'console' requires <domain> option

Enable serial console[edit]

You need to enable serial console in your VM machine.[1]

1) Enable serial console on VM_MACHINE:

2) Connect to VM:

Configure KVM server[edit]

virsh edit VM_NAME
<serial type='pty'>
 <source path='/dev/pts/0'/>
 <target type='isa-serial' port='0'>
   <model name='isa-serial'/>
 </target>
 <alias name='serial0'/>
</serial>
<console type='pty' tty='/dev/pts/0'>
 <source path='/dev/pts/0'/>
 <target type='serial' port='0'/>
 <alias name='serial0'/>
</console>

Ref: https://ravada.readthedocs.io/en/latest/docs/config_console.html

Quit console[edit]

Use CTRL + 5 to exit the console.[2]

Kill old console[edit]

ps -ef | grep console
kill -9 {PID}

Related[edit]

See also[edit]

  • https://www.cyberciti.biz/faq/how-to-enable-kvm-virsh-console-access-for-ubuntu-linux-vm/
  • https://ravada.readthedocs.io/en/latest/docs/config_console.html
  • Advertising: