From a02a78a865fc37f7bdea077a4421319b84c635c9 Mon Sep 17 00:00:00 2001 From: Stoiko Ivanov Date: Thu, 16 Nov 2023 16:00:38 +0100 Subject: [PATCH] fix #4747: pass kernel cmdline parameters to target system Parameters needed for booting during installation are best preserved in the target cmdline as well - e.g. if you need a particular cmdline switch for your system to boot at all - not having to add it for the first boot of the installed system and manually adding it to the bootloader config is an improvement. This additionally enables us to drop the console parameter handling for serial consoles (it is just one of the parameters to pass along). Finally it fixes the regular expressions for the installer settings we read from the cmdline (swapsize, maxroot,...) which were broken if added as last entry. Signed-off-by: Stoiko Ivanov --- Proxmox/Install.pm | 11 +++++------ Proxmox/Install/Config.pm | 25 +++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Proxmox/Install.pm b/Proxmox/Install.pm index 66adb2d..c868992 100644 --- a/Proxmox/Install.pm +++ b/Proxmox/Install.pm @@ -1152,11 +1152,10 @@ _EOD } update_progress(0.8, 0.95, 1, "make system bootable"); - my $console_param=''; - if (my $console = Proxmox::Install::Config::get_console()) { - $console_param="console=$console"; - my $console_snippet = "GRUB_CMDLINE_LINUX=\"\$GRUB_CMDLINE_LINUX $console_param\""; - file_write_all("$targetdir/etc/default/grub.d/console.cfg", $console_snippet); + my $target_cmdline=''; + if ($target_cmdline = Proxmox::Install::Config::get_target_cmdline()) { + my $target_cmdline_snippet = "GRUB_CMDLINE_LINUX=\"\$GRUB_CMDLINE_LINUX $target_cmdline\""; + file_write_all("$targetdir/etc/default/grub.d/installer.cfg", $target_cmdline_snippet); } if ($use_zfs) { @@ -1164,7 +1163,7 @@ _EOD my $zfs_snippet = "GRUB_CMDLINE_LINUX=\"\$GRUB_CMDLINE_LINUX root=ZFS=$zfs_pool_name/ROOT/$zfs_root_volume_name boot=zfs\""; file_write_all("$targetdir/etc/default/grub.d/zfs.cfg", $zfs_snippet); - file_write_all("$targetdir/etc/kernel/cmdline", "root=ZFS=$zfs_pool_name/ROOT/$zfs_root_volume_name boot=zfs $console_param\n"); + file_write_all("$targetdir/etc/kernel/cmdline", "root=ZFS=$zfs_pool_name/ROOT/$zfs_root_volume_name boot=zfs $target_cmdline\n"); zfs_setup_module_conf($targetdir); } diff --git a/Proxmox/Install/Config.pm b/Proxmox/Install/Config.pm index 5e80255..b1acebc 100644 --- a/Proxmox/Install/Config.pm +++ b/Proxmox/Install/Config.pm @@ -16,36 +16,37 @@ my sub parse_kernel_cmdline { my $cmdline = Proxmox::Install::RunEnv::get('kernel_cmdline'); - if ($cmdline =~ m/\s(ext4|xfs)(\s.*)?$/) { + if ($cmdline =~ s/\b(ext4|xfs)\s?//i) { $cfg->{filesys} = $1; } - if ($cmdline =~ m/hdsize=(\d+(\.\d+)?)[\s\n]/i) { + if ($cmdline =~ s/\bhdsize=(\d+(\.\d+)?)\s?//i) { $cfg->{hdsize} = $1; } - if ($cmdline =~ m/swapsize=(\d+(\.\d+)?)[\s\n]/i) { + if ($cmdline =~ s/\bswapsize=(\d+(\.\d+)?)\s?//i) { $cfg->{swapsize} = $1; } - if ($cmdline =~ m/maxroot=(\d+(\.\d+)?)[\s\n]/i) { + if ($cmdline =~ s/\bmaxroot=(\d+(\.\d+)?)\s?//i) { $cfg->{maxroot} = $1; } - if ($cmdline =~ m/minfree=(\d+(\.\d+)?)[\s\n]/i) { + if ($cmdline =~ s/\bminfree=(\d+(\.\d+)?)\s?//i) { $cfg->{minfree} = $1; } my $iso_env = Proxmox::Install::ISOEnv::get(); if ($iso_env->{product} eq 'pve') { - if ($cmdline =~ m/maxvz=(\d+(\.\d+)?)[\s\n]/i) { + if ($cmdline =~ s/\bmaxvz=(\d+(\.\d+)?)\s?//i) { $cfg->{maxvz} = $1; } } - if ($cmdline =~ m/console=(\S+)[\s\n]?/i) { - $cfg->{console} = $1; - } + $cmdline =~ s/(?:BOOT_IMAGE|root|ramdisk_size|splash|vga)=\S+\s?//gi; + $cmdline =~ s/ro|rw|quiet|proxdebug|proxtui|nomodeset//gi; + + $cfg->{target_cmdline}= $cmdline; return $cfg; } @@ -101,7 +102,7 @@ my sub init_cfg { cidr => undef, gateway => undef, dns => undef, - console => undef, + target_cmdline => undef, }; $initial = parse_kernel_cmdline($initial); @@ -235,8 +236,8 @@ sub get_gateway { return get('gateway'); } sub set_dns { set_key('dns', $_[0]); } sub get_dns { return get('dns'); } -sub set_console { set_key('console', $_[0]); } -sub get_console { return get('console'); } +sub set_target_cmdline { set_key('target_cmdline', $_[0]); } +sub get_target_cmdline { return get('target_cmdline'); } 1;