Enable Serial Console on Boot: Difference between revisions
(→Enabling a login console: SIGHUB only reloads the inittab) |
|||
(25 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
== How to Enable the Serial Console on Boot (1.10.x)== | ==Syslinux / Extlinux== | ||
=== How to Enable the Serial Console on Boot (1.10.x)=== | |||
When using syslinux to boot, you'll need to modify the syslinux.cfg file in the root directory of the boot device. If using a disk-based Alpine, modify the /boot/extlinux.cfg file. | When using syslinux to boot, you'll need to modify the syslinux.cfg file in the root directory of the boot device. If using a disk-based Alpine, modify the /boot/extlinux.cfg file. | ||
Line 8: | Line 9: | ||
* optionally, remove <tt>quiet</tt> from the <tt>append </tt> parameter | * optionally, remove <tt>quiet</tt> from the <tt>append </tt> parameter | ||
=== Example syslinux.cfg === | ==== Example syslinux.cfg ==== | ||
<pre> | <pre> | ||
Line 21: | Line 22: | ||
=== | === extlinux.conf (3.0+)=== | ||
The /etc/update-extlinux.conf is read by the update-extlinux utility. | The /etc/update-extlinux.conf is read by the update-extlinux utility. | ||
To do so, change the default entry: | To do so, change the default entry: | ||
default_kernel_opts="quiet" | <pre>default_kernel_opts="quiet"</pre> | ||
to read like this: | to read like this: | ||
default_kernel_opts="console= | <pre>default_kernel_opts="console=ttyS0,9600 quiet"</pre> | ||
Set the serial port and baud rate to match the default_kernel_opts line above: | |||
<pre>serial_port=0 | |||
serial_baud=9600</pre> | |||
==== Xen ==== | |||
Notice, if you want to use this for a Xen VM, | Notice, if you want to use this for a Xen VM, | ||
you need to configure the speed at 115200 bps and enable the | you need to configure the speed at '''115200''' bps and enable the | ||
<pre>serial="pty"</pre> | |||
setting in the VM config file. | |||
---- | |||
Xen can be configured to use and log to a serial console by editing /etc/update-extlinux.conf to include the following lines: | |||
<pre> | |||
default_kernel_opts="console=hvc0 earlyprintk=xen nomodeset" | |||
xen_opts="dom0_mem=256M com1=115200,8n1 console=com1" | |||
</pre> | |||
See the [https://wiki.xenproject.org/wiki/Xen_Serial_Console Xen wiki] for more details. | |||
==== qemu ==== | |||
Like Xen, qemu should run at speed 115200. | |||
Conveniently, the alpine "virt" image (but not the "standard" image) comes with this all configured on the default ISO. | |||
Sample command to run qemu on alpine-virt with a serial console: | |||
<pre> | |||
qemu-system-x86_64 -accel kvm -cdrom alpine-virt-3.16.0-x86_64.iso -display none -chardev stdio,id=char0,logfile=serial.log,signal=off -serial chardev:char0 | |||
</pre> | |||
Note that this example command uses the logfile option to log the output of the serial console; you can remove this if you don't need it. | |||
==== Example /boot/extlinux.conf ==== | |||
This is a complete file, written by the update-extlinux command. | |||
<pre> | <pre> | ||
DEFAULT menu.c32 | DEFAULT menu.c32 | ||
Line 41: | Line 73: | ||
MENU TITLE Alpine/Linux Boot Menu | MENU TITLE Alpine/Linux Boot Menu | ||
MENU AUTOBOOT Alpine will be booted automatically in # seconds. | MENU AUTOBOOT Alpine will be booted automatically in # seconds. | ||
SERIAL 0 | SERIAL 0 9600 | ||
TIMEOUT 100 | TIMEOUT 100 | ||
LABEL grsec | LABEL grsec | ||
Line 48: | Line 80: | ||
LINUX vmlinuz-3.10.33-0-grsec | LINUX vmlinuz-3.10.33-0-grsec | ||
INITRD initramfs-3.10.33-0-grsec | INITRD initramfs-3.10.33-0-grsec | ||
APPEND root=UUID=re-mov-ed-uu-id modules=sd-mod,usb-storage,ext4 console=ttyS0, | APPEND root=UUID=re-mov-ed-uu-id modules=sd-mod,usb-storage,ext4 console=ttyS0,9600 | ||
MENU SEPARATOR | MENU SEPARATOR | ||
</pre> | </pre> | ||
Please: adjust the tty speed to | Please: adjust the tty speed to 115200 if needed (Xen/qemu!!). | ||
The timeout is given in | |||
The timeout is given in deciseconds, so this would be a 10 second timeout.[https://wiki.syslinux.org/wiki/index.php?title=Config#TIMEOUT] A timeout of 0 does not boot without delay, but rather waits indefinitely for the user. | |||
If the file is read by pygrub, the same value is interpreted as seconds, resulting in a 100s bootup delay per VM. | |||
==Grub== | |||
If you're using Grub as your bootloader, follow this section. | |||
Edit <tt>/etc/default/grub</tt> and add the following lines (assuming you're using the first serial port at 115200 baud rate): | |||
<pre> | |||
GRUB_TERMINAL="serial console" | |||
GRUB_SERIAL_COMMAND="serial --unit=0 --word=8 --parity=no --speed 115200 --stop=1" | |||
</pre> | |||
Also add <tt>console=ttyS0,115200n8d</tt> to the <tt>GRUB_CMDLINE_LINUX_DEFAULT</tt> variable | |||
Your <tt>/etc/default/grub</tt> should now look something like this: | |||
<pre> | |||
GRUB_TIMEOUT=2 | |||
GRUB_DISABLE_SUBMENU=y | |||
GRUB_DISABLE_RECOVERY=true | |||
GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200n8d modules=sd-mod,usb-storage,xfs quiet rootfstype=xfs" | |||
GRUB_TERMINAL="serial console" | |||
GRUB_SERIAL_COMMAND="serial --unit=0 --word=8 --parity=no --speed 115200 --stop=1" | |||
</pre> | |||
Now, regenerate your grub.cfg with the following command: | |||
<pre> | |||
grub-mkconfig -o /boot/grub/grub.cfg | |||
</pre> | |||
Follow the final 2 steps below: <tt>Enabling a login console</tt> and <tt>Add your serial console to the trusted local terminal list</tt> | |||
== Enabling a login console == | |||
This is done in /etc/inittab. There is commented entry for ttyS0. Just enable it. | |||
<pre> | |||
# Put a getty on the serial port | |||
ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100 | |||
</pre> | |||
To start the getty, reload the inittab: | |||
<pre> | |||
kill -HUP 1 | |||
</pre> | |||
== Enabling two consoles during boot == | |||
It's possible to output to both the serial and vga console during the system boot. | |||
<PRE> | |||
append "quiet console=ttyS0,9600 console=tty0" | |||
</PRE> | |||
Not known how to do the same thing in the extlinux menu. | |||
You might find a starting point in this thread: http://patchwork.openembedded.org/patch/45175/ | |||
== Add your serial console to the trusted local terminal list == | |||
If you face the problem that the login prompt always refuses your password when you use serial console, you missed this entry. | |||
Add this to the <tt>/etc/securetty</tt> file: | |||
<PRE> | |||
ttyS0 | |||
</PRE> | |||
[[Category:Booting]] | [[Category:Booting]] | ||
[[Category:Installation]] | [[Category:Installation]] |
Latest revision as of 10:11, 29 February 2024
Syslinux / Extlinux
How to Enable the Serial Console on Boot (1.10.x)
When using syslinux to boot, you'll need to modify the syslinux.cfg file in the root directory of the boot device. If using a disk-based Alpine, modify the /boot/extlinux.cfg file.
Add the following:
- serial 0 9600
- add console=ttyS0,9600 to the append parameter
- optionally, remove quiet from the append parameter
Example syslinux.cfg
serial 0 9600 timeout 20 prompt 1 default grsec label grsec kernel /boot/grsec append initrd=/boot/grsec.gz alpine_dev=sda1:vfat modules=sd-mod,usb-storage console=ttyS0,9600
extlinux.conf (3.0+)
The /etc/update-extlinux.conf is read by the update-extlinux utility.
To do so, change the default entry:
default_kernel_opts="quiet"
to read like this:
default_kernel_opts="console=ttyS0,9600 quiet"
Set the serial port and baud rate to match the default_kernel_opts line above:
serial_port=0 serial_baud=9600
Xen
Notice, if you want to use this for a Xen VM, you need to configure the speed at 115200 bps and enable the
serial="pty"
setting in the VM config file.
Xen can be configured to use and log to a serial console by editing /etc/update-extlinux.conf to include the following lines:
default_kernel_opts="console=hvc0 earlyprintk=xen nomodeset" xen_opts="dom0_mem=256M com1=115200,8n1 console=com1"
See the Xen wiki for more details.
qemu
Like Xen, qemu should run at speed 115200.
Conveniently, the alpine "virt" image (but not the "standard" image) comes with this all configured on the default ISO.
Sample command to run qemu on alpine-virt with a serial console:
qemu-system-x86_64 -accel kvm -cdrom alpine-virt-3.16.0-x86_64.iso -display none -chardev stdio,id=char0,logfile=serial.log,signal=off -serial chardev:char0
Note that this example command uses the logfile option to log the output of the serial console; you can remove this if you don't need it.
Example /boot/extlinux.conf
This is a complete file, written by the update-extlinux command.
DEFAULT menu.c32 PROMPT 0 MENU TITLE Alpine/Linux Boot Menu MENU AUTOBOOT Alpine will be booted automatically in # seconds. SERIAL 0 9600 TIMEOUT 100 LABEL grsec MENU DEFAULT MENU LABEL Linux 3.10.33-0-grsec LINUX vmlinuz-3.10.33-0-grsec INITRD initramfs-3.10.33-0-grsec APPEND root=UUID=re-mov-ed-uu-id modules=sd-mod,usb-storage,ext4 console=ttyS0,9600 MENU SEPARATOR
Please: adjust the tty speed to 115200 if needed (Xen/qemu!!).
The timeout is given in deciseconds, so this would be a 10 second timeout.[1] A timeout of 0 does not boot without delay, but rather waits indefinitely for the user.
If the file is read by pygrub, the same value is interpreted as seconds, resulting in a 100s bootup delay per VM.
Grub
If you're using Grub as your bootloader, follow this section. Edit /etc/default/grub and add the following lines (assuming you're using the first serial port at 115200 baud rate):
GRUB_TERMINAL="serial console" GRUB_SERIAL_COMMAND="serial --unit=0 --word=8 --parity=no --speed 115200 --stop=1"
Also add console=ttyS0,115200n8d to the GRUB_CMDLINE_LINUX_DEFAULT variable
Your /etc/default/grub should now look something like this:
GRUB_TIMEOUT=2 GRUB_DISABLE_SUBMENU=y GRUB_DISABLE_RECOVERY=true GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200n8d modules=sd-mod,usb-storage,xfs quiet rootfstype=xfs" GRUB_TERMINAL="serial console" GRUB_SERIAL_COMMAND="serial --unit=0 --word=8 --parity=no --speed 115200 --stop=1"
Now, regenerate your grub.cfg with the following command:
grub-mkconfig -o /boot/grub/grub.cfg
Follow the final 2 steps below: Enabling a login console and Add your serial console to the trusted local terminal list
Enabling a login console
This is done in /etc/inittab. There is commented entry for ttyS0. Just enable it.
# Put a getty on the serial port ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100
To start the getty, reload the inittab:
kill -HUP 1
Enabling two consoles during boot
It's possible to output to both the serial and vga console during the system boot.
append "quiet console=ttyS0,9600 console=tty0"
Not known how to do the same thing in the extlinux menu. You might find a starting point in this thread: http://patchwork.openembedded.org/patch/45175/
Add your serial console to the trusted local terminal list
If you face the problem that the login prompt always refuses your password when you use serial console, you missed this entry.
Add this to the /etc/securetty file:
ttyS0