No login prompt in QEMU serial console

I’m running an Ubuntu Jammy Desktop VM in QEMU. The host system is also Ubuntu Jammy. The command is:

qemu-system-x86_64 
  -nodefaults 
  -machine q35,accel=kvm 
  -cpu host 
  -smp 2 
  -m 2G 
  -chardev vc,id=monitor 
  -mon monitor 
  -serial vc 
  -bios /usr/share/qemu/OVMF.fd 
  -cdrom jammy-desktop-amd64.iso

When I go to the serial console with Ctrl+Alt+2, I can see a GRUB menu there (as expected). Then I hit enter to start the system. From this point on the console remains silent, and there is no login prompt.

I am confused because I used to do exactly the same thing on a Mac (M2) as a host machine, and I always got a login prompt, like here:

enter image description here

Why doesn’t this work on Linux/AMD64?

Asked By: ghik

||

This doesn’t work because nothing told Linux to start a login console there. That is not the default; it’s something Ubuntu does specifically for their bootable ISOs on ARM.

It seems that Ubuntu pre-configure their ARM images to redirect both the bootloader and the Linux console to an available serial port, because often that’s the only output that an ARM-based system has. (It is far more common for users to boot ARM distributions on something like a Raspberry Pi than on a MacBook.)

x86 devices, on the other hand, do not usually have that issue – they always have a firmware-provided text console output available – and that’s what both GRUB and Linux use as their default console. Redirecting to a serial port (which is increasingly rare on x861,2) has never been the default at any time; such configuration is usually left to the user on most distributions.

(In addition, only one device can really be set as the target for /dev/console, so if it is redirected to serial, you wouldn’t have system boot messages on the firmware VGA console (unless the distribution used e.g. Plymouth which can duplicate the messages) – it’d be silent until the login prompt shows up.)

If you have access to the bootloader screen, edit the kernel command line to specify console=ttyS0,115200 to redirect /dev/console; this will make boot output go to the first serial port (COM1). Systemd will then also automatically start a serial-getty@ttyS0 service to provide a login prompt as well.

If you don’t have access to the bootloader screen, you’ll have to modify the ISO image to edit the bootloader configuration (GRUB or more likely Syslinux/isolinux). By doing this you can also add the necessary options to redirect the bootloader itself over serial as well.

With recent systemd versions there is a mechanism to pass additional boot options via DMI data (which Qemu has an option for) but I haven’t investigated that yet. It would help you start a serial-getty service, though not see the rest of the boot process (the mechanism is handled by init, not by the kernel).


1 (Or set to a very slow rate, or redirected to a network, etc. Trying to output data to a nonexistent serial port can sometimes cause problems.)

2 (Rarity aside, it’s also common for x86 systems to have non-terminal devices attached to ttyS0, and I’ve seen quite a few people complain about ModemManager sending probe ‘AT’ commands to their GPS receiver or whatever; similarly Windows famously used to probe all serial ports for mice on every startup, which Linux users also like to make fun out of. So I suspect that sending out "ubuntu login:" by default wouldn’t be well-received.)

Answered By: u1686_grawity
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.