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
Description:
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.

Usage:
lxc console [:] [flags]

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{
                c.state.OS.ExecPath,
                "forkconsole",
                projectPrefix(c.Project(), c.Name()),
                c.state.OS.LxcPath,
                filepath.Join(c.LogPath(), "lxc.conf"),
                "tty=0",      <==============
                "escape=-1"}

        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