libvirt serial console on non-x86 platforms

Leigh Brown posted 1 patch 1 week ago
Failed in applying to current master (apply log)
libvirt serial console on non-x86 platforms
Posted by Leigh Brown 1 week ago
Hi Daniel,

On a whim, I tried installing libvirt on a Raspberry Pi 5. I was
pleasantly surprised to find that it all worked, apart from one small
wrinkle.

I typically use virt-install and set up a serial console, but this
failed with the error:

ERROR    unsupported configuration: BIOS serial console only supported
on x86 architectures

I created the VM with a graphical console then manually adjusted the
config afterwards to use a serial console and it all worked fine. After
a bit of digging I saw an email[1] from yourself talking about how
graphics=off has semantic effects beyond just controlling whether the
firmware prints to the serial or not.  After a bit more digging, I
found out that Qemu 8.0[2] removed the sga device due to SeaBIOS 1.11.0
and newer supporting this feature natively when QEMU is started with the
option -M graphics=off.

I made the following small patch against the Debian package:

--- libvirt-11.3.0.orig/src/qemu/qemu_validate.c
+++ libvirt-11.3.0/src/qemu/qemu_validate.c
@@ -1304,15 +1304,7 @@ qemuValidateDomainDef(const virDomainDef
          /* On x86 -machine graphics=off toggles the use of the
           * serial console in SeaBIOS (and theoretically other
           * firmwares).
-         * On non-x86, it has also sorts of other effects
-         * on QEMU device models created and so we don't
-         * want to allow its use.
           */
-        if (!ARCH_IS_X86(def->os.arch)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("BIOS serial console only supported on x86 
architectures"));
-            return -1;
-        }
          if (!def->nserials) {
              virReportError(VIR_ERR_XML_ERROR, "%s",
                             _("need at least one serial port to use BIOS 
serial output"));

With that change, I can now create VMs with a serial console through
virt-install on the Raspberry PI 5.

Have I got this right? If so, I'm happy to submit the patch.

Regards,

Leigh.

--
[1] https://mail.gnu.org/archive/html/qemu-devel/2021-09/msg02417.html
[2] https://wiki.qemu.org/ChangeLog/8.0
Re: libvirt serial console on non-x86 platforms
Posted by Daniel P. Berrangé via Devel 6 days, 21 hours ago
On Fri, Nov 14, 2025 at 08:58:11AM +0000, Leigh Brown wrote:
> Hi Daniel,
> 
> On a whim, I tried installing libvirt on a Raspberry Pi 5. I was
> pleasantly surprised to find that it all worked, apart from one small
> wrinkle.
> 
> I typically use virt-install and set up a serial console, but this
> failed with the error:
> 
> ERROR    unsupported configuration: BIOS serial console only supported
> on x86 architectures
> 
> I created the VM with a graphical console then manually adjusted the
> config afterwards to use a serial console and it all worked fine. After
> a bit of digging I saw an email[1] from yourself talking about how
> graphics=off has semantic effects beyond just controlling whether the
> firmware prints to the serial or not.  After a bit more digging, I
> found out that Qemu 8.0[2] removed the sga device due to SeaBIOS 1.11.0
> and newer supporting this feature natively when QEMU is started with the
> option -M graphics=off.



> 
> --- libvirt-11.3.0.orig/src/qemu/qemu_validate.c
> +++ libvirt-11.3.0/src/qemu/qemu_validate.c
> @@ -1304,15 +1304,7 @@ qemuValidateDomainDef(const virDomainDef
>          /* On x86 -machine graphics=off toggles the use of the
>           * serial console in SeaBIOS (and theoretically other
>           * firmwares).
> -         * On non-x86, it has also sorts of other effects
> -         * on QEMU device models created and so we don't
> -         * want to allow its use.
>           */
> -        if (!ARCH_IS_X86(def->os.arch)) {
> -            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> -                           _("BIOS serial console only supported on x86
> architectures"));
> -            return -1;
> -        }
>          if (!def->nserials) {
>              virReportError(VIR_ERR_XML_ERROR, "%s",
>                             _("need at least one serial port to use BIOS
> serial output"));
> 
> With that change, I can now create VMs with a serial console through
> virt-install on the Raspberry PI 5.
> 
> Have I got this right? If so, I'm happy to submit the patch.

This code is specifically only about a config setting for enabling
the BIOS to output its boot message/menus on the serial console.
It is independent of the broader serial console concept - a guest
OS can still be configured with a serial console without the above
change.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Re: libvirt serial console on non-x86 platforms
Posted by Leigh Brown 6 days, 19 hours ago
Hi Daniel,
On 2025-11-14 12:48, Daniel P. Berrangé wrote:
> On Fri, Nov 14, 2025 at 08:58:11AM +0000, Leigh Brown wrote:
[...]

>> --- libvirt-11.3.0.orig/src/qemu/qemu_validate.c
>> +++ libvirt-11.3.0/src/qemu/qemu_validate.c
>> @@ -1304,15 +1304,7 @@ qemuValidateDomainDef(const virDomainDef
>>          /* On x86 -machine graphics=off toggles the use of the
>>           * serial console in SeaBIOS (and theoretically other
>>           * firmwares).
>> -         * On non-x86, it has also sorts of other effects
>> -         * on QEMU device models created and so we don't
>> -         * want to allow its use.
>>           */
>> -        if (!ARCH_IS_X86(def->os.arch)) {
>> -            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
>> -                           _("BIOS serial console only supported on 
>> x86
>> architectures"));
>> -            return -1;
>> -        }
>>          if (!def->nserials) {
>>              virReportError(VIR_ERR_XML_ERROR, "%s",
>>                             _("need at least one serial port to use 
>> BIOS
>> serial output"));
>> 
>> With that change, I can now create VMs with a serial console through
>> virt-install on the Raspberry PI 5.
>> 
>> Have I got this right? If so, I'm happy to submit the patch.
> 
> This code is specifically only about a config setting for enabling
> the BIOS to output its boot message/menus on the serial console.
> It is independent of the broader serial console concept - a guest
> OS can still be configured with a serial console without the above
> change.

Sorry I wasn't 100% clear. With the change I am also able to use serial
for the BIOS[1] and Grub[2]. Although the grub output is not quite right
it works well enough to select an entry.

Regards,

Leigh.

-- 
[1] https://www.solinno.co.uk/public/leigh/rpi5_kvm_serial_bios.png
[2] https://www.solinno.co.uk/public/leigh/rpi5_kvm_serial_grub.png
Re: libvirt serial console on non-x86 platforms
Posted by Daniel P. Berrangé via Devel 6 days, 19 hours ago
On Fri, Nov 14, 2025 at 02:05:18PM +0000, Leigh Brown wrote:
> Hi Daniel,
> On 2025-11-14 12:48, Daniel P. Berrangé wrote:
> > On Fri, Nov 14, 2025 at 08:58:11AM +0000, Leigh Brown wrote:
> [...]
> 
> > > --- libvirt-11.3.0.orig/src/qemu/qemu_validate.c
> > > +++ libvirt-11.3.0/src/qemu/qemu_validate.c
> > > @@ -1304,15 +1304,7 @@ qemuValidateDomainDef(const virDomainDef
> > >          /* On x86 -machine graphics=off toggles the use of the
> > >           * serial console in SeaBIOS (and theoretically other
> > >           * firmwares).
> > > -         * On non-x86, it has also sorts of other effects
> > > -         * on QEMU device models created and so we don't
> > > -         * want to allow its use.
> > >           */
> > > -        if (!ARCH_IS_X86(def->os.arch)) {
> > > -            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> > > -                           _("BIOS serial console only supported on
> > > x86
> > > architectures"));
> > > -            return -1;
> > > -        }
> > >          if (!def->nserials) {
> > >              virReportError(VIR_ERR_XML_ERROR, "%s",
> > >                             _("need at least one serial port to use
> > > BIOS
> > > serial output"));
> > > 
> > > With that change, I can now create VMs with a serial console through
> > > virt-install on the Raspberry PI 5.
> > > 
> > > Have I got this right? If so, I'm happy to submit the patch.
> > 
> > This code is specifically only about a config setting for enabling
> > the BIOS to output its boot message/menus on the serial console.
> > It is independent of the broader serial console concept - a guest
> > OS can still be configured with a serial console without the above
> > change.
> 
> Sorry I wasn't 100% clear. With the change I am also able to use serial
> for the BIOS[1] and Grub[2]. Although the grub output is not quite right
> it works well enough to select an entry.

So the above code you're removing is related to the XML config

 <bios useserial='yes' />

This was originally added for SeaBIOS since it needed an explicit
opt-in for using serial output, via the side-loaded sgabios.

Recent SeaBIOS no longer needs sgabios, so useserial is obsolete.

For non-x86, or x86 with EFI, we have no control knobs. Either the
firmware used will output to the serial console or it won't, so
the 'useserial=yes' config serves no purpose, which is why the
above code rejects it.

IOW, if you delete 'useserial=yes' from your guest XML it should
all still work fine AFAIR


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

Re: libvirt serial console on non-x86 platforms
Posted by Leigh Brown 3 days, 12 hours ago
Hi Daniel,
On 2025-11-14 14:16, Daniel P. Berrangé wrote:
[...]
> IOW, if you delete 'useserial=yes' from your guest XML it should
> all still work fine AFAIR

You're right! After confirming that, I fiddled around with my
virt-install script and am now able to create a vm using a
serial console, with no graphics and without needing any
patches.

Thanks for your help.

Cheers,

Leigh.