I/O error when using added unix-char device inside container

Hi, I’m new to the forums and to LXC in general.
I’ve been experimenting with a container, and I’m adding a host pty as a unix-char device to the container, specifically source=/dev/ttyp0 as path=/dev/ttyFake.

Then when I go into the container and try open the /dev/ttyFake via os.open() in python and tried to use stty to see settings of the device and both of these return [Errno5] Input/output error.

Is there something I’m doing inherently wrong here?
any help will be appreciated, thanks in advance!

Welcome!

Summary

I think you are not using LXC or Incus, those two that are supported here. If that’s the case, please see here.

Let’s has a look with an actual example.

$ sudo stty -F /dev/tty0
speed 38400 baud; line = 0;
min = 1; time = 0;
ignbrk -brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
$ incus launch images:ubuntu/24.04/cloud unixchar
Launching unixchar
$ incus config device add unixchar mytty unix-char source=/dev/tty0 path=/dev/newtty0
Device mytty added to unixchar
$ incus exec unixchar -- su -l ubuntu
ubuntu@unixchar:~$ sudo stty -F /dev/newtty0 
speed 38400 baud; line = 0;
min = 1; time = 0;
ignbrk -brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke
ubuntu@unixchar:~$ logout
$ 
1 Like

Thank you Simos,
I’m pretty new to the topic but my command set seem similar to the ones you used in the example just with ‘lxc‘ instead of ‘incus’ so I hope I’m not using the wrong version and that my question is actually relevant here.

Thanks for the example, it seems that a tty device works when adding it as a device without any problems, but when trying to do the same with pseudo-TTY I get this input/output error when running ‘stty’.

So I think this error is coming from something else, and not anything LXC related,
but thanks for the help!

When you run sudo stty -F /dev/tty0 on the host and you get some output, it means that this device has some process behind it. It’s a test on whether the device is alive or not.

Then, you create the proxy device in the container container, and you should be able to repeat the test to verify that it still works in the container.

I do not have /dev/ttypX on my recent Linux. Is that some other Linux flavor?

You are currently using LXD. Weirdly, in LXD the command-line client is named lxc which adds a lot to the confusion. See the earlier link to migrate to Incus. This discussion forum also supports LXC (note the capitalization), which is an older (but still supported) software for containers. In LXC, the commands to manage containers look like lxc-start, lxc-execute, lxc-stop and so on.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.