How can I attach to other ttys with lxd?

LXD includes the command-line tool ‘lxc’.

‘lxc console’ is supposed to allow a user to attach to the container console.

But what if I have virtual consoles? With lxc-console, you could specify ttys:
lxc-console -n name [ -e escape character ] [ -t ttynum ]

$ lxc console --help
Attach to container consoles

This command allows you to interact with the boot console of a container
as well as retrieve past log entries from it.

lxc console [:] [flags]

–show-log Retrieve the container’s console log

Global Flags:
–debug Show all debug messages
–force-local Force using the local unix socket
-h, --help Print help
-v, --verbose Show all information messages
–version Print version number

The api allows to specify a console number, unfortunately it’s impossible to verify if it works currently since it’s hard coded in lxc client

func (c *containerLXC) Console(terminal *os.File) *exec.Cmd {
        args := []string{
                projectPrefix(c.Project(), c.Name()),
                filepath.Join(c.LogPath(), "lxc.conf"),
                "tty=0",      <==============

        cmd := exec.Cmd{}
        cmd.Path = c.state.OS.ExecPath
        cmd.Args = args
        cmd.Stdin = terminal
        cmd.Stdout = terminal
        cmd.Stderr = terminal
        return &cmd
1 Like

from this post it’s possible to advance that this restriction is by design as LXD developers don’t want these ttys to exist.

1 Like