[pve-devel] [PATCH kernel-meta] fix #2403: exclude initrd entries from /proc/cmdline

Oguz Bektas o.bektas at proxmox.com
Tue Oct 15 16:39:08 CEST 2019


On Tue, Oct 15, 2019 at 03:54:14PM +0200, Thomas Lamprecht wrote:
> On 10/15/19 3:22 PM, Oguz Bektas wrote:
> > if we fallback to /proc/cmdline, it can include the booted initrd.
> > 
> > to avoid loader entries with (sometimes even multiple) initrd lines,
> > we have to parse them out.
> > 
> > Signed-off-by: Oguz Bektas <o.bektas at proxmox.com>
> > ---
> >  efiboot/zz-pve-efiboot | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/efiboot/zz-pve-efiboot b/efiboot/zz-pve-efiboot
> > index 4756555..5a84af2 100755
> > --- a/efiboot/zz-pve-efiboot
> > +++ b/efiboot/zz-pve-efiboot
> > @@ -50,7 +50,8 @@ update_esps() {
> >  		CMDLINE="$(cat /etc/kernel/cmdline)"
> >  	else
> >  		warn "No /etc/kernel/cmdline found - falling back to /proc/cmdline"
> > -		CMDLINE="$(cat /proc/cmdline)"
> > +		# remove initrd entries
> > +		CMDLINE="$(cat /proc/cmdline | awk '{gsub(/initrd=([0-9a-zA-Z\\.-])*\s/,x)}1')"
> 
> could pontentially match a field which ends with initrd, e.g.,
> noinitrd=foo
> 
> while just an example that still should be caught..
> 
> also, this is a wrong use of cat, you could just do:
> "$(awk '...' /proc/cmdline)"
> 
> not point for the pipe..

sorry my bad
> 
> now if the initrd= is _always_ the first one we could also do:
> "$(cut -d ' ' -f2- /proc/cmdline)"
> 
> but no hard feelings.
that doesnt work because there can be multiple of them

i tested this one and it worked:

$ cat input

noinitrd=foo initrd=\EFI\proxmox\5.0.21-2-pve\initrd.img-5.0.21-2-pve initrd=\EFI\proxmox\5.0.21-2-pve\initrd.img-5.0.21-2-pve initrd=\EFI\proxmox\5.0.21-2-pve\initrd.img-5.0.21-2-pve initrd=\EFI\proxmox\5.0.21-2-pve\initrd.img-5.0.21-2-pve initrd=\EFI\proxmox\5.0.21-1-pve\initrd.img-5.0.21-1-pve root=ZFS=rpool/ROOT/pve-1 boot=zfs

$ awk '{gsub(/\yinitrd=([0-9a-zA-Z\\.-])*\s/,x)}1' input

noinitrd=foo root=ZFS=rpool/ROOT/pve-1 boot=zfs

the '\y' is the awk equivalent of '\b' since awk treats '\b' as the
backspace character...

i'll send a v2




More information about the pve-devel mailing list