#2961 PR open: Copy the console= kernel arguments from the original system

Labels: cleanup, minor bug

jsmeix opened issue at 2023-03-28 12:19:

Overhauled the whole automated serial console setup
for the recovery system in particular
prep/GNU/Linux/200_include_serial_console.sh
and lib/serial-functions.sh which results that
rescue/GNU/Linux/400_use_serial_console.sh is obsolete, see
https://github.com/rear/rear/pull/2749#issuecomment-1196650631

jsmeix commented at 2023-03-28 12:30:

Tomorrow I will do some initial testing.

jsmeix commented at 2023-03-29 10:19:

My first test result of the new default behaviour
(i.e. when no SERIAL_CONSOLE config variables are specified):

I booted the original system (a QEMU/KVM virtual machine)
with artificial (I do not have serial port hardware)
additional kernel 'console' command line options:

... console=ttyS1,9600n8 ... console=ttyS3 ... console=tty0 ...

and got

# dmesg | grep console
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-5.3.18-57-default root=/dev/mapper/system-root console=ttyS1,9600n8 resume=/dev/system/swap console=ttyS3 crashkernel=203M,high console=tty0 mitigations=off
[    0.122561] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-5.3.18-57-default root=/dev/mapper/system-root console=ttyS1,9600n8 resume=/dev/system/swap console=ttyS3 crashkernel=203M,high console=tty0 mitigations=off
[    0.146431] printk: console [tty0] enabled
[    0.219572] printk: console [ttyS1] enabled
[    5.980855] qxl 0000:00:02.0: vgaarb: deactivate vga console

# ls -l /dev/ttyS[0-9]
crw-rw---- 1 root dialout 4, 64 Mar 29 11:10 /dev/ttyS0
crw-rw---- 1 root dialout 4, 65 Mar 29 11:10 /dev/ttyS1
crw-rw---- 1 root dialout 4, 66 Mar 29 11:10 /dev/ttyS2
crw-rw---- 1 root dialout 4, 67 Mar 29 11:10 /dev/ttyS3
crw-rw---- 1 root dialout 4, 68 Mar 29 11:10 /dev/ttyS4
crw-rw---- 1 root dialout 4, 69 Mar 29 11:10 /dev/ttyS5
crw-rw---- 1 root dialout 4, 70 Mar 29 11:10 /dev/ttyS6
crw-rw---- 1 root dialout 4, 71 Mar 29 11:10 /dev/ttyS7
crw-rw---- 1 root dialout 4, 72 Mar 29 11:10 /dev/ttyS8
crw-rw---- 1 root dialout 4, 73 Mar 29 11:10 /dev/ttyS9

# uname -a
Linux localhost 5.3.18-57-default #1 SMP Wed Apr 28 10:54:41 UTC 2021 (ba3c2e9) x86_64 x86_64 x86_64 GNU/Linux

That there is first console [tty0] enabled
and then console [ttyS1] enabled
but no 'console [ttyS3] enabled' matches what
https://www.kernel.org/doc/html/v5.3/admin-guide/serial-console.html
reads (excerpts)

So, for example:

console=ttyS1,9600 console=tty0

defines that opening /dev/console will get you the
current foreground virtual console, and kernel messages
will appear on both the VGA console and
the 2nd serial port (ttyS1 or COM2) at 9600 baud.

Note that you can only define one console
per device type (serial, video).

If no console device is specified, the first device found
capable of acting as a system console will be used.
At this time, the system first looks for a VGA card and
then for a serial port.
So if you don't have a VGA card in your system
the first serial port will automatically become the console.

ReaR on the original system (which runs SLES15 SP3):

# egrep -v '^#|^$' etc/rear/local.conf
FIRMWARE_FILES=( 'no' )
MODULES=( 'loaded_modules' )
PROGRESS_MODE="plain"
PROGRESS_WAIT_SECONDS="5"
OUTPUT=ISO
BACKUP=NETFS
BACKUP_OPTIONS="nfsvers=3,nolock"
BACKUP_URL=nfs://192.168.122.1/nfs
REQUIRED_PROGS+=( snapper chattr )
PROGS+=( lsattr )
COPY_AS_IS+=( /usr/lib/snapper/installation-helper /etc/snapper/config-templates/default )
BACKUP_PROG_INCLUDE=( /boot/grub2/x86_64-efi /boot/grub2/i386-pc /opt /srv /usr/local /root /tmp /var ) 
POST_RECOVERY_SCRIPT=( 'if snapper --no-dbus -r $TARGET_FS_ROOT get-config | grep -q "^QGROUP.*[0-9]/[0-9]" ; then snapper --no-dbus -r $TARGET_FS_ROOT set-config QGROUP= ; snapper --no-dbus -r $TARGET_FS_ROOT setup-quota && echo snapper setup-quota done || echo snapper setup-quota failed ; else echo snapper setup-quota not used ; fi' )
SSH_ROOT_PASSWORD='rear'
USE_DHCLIENT="yes"

# usr/sbin/rear -D mkrescue
...
Using build area: /var/tmp/rear.9suWIs5VRXA4OhL
...
Running 'rescue' stage ======================
Creating recovery system root filesystem skeleton layout
Adding 'console=ttyS1,9600n8' to KERNEL_CMDLINE
Adding 'console=ttyS3' to KERNEL_CMDLINE
Adding 'console=tty0' to KERNEL_CMDLINE
Handling network interface 'eth0'
eth0 is a physical device
Handled network interface 'eth0'
Skipping 'lo': not bound to any physical interface.
skipping usr/share/rear/rescue/GNU/Linux/400_use_serial_console.sh
...

# find /var/tmp/rear.9suWIs5VRXA4OhL -xdev -type f | xargs grep 'console=ttyS1,9600n8'
...
/var/tmp/rear.9suWIs5VRXA4OhL/tmp/isofs/isolinux/isolinux.cfg:
append initrd=initrd.cgz root=/dev/ram0 vga=normal rw  selinux=0 console=ttyS1,9600n8 console=ttyS3 console=tty0
/var/tmp/rear.9suWIs5VRXA4OhL/tmp/isofs/isolinux/isolinux.cfg:
append initrd=initrd.cgz root=/dev/ram0 vga=normal rw  selinux=0 console=ttyS1,9600n8 console=ttyS3 console=tty0 auto_recover

Excerpt from the ReaR log file:

+ source /root/rear.github.master/usr/share/rear/prep/GNU/Linux/200_include_serial_console.sh
...
+++ cat /proc/cmdline
++ for kernel_option in $( cat /proc/cmdline )
++ test BOOT_IMAGE = console
++ for kernel_option in $( cat /proc/cmdline )
++ test root = console
++ for kernel_option in $( cat /proc/cmdline )
++ test console = console
++ USE_SERIAL_CONSOLE=yes
++ COPY_KERNEL_PARAMETERS+=(console)
++ break
+ source_return_code=0

ReaR recovery system on replacement hardware/VM:

RESCUE localhost:~ # dmesg | grep console
[    0.000000] Command line: initrd=initrd.cgz root=/dev/ram0 vga=normal rw  selinux=0 console=ttyS1,9600n8 console=ttyS3 console=tty0 debug BOOT_IMAGE=kernel 
[    0.147923] Kernel command line: initrd=initrd.cgz root=/dev/ram0 vga=normal rw  selinux=0 console=ttyS1,9600n8 console=ttyS3 console=tty0 debug BOOT_IMAGE=kernel 
[    0.278021] printk: console [tty0] enabled
[    0.398808] printk: console [ttyS1] enabled
[    5.186534] qxl 0000:00:02.0: vgaarb: deactivate vga console

All recovery system startup messages appear for me
so the new default behaviour seems in particular to fix
https://github.com/rear/rear/issues/2843

I will verify this in a second test where I do not use
any kernel 'console' command line options...

jsmeix commented at 2023-03-29 11:26:

Second test where I do not use
any kernel 'console' command line options
on the original system:

# dmesg | egrep 'Kernel command line|console'
[    0.149486] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-5.3.18-57-default root=/dev/mapper/system-root resume=/dev/system/swap crashkernel=203M,high mitigations=off
[    0.173618] printk: console [tty0] enabled
[    5.807052] qxl 0000:00:02.0: vgaarb: deactivate vga console

# usr/sbin/rear -D mkrescue
...
Using build area: /var/tmp/rear.Vdrk58sZjJRSsc9
...

# grep 'root=' /var/tmp/rear.Vdrk58sZjJRSsc9/tmp/isofs/isolinux/isolinux.cfg
append initrd=initrd.cgz root=/dev/ram0 vga=normal rw  selinux=0
append initrd=initrd.cgz root=/dev/ram0 vga=normal rw  selinux=0 auto_recover

so there is also no kernel 'console' command line option set
for the ReaR recovery system.

Excerpt from the ReaR log file:

+ source /root/rear.github.master/usr/share/rear/prep/GNU/Linux/200_include_serial_console.sh
...
+++ cat /proc/cmdline
++ for kernel_option in $( cat /proc/cmdline )
++ test BOOT_IMAGE = console
++ for kernel_option in $( cat /proc/cmdline )
++ test root = console
++ for kernel_option in $( cat /proc/cmdline )
++ test resume = console
++ for kernel_option in $( cat /proc/cmdline )
++ test crashkernel = console
++ for kernel_option in $( cat /proc/cmdline )
++ test mitigations = console
+ source_return_code=0

ReaR recovery system on replacement hardware/VM:

RESCUE localhost:~ # dmesg | egrep 'Kernel command line|console'
[    0.132793] Kernel command line: initrd=initrd.cgz root=/dev/ram0 vga=normal rw  selinux=0 BOOT_IMAGE=kernel 
[    0.216293] printk: console [tty0] enabled
[    4.087957] qxl 0000:00:02.0: vgaarb: deactivate vga console

All recovery system startup messages appear for me
so the new default behaviour fixes
https://github.com/rear/rear/issues/2843
in particular when no kernel 'console' command line options
are used on the original system.

jsmeix commented at 2023-04-24 05:57:

This pull request is currently in a not yet finished sate.
I was interrupted to work on this one by other things.
I will continue here as time permits.

schlomo commented at 2023-04-24 07:00:

Ah, sorry. Please kindly set it to draft mode for everybody to see the not-yet-ready state right away.

jsmeix commented at 2023-04-24 07:29:

@schlomo
thank you for the link to the matching GitHub documentation!
(I had noticed that "convert to draft" button since some time
but never found time to find out what that actually means.)


[Export of Github issue for rear/rear.]