How to exit console in L2 vm?

Hi, I have a question about nested virtualization. The scenario is as below: 1. Prepare the nested environment, start L2 guest. 2. On the host, connect the L1 vm console, then on L1 guest, connect the L2 guest console: (host)# virsh console L1_vm Connected to domain L1_vm Escape character is ^] (Ctrl + ]) ... (L1 vm)# virsh console L2_vm Connected to domain L2_vm Escape character is ^] (Ctrl + ]) ... (L2 vm)# <=== press " ^] " to exit the console, it return to the **host** (host)# Is it expected that "^]" in L2 guest will exit thoroughly to the host, not the L1 guest? Thank you! ------- Best Regards, Yalan Zhang IRC: yalzhang

Hi Yalan, I am not certain about that but I think it is as expected. When you send ^] (which is the common escape sequence used in telnet) on the host L1 console wil receive the key codes and forward to L2 console so the latter one should exit. But L1 console also receives the escape character itself so it also exits. A solution it to set a different escape sequence for the consoles[1]:
- -e, --escape string
Set alternative escape sequence for console command. By default, telnet's ^] is used. Allowed characters when using hat notation are: alphabetic character, @, [, ], , ^, _.
So that L1 console will not exit when forwarding the sequence to L2 console without quitting itself. [1]: https://libvirt.org/manpages/virsh.html#description Yalan Zhang <yalzhang@redhat.com> 於 2020年11月30日 週一 下午2:55寫道:
Hi,
I have a question about nested virtualization. The scenario is as below: 1. Prepare the nested environment, start L2 guest. 2. On the host, connect the L1 vm console, then on L1 guest, connect the L2 guest console: (host)# virsh console L1_vm Connected to domain L1_vm Escape character is ^] (Ctrl + ]) ... (L1 vm)# virsh console L2_vm Connected to domain L2_vm Escape character is ^] (Ctrl + ]) ... (L2 vm)# <=== press " ^] " to exit the console, it return to the **host** (host)#
Is it expected that "^]" in L2 guest will exit thoroughly to the host, not the L1 guest? Thank you!
------- Best Regards, Yalan Zhang IRC: yalzhang
-- Regards, Yukin CHAN, ISTQB She / Her / Hers Software Quality Engineer, Virtualization Red Hat APAC <https://www.redhat.com/> 9 floor, Raycom Infotech Park, North Tower C 2 Kexueyuan Nanlu, Haidian District, Beijing, China T: 86-10-65627449 PGP: AC7BCF02F44FA43F940A3B9A25D5E545D2C3D639 <https://www.redhat.com/>

On Mon, Nov 30, 2020 at 02:50:33PM +0800, Yalan Zhang wrote:
Hi,
I have a question about nested virtualization. The scenario is as below: 1. Prepare the nested environment, start L2 guest. 2. On the host, connect the L1 vm console, then on L1 guest, connect the L2 guest console: (host)# virsh console L1_vm Connected to domain L1_vm Escape character is ^] (Ctrl + ]) ... (L1 vm)# virsh console L2_vm Connected to domain L2_vm Escape character is ^] (Ctrl + ]) ... (L2 vm)# <=== press " ^] " to exit the console, it return to the **host** (host)#
Is it expected that "^]" in L2 guest will exit thoroughly to the host, not the L1 guest? Thank you!
Hi, With virsh you can configure different escape character. It could look like this for example: On host you would run: virsh console L1_vm and in the L1 VM you would run this: virsh -e ^[ console L2_vm For more info check the virsh man page. Pavel

On Mon, Nov 30, 2020 at 14:50:33 +0800, Yalan Zhang wrote:
Hi,
I have a question about nested virtualization. The scenario is as below: 1. Prepare the nested environment, start L2 guest. 2. On the host, connect the L1 vm console, then on L1 guest, connect the L2 guest console: (host)# virsh console L1_vm Connected to domain L1_vm Escape character is ^] (Ctrl + ]) ... (L1 vm)# virsh console L2_vm Connected to domain L2_vm Escape character is ^] (Ctrl + ]) ... (L2 vm)# <=== press " ^] " to exit the console, it return to the **host** (host)#
Is it expected that "^]" in L2 guest will exit thoroughly to the host, not the L1 guest?
Yes it is expected since the keystroke goes through L1 first. You can use the '-e' switch of virsh to set the console escape character in one of the clients differently: $ virsh -e '^[' console 1 Connected to domain fedora32 Escape character is ^[ (Ctrl + [)

I see. Thank you for the detailed explanation. ------- Best Regards, Yalan Zhang IRC: yalzhang On Mon, Nov 30, 2020 at 3:31 PM Peter Krempa <pkrempa@redhat.com> wrote:
On Mon, Nov 30, 2020 at 14:50:33 +0800, Yalan Zhang wrote:
Hi,
I have a question about nested virtualization. The scenario is as below: 1. Prepare the nested environment, start L2 guest. 2. On the host, connect the L1 vm console, then on L1 guest, connect the L2 guest console: (host)# virsh console L1_vm Connected to domain L1_vm Escape character is ^] (Ctrl + ]) ... (L1 vm)# virsh console L2_vm Connected to domain L2_vm Escape character is ^] (Ctrl + ]) ... (L2 vm)# <=== press " ^] " to exit the console, it return to the **host** (host)#
Is it expected that "^]" in L2 guest will exit thoroughly to the host, not the L1 guest?
Yes it is expected since the keystroke goes through L1 first.
You can use the '-e' switch of virsh to set the console escape character in one of the clients differently:
$ virsh -e '^[' console 1 Connected to domain fedora32 Escape character is ^[ (Ctrl + [)
participants (4)
-
Pavel Hrdina
-
Peter Krempa
-
Yalan Zhang
-
Yukin Chan