1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-05 12:46:18 +01:00
Files
openshift-docs/modules/virt-connecting-vm-virtctl.adoc
2025-12-04 21:28:45 +00:00

84 lines
2.2 KiB
Plaintext

// Module included in the following assemblies:
//
// * virt/virtual_machines/virt-accessing-vm-consoles.adoc
ifeval::["{context}" == "vnc-console"]
:vnc-console:
:console: VNC console
endif::[]
ifeval::["{context}" == "serial-console"]
:serial-console:
:console: serial console
endif::[]
:_mod-docs-content-type: PROCEDURE
[id="virt-connecting-vm-virtctl_{context}"]
= Connecting to the {console} by using virtctl
[role="_abstract"]
You can use the `virtctl` command-line tool to connect to the {console} of a running virtual machine.
ifdef::vnc-console[]
[NOTE]
====
If you run the `virtctl vnc` command on a remote machine over an SSH connection, you must forward the X session to your local machine by running the `ssh` command with the `-X` or `-Y` flags.
====
.Prerequisites
* You must install the `virt-viewer` package.
endif::[]
.Procedure
. Run the following command to start the console session:
+
ifdef::serial-console[]
[source,terminal]
----
$ virtctl console <vm_name>
----
. Press `Ctrl+]` to end the console session.
endif::[]
ifdef::vnc-console[]
+
[source,terminal]
----
$ virtctl vnc <vm_name> -n <namespace> --preserve-session
----
+
where:
+
<vm_name>:: The name of the VM.
+
<namespace>:: The namespace that contains the VM.
+
--preserve-session:: Prevents an existing VNC console connection from being disconnected if you attempt to start a new session.
+
Only one connection to the VNC console is possible at a time. If you attempt to create a second connection to the same VNC console, an error is displayed and the connection fails.
+
Example error message:
+
[source,terminal]
----
can't access VMI example-vm: Internal error occurred: Can't connect to websocket (503): websocket: bad handshake: application info: Active VNC connection. Request denied.
----
+
If you attempt to create a second connection to the same VNC console without using the `--preserve-session` flag, this forces the existing connection to disconnect to allow the new connection.
. If the connection fails, run the following command to collect troubleshooting information:
+
[source,terminal]
----
$ virtctl vnc <vm_name> -v 4
----
endif::[]
ifeval::["{context}" == "vnc-console"]
:!console:
endif::[]
ifeval::["{context}" == "serial-console"]
:!console:
endif::[]