Connecting to the LXC (CT) console is straightforward; simply use the command: pct enter <container_id>.

However, connecting to a VM console requires a few additional setup steps beforehand.

The process is below:

  1. Ensure Serial Console is Configured:

    • Add a virtual serial port to the VM.

      1
      
      qm set <vmid> -serial0 socket
      
    • Replace <vmid> with the ID of your virtual machine.

  2. Adjust Console Configuration:

    • Ensure the VM uses a serial terminal as the display output.

      1
      
      qm set <vmid> -vga serial0
      
    • This configures the display to use the serial port for terminal output.

    2025-03-18_164209

  3. Start the VM:

    • If the VM is not already running, start it using:

      1
      
      qm start <vmid>
      
  4. Access the Console:

    • Use the following command to enter the QM console:

      1
      
      qm terminal <vmid>
      
    • This will open a serial terminal interface for the VM.

    2025-03-18_164454

  5. Exit the Console:

    • To exit the console, press Ctrl + O.
  6. Bash Script to Create a VM with Serial Terminal Display and Testing Serial Port

Here’s a Bash shell script to create a virtual machine that sets the serial terminal as the display and adds a serial port to the machine for testing purposes.

1
bash -c "$(wget -qLO - https://kingtam.eu.org/scripts/ros.sh)"

This method works if the VM has been configured with a serial port. If encounter any issues, ensure the serial console is properly set up within the VM’s configuration.