Skip to contentSkip to conversation

Grub xen_pvh platform does not seem to support uncompressed kernels

DISCUSSION Andy Smith 2 participants 6 messages Nov 2, 2020

lore
Share & tools
lore

Andy Smith

author
#0 lore raw

Hi,

[ xen-users in CC as I know a few there are using a decompressed
kernel workaround for LZ4 and might be hit by this too ]

I'm currently evaluating switching from booting Xen guests with grub Xen PV (grub-mkimage -O x86_64-xen) to Xen PVH (grub-mkimage -O i386-xen_pvh). I've noticed that a decompressed guest kernel refuses to boot under PVH with the following error:

Loading Linux 5.4.0-52-generic ...
error: invalid magic number.

That same kernel boots with PV.

If I use the LZ4-compressed version of that kernel as supplied by the distribution (Ubuntu 20.04), it works PVH. I therefore can only conclude that PVH grub doesn't like kernels with no compression. Is that expected?

I suppose it is possible that the method I use to decompress the kernel could be wrong, though as I say, it does work with PV grub. I basically use the extract-vmlinux script from the upstream kernel source¹.

When decompressed:

$ sudo file /boot/vmlinuz-5.4.0-52-generic
/boot/vmlinuz-5.4.0-52-generic: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=d435b2b7b13b7e1904dddeee22bff30225d2bd04, stripped
$ ls -lah /boot/vmlinuz-5.4.0-52-generic
-rw------- 1 root root 43M Nov  1 20:00 /boot/vmlinuz-5.4.0-52-generic

When leaving it LZ4 compressed as it comes from the distributor:

$ sudo file /boot/vmlinuz-5.4.0-52-generic
/boot/vmlinuz-5.4.0-52-generic: Linux kernel x86 boot executable bzImage, version 5.4.0-52-generic (buildd@lgw01-amd64-060) #57-Ubuntu SMP Thu Oct 15 10:57:00 UTC 2020, RO-rootFS, swap_dev 0xB, Normal VGA
$ ls -lah /boot/vmlinuz-5.4.0-52-generic
-rw------- 1 root root 12M Oct 15 11:33 /boot/vmlinuz-5.4.0-52-generic

The reason why I am decompressing these guest kernels is because PV grub does not understand LZ4 compression and as I currently do boot guests this way, they would be unbootable otherwise.

For new installs I can skip installing my hack that decompresses the kernel image, but if PVH grub won't support uncompressed kernel images then this is inconvenient for the installed base who will need to make extra changes.

Is not supporting decompressed kernel images a bug in PVH grub?

This was tested with a git clone just now, following these instructions:

https://wiki.xenproject.org/wiki/Xen_4.12_RC_test_instructions#PVH_domU_boot_via_grub2

Thanks,
Andy

¹ https://raw.githubusercontent.com/torvalds/linux/master/scripts/extract-vmlinux

#1 lore raw
Quoted 13 lines · Andy Smith

Hi,

[ xen-users in CC as I know a few there are using a decompressed
kernel workaround for LZ4 and might be hit by this too ]

I'm currently evaluating switching from booting Xen guests with grub Xen PV (grub-mkimage -O x86_64-xen) to Xen PVH (grub-mkimage -O i386-xen_pvh). I've noticed that a decompressed guest kernel refuses to boot under PVH with the following error:

Loading Linux 5.4.0-52-generic ...
error: invalid magic number.

Quoted 6 lines

That same kernel boots with PV.

If I use the LZ4-compressed version of that kernel as supplied by the distribution (Ubuntu 20.04), it works PVH. I therefore can only conclude that PVH grub doesn't like kernels with no compression. Is that expected?

Can you boot the decompressed kernel on bare metal or in an HVM domain using grub?

I'm asking because PVH grub is using the standard i386 kernel loading functions, so I wouldn't expect any differences here compared to bare metal.

It might still be that PVH grub is missing some code due to wrong configure parameters, of course.

Juergen

author
#2 lore raw

Hi Jürgen,

Quoted 6 lines · Jürgen Groß
Quoted 2 lines · Andy Smith

I therefore can only conclude that PVH grub doesn't like kernels with no compression. Is that expected?

Can you boot the decompressed kernel on bare metal or in an HVM domain using grub?

Oh that's interesting. The decompressed kernel doesn't boot bare metal either (same message).

The decompressed kernel is generated like this:

# extract-vmlinux /boot/vmlinuz-5.4.0-52-generic > /boot/vmlinuz-5.4.0-52-generic-decompressed

The decompressed kernel does boot when presented to the hypervisor directly, i.e. no grub, directly listed in guest config file.

I don't have an HVM test setup right now so am unable to test that, but I suppose we can assume it will fail as the problem is in the standard grub loading functions.

So, is this a bug? Grub should be able to boot uncompressed kernels, shouldn't it?

Thanks,
Andy

#3 lore raw
Quoted 20 lines · Andy Smith

Hi Jürgen,

Quoted 6 lines · Jürgen Groß
Quoted 2 lines · Andy Smith

I therefore can only conclude that PVH grub doesn't like kernels with no compression. Is that expected?

Can you boot the decompressed kernel on bare metal or in an HVM domain using grub?

Oh that's interesting. The decompressed kernel doesn't boot bare metal either (same message).

The decompressed kernel is generated like this:

# extract-vmlinux /boot/vmlinuz-5.4.0-52-generic > /boot/vmlinuz-5.4.0-52-generic-decompressed

The decompressed kernel does boot when presented to the hypervisor directly, i.e. no grub, directly listed in guest config file.

Quoted 6 lines

I don't have an HVM test setup right now so am unable to test that, but I suppose we can assume it will fail as the problem is in the standard grub loading functions.

So, is this a bug? Grub should be able to boot uncompressed kernels, shouldn't it?

As long as the boot entry code is included in this kernel, yes.

Juergen

author
#4 lore raw

Hi,

Quoted 8 lines · Jürgen Groß
Quoted 7 lines · Andy Smith

The decompressed kernel is generated like this:

# extract-vmlinux /boot/vmlinuz-5.4.0-52-generic > /boot/vmlinuz-5.4.0-52-generic-decompressed

The decompressed kernel does boot when presented to the hypervisor directly, i.e. no grub, directly listed in guest config file.

Quoted 8 lines
Quoted 6 lines

I don't have an HVM test setup right now so am unable to test that, but I suppose we can assume it will fail as the problem is in the standard grub loading functions.

So, is this a bug? Grub should be able to boot uncompressed kernels, shouldn't it?

As long as the boot entry code is included in this kernel, yes.

I actually think now that the output of extract-vmlinux lacks something and I further suspect that if I would use a vmlinux file from within a kernel build tree it would be fine.

In which case this is not an issue for grub or xen, and only for those of us employing hacks based around extract-vmlinux.

Apologies for the distraction!

Thanks,
Andy

#5 lore raw
Quoted 20 lines · Andy Smith

Hi,

Quoted 8 lines · Jürgen Groß
Quoted 7 lines · Andy Smith

The decompressed kernel is generated like this:

# extract-vmlinux /boot/vmlinuz-5.4.0-52-generic > /boot/vmlinuz-5.4.0-52-generic-decompressed

The decompressed kernel does boot when presented to the hypervisor directly, i.e. no grub, directly listed in guest config file.

Quoted 8 lines
Quoted 6 lines

I don't have an HVM test setup right now so am unable to test that, but I suppose we can assume it will fail as the problem is in the standard grub loading functions.

So, is this a bug? Grub should be able to boot uncompressed kernels, shouldn't it?

As long as the boot entry code is included in this kernel, yes.

Quoted 8 lines

I actually think now that the output of extract-vmlinux lacks something and I further suspect that if I would use a vmlinux file from within a kernel build tree it would be fine.

In which case this is not an issue for grub or xen, and only for those of us employing hacks based around extract-vmlinux.

Apologies for the distraction!

No need to apologize.

We should really think about adding lz4 decompression support to grub for being able to use lz4 compressed kernels with pvgrub.

Juergen