Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Feb 2025 19:36:21 -0500
From:      peter garshtja <peter.garshtja@ambient-md.com>
To:        Michael Gmelin <grembo@freebsd.org>
Cc:        Paul Vixie <paul@redbarn.org>, virtualization@freebsd.org,  freebsd-virtualization@freebsd.org
Subject:   Re: bhyve vm and virtio-console
Message-ID:  <CALFUBVHEV=Ee4Wvdhrq622KPnbEv6M8mkFH%2BxZ7nioLrqCmVgw@mail.gmail.com>
In-Reply-To: <CALFUBVE2j54=iDXP=NpbBnrf=aMR2-kD3PLwRkzT0Aaf1Ywfhw@mail.gmail.com>
References:  <9865e8dd-7af9-4cc6-97c7-2e3197c62e62@ambient-md.com> <899331A6-1635-4546-ADE6-FE21B52138FF@freebsd.org> <CALFUBVE2j54=iDXP=NpbBnrf=aMR2-kD3PLwRkzT0Aaf1Ywfhw@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help

[-- Attachment #1 --]
Alright, I was missing the point, in my case if I want to get shell access
via virtio-console then I should have attached getty to that console inside
the guest os, and eventually I expected to see the same behavior as I have
experienced with null modem emulator.

Thx

On Fri, Feb 14, 2025, 18:16 peter garshtja <peter.garshtja@ambient-md.com>
wrote:

> Exactly, I expect to get the shell after I connect with socat, something
> similar to docker exec -it.
>
> On Fri, Feb 14, 2025, 18:10 Michael Gmelin <grembo@freebsd.org> wrote:
>
>>
>>
>> > On 14. Feb 2025, at 23:46, Petru Garstea <peter.garshtja@ambient-md.com>
>> wrote:
>> >
>> > Spinning up the vm with /dev/nmdm* and connecting with cu -l is not an
>> issue on my end.
>> > I am trying to create a vm using freebsd cloud image and connect to
>> guest OS terminal with virtio-console and socat(no X11).
>> > When spawning the vm the unix socket indeed is created, however when I
>> connect to it with socat nothing is being shown(not actions on any terminal
>> commands as well).
>> > Also, I noticed there is a kernel module(virtio_console.ko) and
>> apparently I believe it has to be loaded it, not sure here.
>> >
>> > Please advise,
>> >
>>
>> You can connect to the device inside the vm like I wrote and pass data to
>> the socat connected socket on the outside (this is what I tested, please
>> see my previous email).
>>
>> Are you trying to get some sort of shell over this connection?
>>
>> -m
>>
>>
>> >> On 2/14/25 17:23, Paul Vixie wrote:
>> >> if you want to use cu, you have to use -l to map guest com1 to some
>> host nmdm
>> >> device. if you want to use virtio-console, it will create unix domain
>> sockets
>> >> not pseudo tty endpoints. from bhyve(8) we see:
>> >>
>> >>>                  Virtio console device backends:
>> >>>                                    •
>> >>>                  port1=/path/to/port1.sock[,portN=/path/to/port2.sock
>> ...]
>> >>>                                    A maximum of 16 ports per device
>> can be created.  Every
>> >>>                  port
>> >>>                  is named and corresponds to a Unix domain socket
>> created by
>> >>>                  bhyve.  bhyve accepts at most one connection per
>> port at a
>> >>>                  time.
>> >>>                                    Limitations:
>> >>>                                    •   Due to lack of destructors in
>> bhyve, sockets on the
>> >>>                      filesystem must be cleaned up manually after
>> bhyve
>> >>>                      exits.
>> >>>                                    •   There is no way to use the
>> “console port” feature, nor
>> >>>                      the console port resize at present.
>> >>>                                    •   Emergency write is advertised,
>> but no-op at present.
>> >> i know of no host-side client which will connect to these unix domain
>> sockets
>> >> and offer a cu-like user interface. "unidirectional" may be the
>> experience
>> >> you'll get from "socat".
>> >>
>> >> if what you're trying to accomplish is a graphical console,
>> virtio-console is
>> >> not the way to do it. rather, you'll want "fbuf" to create a guest
>> VGA/similar
>> >> that gateways to a host VNC.
>> >>
>> >> re:
>> >>
>> >>> On Friday, February 14, 2025 9:55:23 PM UTC Petru Garstea wrote:
>> >>> I tried with the following command, and got the same result.
>> >>>
>> >>> */usr/sbin/bhyve -H -P -A -c 1 -m 1500M \
>> >>> -s 0,hostbridge \
>> >>> -s 6,virtio-console,0=/tmp/vtcon.0 \
>> >>> -s 31,lpc \
>> >>> -l bootrom,/tmp/BHYVE_UEFI.fd \
>> >>> -s 1,virtio-blk,/tmp/fbsd.img \
>> >>> -s 2,virtio-net,tap0 \
>> >>> tmp*
>> >>>
>> >>>
>> >>> I also able to connect but the bidirectional connection is not
>> happening
>> >>>
>> >>> *socat - UNIX-CONNECT:/tmp/vtcon.0
>> >>> ls
>> >>> *
>> >>> PS: if I use null modem emulation instead virtio-console, then
>> >>> connecting with cu is not an issue.
>> >>>
>> >>> any ideas ?
>> >>>
>> >>> Thanks
>> >>>
>> >>> On 2/14/25 14:57, Michael Gmelin wrote:
>> >>>> On Fri, 14 Feb 2025 14:21:07 -0500
>> >>>>
>> >>>> Petru Garstea<peter.garshtja@ambient-md.com> wrote:
>> >>>>> Hi,
>> >>>>> I am trying to configure bhyve vm with support of virtio-console,
>> the
>> >>>>> following option is added to bhyve command line
>> >>>>>
>> >>>>> *-s 3,virtio-console,port1=/test/console.sock
>> >>>>>
>> >>>>> *However when trying to connect to socket with socat trere are no
>> >>>>> input/ouptut is observed.
>> >>>>>
>> >>>>> Has virtio-console ever worked ?
>> >>>> Yes it works, I just tried it using sysutils/vm-bhyve (just add
>> >>>> virt_console0="Yes" to the configuration file).
>> >>>>
>> >>>> Based on the logs, these device settings are used by it:
>> >>>>      bhyve devices:
>> >>>>        -s 0,hostbridge \
>> >>>>        -s 31,lpc \
>> >>>>        -s 4:0,virtio-blk,/dev/zvol/zroot/vms/freebsd14-test/disk0 \
>> >>>>        -s 5:0,virtio-net,tap0,mac=58:9c:fc:aa:aa:aa \
>> >>>>        -s 6:0,virtio-console,0=/vms/freebsd14-test/vtcon.0
>> >>>>
>> >>>> I could connect to /vms/freebsd14-test/vtcon.0 using socat:
>> >>>>      socat - UNIX-CONNECT:/vms/freebsd14-test/vtcon.0
>> >>>>
>> >>>> Inside the vm it's /dev/vtcon/0.
>> >>>>
>> >>>> -m
>> >>
>> >
>>
>>

[-- Attachment #2 --]
<div dir="auto">Alright, I was missing the point, in my case if I want to get shell access via virtio-console then I should have attached getty to that console inside the guest os, and eventually I expected to see the same behavior as I have experienced with null modem emulator.<div dir="auto"><br></div><div dir="auto">Thx</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Fri, Feb 14, 2025, 18:16 peter garshtja &lt;<a href="mailto:peter.garshtja@ambient-md.com">peter.garshtja@ambient-md.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">Exactly, I expect to get the shell after I connect with socat, something similar to docker exec -it. </div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 14, 2025, 18:10 Michael Gmelin &lt;<a href="mailto:grembo@freebsd.org" target="_blank" rel="noreferrer">grembo@freebsd.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
&gt; On 14. Feb 2025, at 23:46, Petru Garstea &lt;<a href="mailto:peter.garshtja@ambient-md.com" rel="noreferrer noreferrer" target="_blank">peter.garshtja@ambient-md.com</a>&gt; wrote:<br>
&gt; <br>
&gt; Spinning up the vm with /dev/nmdm* and connecting with cu -l is not an issue on my end.<br>
&gt; I am trying to create a vm using freebsd cloud image and connect to guest OS terminal with virtio-console and socat(no X11).<br>
&gt; When spawning the vm the unix socket indeed is created, however when I connect to it with socat nothing is being shown(not actions on any terminal commands as well).<br>
&gt; Also, I noticed there is a kernel module(virtio_console.ko) and apparently I believe it has to be loaded it, not sure here.<br>
&gt; <br>
&gt; Please advise,<br>
&gt; <br>
<br>
You can connect to the device inside the vm like I wrote and pass data to the socat connected socket on the outside (this is what I tested, please see my previous email).<br>
<br>
Are you trying to get some sort of shell over this connection?<br>
<br>
-m<br>
<br>
<br>
&gt;&gt; On 2/14/25 17:23, Paul Vixie wrote:<br>
&gt;&gt; if you want to use cu, you have to use -l to map guest com1 to some host nmdm<br>
&gt;&gt; device. if you want to use virtio-console, it will create unix domain sockets<br>
&gt;&gt; not pseudo tty endpoints. from bhyve(8) we see:<br>
&gt;&gt; <br>
&gt;&gt;&gt;                  Virtio console device backends:<br>
&gt;&gt;&gt;                                    •<br>
&gt;&gt;&gt;                  port1=/path/to/port1.sock[,portN=/path/to/port2.sock ...]<br>
&gt;&gt;&gt;                                    A maximum of 16 ports per device can be created.  Every<br>
&gt;&gt;&gt;                  port<br>
&gt;&gt;&gt;                  is named and corresponds to a Unix domain socket created by<br>
&gt;&gt;&gt;                  bhyve.  bhyve accepts at most one connection per port at a<br>
&gt;&gt;&gt;                  time.<br>
&gt;&gt;&gt;                                    Limitations:<br>
&gt;&gt;&gt;                                    •   Due to lack of destructors in bhyve, sockets on the<br>
&gt;&gt;&gt;                      filesystem must be cleaned up manually after bhyve<br>
&gt;&gt;&gt;                      exits.<br>
&gt;&gt;&gt;                                    •   There is no way to use the “console port” feature, nor<br>
&gt;&gt;&gt;                      the console port resize at present.<br>
&gt;&gt;&gt;                                    •   Emergency write is advertised, but no-op at present.<br>
&gt;&gt; i know of no host-side client which will connect to these unix domain sockets<br>
&gt;&gt; and offer a cu-like user interface. &quot;unidirectional&quot; may be the experience<br>
&gt;&gt; you&#39;ll get from &quot;socat&quot;.<br>
&gt;&gt; <br>
&gt;&gt; if what you&#39;re trying to accomplish is a graphical console, virtio-console is<br>
&gt;&gt; not the way to do it. rather, you&#39;ll want &quot;fbuf&quot; to create a guest VGA/similar<br>
&gt;&gt; that gateways to a host VNC.<br>
&gt;&gt; <br>
&gt;&gt; re:<br>
&gt;&gt; <br>
&gt;&gt;&gt; On Friday, February 14, 2025 9:55:23 PM UTC Petru Garstea wrote:<br>
&gt;&gt;&gt; I tried with the following command, and got the same result.<br>
&gt;&gt;&gt; <br>
&gt;&gt;&gt; */usr/sbin/bhyve -H -P -A -c 1 -m 1500M \<br>
&gt;&gt;&gt; -s 0,hostbridge \<br>
&gt;&gt;&gt; -s 6,virtio-console,0=/tmp/vtcon.0 \<br>
&gt;&gt;&gt; -s 31,lpc \<br>
&gt;&gt;&gt; -l bootrom,/tmp/BHYVE_UEFI.fd \<br>
&gt;&gt;&gt; -s 1,virtio-blk,/tmp/fbsd.img \<br>
&gt;&gt;&gt; -s 2,virtio-net,tap0 \<br>
&gt;&gt;&gt; tmp*<br>
&gt;&gt;&gt; <br>
&gt;&gt;&gt; <br>
&gt;&gt;&gt; I also able to connect but the bidirectional connection is not happening<br>
&gt;&gt;&gt; <br>
&gt;&gt;&gt; *socat - UNIX-CONNECT:/tmp/vtcon.0<br>
&gt;&gt;&gt; ls<br>
&gt;&gt;&gt; *<br>
&gt;&gt;&gt; PS: if I use null modem emulation instead virtio-console, then<br>
&gt;&gt;&gt; connecting with cu is not an issue.<br>
&gt;&gt;&gt; <br>
&gt;&gt;&gt; any ideas ?<br>
&gt;&gt;&gt; <br>
&gt;&gt;&gt; Thanks<br>
&gt;&gt;&gt; <br>
&gt;&gt;&gt; On 2/14/25 14:57, Michael Gmelin wrote:<br>
&gt;&gt;&gt;&gt; On Fri, 14 Feb 2025 14:21:07 -0500<br>
&gt;&gt;&gt;&gt; <br>
&gt;&gt;&gt;&gt; Petru Garstea&lt;<a href="mailto:peter.garshtja@ambient-md.com" rel="noreferrer noreferrer" target="_blank">peter.garshtja@ambient-md.com</a>&gt; wrote:<br>
&gt;&gt;&gt;&gt;&gt; Hi,<br>
&gt;&gt;&gt;&gt;&gt; I am trying to configure bhyve vm with support of virtio-console, the<br>
&gt;&gt;&gt;&gt;&gt; following option is added to bhyve command line<br>
&gt;&gt;&gt;&gt;&gt; <br>
&gt;&gt;&gt;&gt;&gt; *-s 3,virtio-console,port1=/test/console.sock<br>
&gt;&gt;&gt;&gt;&gt; <br>
&gt;&gt;&gt;&gt;&gt; *However when trying to connect to socket with socat trere are no<br>
&gt;&gt;&gt;&gt;&gt; input/ouptut is observed.<br>
&gt;&gt;&gt;&gt;&gt; <br>
&gt;&gt;&gt;&gt;&gt; Has virtio-console ever worked ?<br>
&gt;&gt;&gt;&gt; Yes it works, I just tried it using sysutils/vm-bhyve (just add<br>
&gt;&gt;&gt;&gt; virt_console0=&quot;Yes&quot; to the configuration file).<br>
&gt;&gt;&gt;&gt; <br>
&gt;&gt;&gt;&gt; Based on the logs, these device settings are used by it:<br>
&gt;&gt;&gt;&gt;      bhyve devices:<br>
&gt;&gt;&gt;&gt;        -s 0,hostbridge \<br>
&gt;&gt;&gt;&gt;        -s 31,lpc \<br>
&gt;&gt;&gt;&gt;        -s 4:0,virtio-blk,/dev/zvol/zroot/vms/freebsd14-test/disk0 \<br>
&gt;&gt;&gt;&gt;        -s 5:0,virtio-net,tap0,mac=58:9c:fc:aa:aa:aa \<br>
&gt;&gt;&gt;&gt;        -s 6:0,virtio-console,0=/vms/freebsd14-test/vtcon.0<br>
&gt;&gt;&gt;&gt; <br>
&gt;&gt;&gt;&gt; I could connect to /vms/freebsd14-test/vtcon.0 using socat:<br>
&gt;&gt;&gt;&gt;      socat - UNIX-CONNECT:/vms/freebsd14-test/vtcon.0<br>
&gt;&gt;&gt;&gt; <br>
&gt;&gt;&gt;&gt; Inside the vm it&#39;s /dev/vtcon/0.<br>
&gt;&gt;&gt;&gt; <br>
&gt;&gt;&gt;&gt; -m<br>
&gt;&gt; <br>
&gt; <br>
<br>
</blockquote></div>
</blockquote></div>

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CALFUBVHEV=Ee4Wvdhrq622KPnbEv6M8mkFH%2BxZ7nioLrqCmVgw>