Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit 3269ba1

Browse files
authored
Merge pull request #704 from amshinde/update-agent-debug-console
docs: Update docs for enabling agent debug console
2 parents e2a4f98 + 219ded8 commit 3269ba1

File tree

1 file changed

+62
-30
lines changed

1 file changed

+62
-30
lines changed

Developer-Guide.md

+62-30
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@
4040
* [Checking Docker default runtime](#checking-docker-default-runtime)
4141
* [Set up a debug console](#set-up-a-debug-console)
4242
* [Create a custom image containing a shell](#create-a-custom-image-containing-a-shell)
43-
* [Create a debug systemd service](#create-a-debug-systemd-service)
4443
* [Build the debug image](#build-the-debug-image)
4544
* [Configure runtime for custom debug image](#configure-runtime-for-custom-debug-image)
4645
* [Ensure debug options are valid](#ensure-debug-options-are-valid)
46+
* [Enable debug console for the agent](#enable-debug-console-for-the-agent)
47+
* [Enabling debug console for QEMU](#enabling-debug-console-for-qemu)
48+
* [Enabling debug console for cloud-hypervisor / firecracker](#enabling-debug-console-for-cloud-hypervisor--firecracker)
4749
* [Create a container](#create-a-container)
4850
* [Connect to the virtual machine using the debug console](#connect-to-the-virtual-machine-using-the-debug-console)
4951
* [Obtain details of the image](#obtain-details-of-the-image)
@@ -526,35 +528,6 @@ $ export ROOTFS_DIR=${GOPATH}/src/github.com/kata-containers/osbuilder/rootfs-bu
526528
$ script -fec 'sudo -E GOPATH=$GOPATH USE_DOCKER=true EXTRA_PKGS="bash coreutils" ./rootfs.sh centos'
527529
```
528530

529-
### Create a debug systemd service
530-
531-
Create the service file that starts the shell in the rootfs directory:
532-
533-
```
534-
$ cat <<EOT | sudo tee ${ROOTFS_DIR}/lib/systemd/system/kata-debug.service
535-
[Unit]
536-
Description=Kata Containers debug console
537-
538-
[Service]
539-
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
540-
StandardInput=tty
541-
StandardOutput=tty
542-
# Must be disabled to allow the job to access the real console
543-
PrivateDevices=no
544-
Type=simple
545-
ExecStart=/bin/bash
546-
Restart=always
547-
EOT
548-
```
549-
550-
**Note**: You might need to adjust the `ExecStart=` path.
551-
552-
Add a dependency to start the debug console:
553-
554-
```
555-
$ sudo sed -i '$a Requires=kata-debug.service' ${ROOTFS_DIR}/lib/systemd/system/kata-containers.target
556-
```
557-
558531
### Build the debug image
559532

560533
Follow the instructions in the [Build a rootfs image](#build-a-rootfs-image)
@@ -598,6 +571,59 @@ $ sudo awk '{if (/^\[proxy\.kata\]/) {got=1}; if (got == 1 && /^.*enable_debug/)
598571
$ sudo install -o root -g root -m 0640 /tmp/configuration.toml /etc/kata-containers/
599572
```
600573

574+
### Enable debug console for the agent
575+
576+
The steps required to enable debug console for QEMU slightly differ with
577+
those for firecracker / cloud-hypervisor.
578+
579+
#### Enabling debug console for QEMU
580+
581+
Add `agent.debug_console` to the guest kernel command line to allow the agent process to start a debug console.
582+
583+
```
584+
$ sudo sed -i -e 's/^kernel_params = "\(.*\)"/kernel_params = "\1 agent.debug_console"/g' "${kata_configuration_file}"
585+
```
586+
587+
Here `kata_configuration_file` could point to `/etc/kata-containers/configuration.toml`
588+
or `/usr/share/defaults/kata-containers/configuration.toml`
589+
or `/opt/kata/share/defaults/kata-containers/configuration-{hypervisor}.toml`, if
590+
you installed Kata Containers using `kata-deploy`.
591+
592+
#### Enabling debug console for cloud-hypervisor / firecracker
593+
594+
Slightly different configuration is required in case of firecracker and cloud hypervisor.
595+
Firecracker and cloud-hypervisor don't have a UNIX socket connected to `/dev/console`.
596+
Hence, the kernel command line option `agent.debug_console` will not work for them.
597+
These hypervisors support `hybrid vsocks`, which can be used for communication
598+
between the host and the guest. The kernel command line option `agent.debug_console_vport`
599+
was added to allow developers specify on which `vsock` port the debugging console should be connected.
600+
601+
602+
Add the parameter `agent.debug_console_vport=1026` to the kernel command line
603+
as shown below:
604+
```
605+
sudo sed -i -e 's/^kernel_params = "\(.*\)"/kernel_params = "\1 agent.debug_console_vport=1026"/g' "${kata_configuration_file}"
606+
```
607+
608+
> **Note** Ports 1024 and 1025 are reserved for communication with the agent
609+
> and gathering of agent logs respectively.
610+
611+
Next, connect to the debug console. The VSOCKS paths vary slightly between
612+
cloud-hypervisor and firecracker.
613+
In case of cloud-hypervisor, connect to the `vsock` as shown:
614+
```
615+
$ sudo su -c 'cd /var/run/vc/vm/{sandbox_id}/root/ && socat stdin unix-connect:clh.sock'
616+
CONNECT 1026
617+
```
618+
619+
**Note**: You need to type `CONNECT 1026` and press `RETURN` key after entering the `socat` command.
620+
621+
For firecracker, connect to the `hvsock` as shown:
622+
```
623+
$ sudo su -c 'cd /var/run/vc/firecracker/{sandbox_id}/root/ && socat stdin unix-connect:kata.hvsock'
624+
CONNECT 1026
625+
```
626+
601627
### Create a container
602628

603629
Create a container as normal. For example using Docker:
@@ -614,6 +640,12 @@ $ console="/var/run/vc/vm/${id}/console.sock"
614640
$ sudo socat "stdin,raw,echo=0,escape=0x11" "unix-connect:${console}"
615641
```
616642

643+
In case of firecracker, you would need the following command:
644+
```
645+
sudo su -c 'cd /var/lib/vc/firecracker/08facf/root/ && socat stdin unix-connect:kata.hvsock'
646+
CONNECT 1026
647+
```
648+
617649
**Note**: You need to press the `RETURN` key to see the shell prompt.
618650

619651
To disconnect from the virtual machine, type `CONTROL+q` (hold down the

0 commit comments

Comments
 (0)