Mailing List Archive

Pvgrub with lz4 compressed kernels
I am running PV guests on xen 4.11 with pvgrub. The recent releases of ubuntu (>19.04) look to have switched to lz4 compressed kernels. These kernels work fine with direct boot, but under pvgrub and pvgrub2 they don't seem bootable.

Most recent release of ubuntu focal 20.04. Guest kernel 5.4.0-28.
```
error: not xen image. [ vmlinuz-5.4.0-28-gen 10B 0% 0.17B/s ]
error: you need to load the kernel first.

Press any key to continue...
```

The same setup works with an older kernel (e.g. 4.19)

I notice there was an issue for this patched into xen itself, has anyone got these kernels working with pvgrub?

Cheers!
John S
Re: Pvgrub with lz4 compressed kernels [ In reply to ]
Hi John,

On Fri, May 01, 2020 at 04:23:29AM +0000, John S wrote:
> I am running PV guests on xen 4.11 with pvgrub. The recent
> releases of ubuntu (>19.04) look to have switched to lz4
> compressed kernels. These kernels work fine with direct boot, but
> under pvgrub and pvgrub2 they don't seem bootable.

I have the same problem. I don't believe there is any support in
Grub for it yet. I asked but have not got a response yet:

https://lists.gnu.org/archive/html/grub-devel/2020-04/msg00198.html

If you see my own response to my email, I found that Grub compiled
as a PVH image will boot these kernels in PVH mode.

The other thing you can do right now is decompress the kernel images
using:

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

They will then boot with pvgrub.

For those of us not yet ready to switch to PVH it would be great if
someone could implement LZ4 decompression for pvgrub.

Cheers,
Andy
Re: Pvgrub with lz4 compressed kernels [ In reply to ]
Hey Andy,

> On Fri, May 01, 2020 at 04:23:29AM +0000, John S wrote:
> I have the same problem. I don't believe there is any support in
> Grub for it yet. I asked but have not got a response yet:
>
> https://lists.gnu.org/archive/html/grub-devel/2020-04/msg00198.html
>
> If you see my own response to my email, I found that Grub compiled
> as a PVH image will boot these kernels in PVH mode.
>
> The other thing you can do right now is decompress the kernel images
> using:
>
> https://raw.githubusercontent.com/torvalds/linux/master/scripts/extract-vmlinux
>
> They will then boot with pvgrub.
>
> For those of us not yet ready to switch to PVH it would be great if
> someone could implement LZ4 decompression for pvgrub.

Thanks for that very useful!, gives me a way forward for the moment.

As a workaround specific to Ubuntu PV guests I have written an apt hook using extract-vmlinux to decompress kernels during installation. (Included 'decompress-kernel')

The hook requires extract-linux somewhere and goes into /etc/kernel/postinst.d/

Hope to see some support for this upstream.

Cheers,
John S
Re: Pvgrub with lz4 compressed kernels [ In reply to ]
Hi John,

On Wed, May 06, 2020 at 04:27:54AM +0000, John S wrote:
> As a workaround specific to Ubuntu PV guests I have written an apt
> hook using extract-vmlinux to decompress kernels during
> installation. (Included 'decompress-kernel')

Good idea.

I had a quick glance and am a bit worried about some of the
temporary paths you use. I haven't verified but as these paths are
predictable ahead of time have you checked that they can't be used
by a malicious non-root user in the guest to overwrite arbitrary
system files?

Do you know a way to detect only LZ4 kernel images? That way this
technique could be used for only LZ4, as every other compression
method works fine at the moment.

Decompressed kernel is about 10 times the size of a compressed one,
so if guest is using a different compression type it would be good
to honour that.

> Hope to see some support for this upstream.

The complete lack of response on grub-devel is discouraging. If
there's anyone who's capable of adding the feature but needs
financial compensation to do so, please do contact me off-list;
maybe we can arrange something. Although at this point I guess the
PV world is moving to PVH.

Cheers,
Andy
Re: Pvgrub with lz4 compressed kernels [ In reply to ]
On Thu, May 07, 2020 at 10:51:54PM +0000, Andy Smith wrote:
> Do you know a way to detect only LZ4 kernel images? That way this
> technique could be used for only LZ4, as every other compression
> method works fine at the moment.

You can of course just use the pattern from extract-vmlinux to check
an image file:

lz4match=$(printf '\002!L\030')
grep -aq "$lz4match" /boot/vmlinuz-5.4.0-29-generic && echo "At least one LZ4 header
found"

Cheers,
Andy
Re: Pvgrub with lz4 compressed kernels [ In reply to ]
Hey Andy,

> I had a quick glance and am a bit worried about some of the
> temporary paths you use. I haven't verified but as these paths are
> predictable ahead of time have you checked that they can't be used
> by a malicious non-root user in the guest to overwrite arbitrary
> system files?

Yeah you are correct fair point, I've adjusted to make use of mktemp instead.

> On Thu, May 07, 2020 at 10:51:54PM +0000, Andy Smith wrote:
>
>> Do you know a way to detect only LZ4 kernel images? That way this
>> technique could be used for only LZ4, as every other compression
>> method works fine at the moment.
>
> You can of course just use the pattern from extract-vmlinux to check
> an image file:
>
> lz4match=$(printf '\002!L\030')
> grep -aq "$lz4match" /boot/vmlinuz-5.4.0-29-generic && echo "At least one LZ4 header
> found"

Its funny as if they were offering anything but lz4 kernels then the script wouldn't be needed at
all. But it doesn't hurt, I've included a check for that as well.

> The complete lack of response on grub-devel is discouraging. If
> there's anyone who's capable of adding the feature but needs
> financial compensation to do so, please do contact me off-list;
> maybe we can arrange something. Although at this point I guess the
> PV world is moving to PVH.

I think we lost most of them to KVM already anyway :(

Cheers,
John S