4

I'm new to QEMU and playing around with its chardevs. I faced the option called -chardev pty,id=id. So I tried to create a VM with -chardev pty,id=pty0 and got the message.

char device redirected to /dev/pts/9 (label pty0)

So I tried to send some data to it:

root@super-pc:~# cat /dev/pts/9

and didn't see any output.

What is the use case of this chardev?

Some Name
  • 143
  • 4

1 Answers1

2

This is an old question, but for folks who find there way here via google:

Setting up a chardev by itself isn't particularly useful, but if you associate it with a serial device...

-chardev pty,id=char0 -serial chardev=char0

...then you have set up a virtual serial port that connects a serial device in your virtual machine to the corresponding pty device on the host.

For example, if I boot a Linux virtual machine like this:

qemu-system-x86_64 -enable-kvm -smp 1 -m 1024 \
  -drive if=virtio,format=qcow2,file=fedora.cow \
  -netdev user,id=net0 \
  -device virtio-net-pci,netdev=net0 \
  -serial mon:stdio \
  -chardev pty,id=char0 \
  -serial chardev:char0

Then inside the virtual machine, /dev/ttyS0 is the serial console, and /dev/ttyS1 is connected to the PTY device created by the -chardev pty option. Assuming that when booting the virtual machine I see:

char device redirected to /dev/pts/9 (label char0)

Then on the host I can connect a serial communication program to /dev/pts/9:

$ picocom /dev/pts/9

And inside the virtual machine, if I run:

echo hello world > /dev/ttyS1

I will in the output from picocom:

hello world

If I start up a shell on /dev/ttyS1 inside the virtual machine:

bash < /dev/ttyS1 > /dev/ttyS1 2> /dev/ttyS1

Then I can interact with that shell over /dev/pts/9 on the host.

larsks
  • 43,623
  • 14
  • 121
  • 180