Ubuntu: Difference between revisions

From BitFolk
Jump to navigation Jump to search
m (→‎Procedure: forgot filename)
(→‎No support for LZ4-compressed kernels at BitFolk: Installing a kernel post-install hook to decompress kernels)
Line 5: Line 5:
==20.04 (Focal Fossa) and beyond==
==20.04 (Focal Fossa) and beyond==
===No support for LZ4-compressed kernels at BitFolk===
===No support for LZ4-compressed kernels at BitFolk===
As of 19.10 Ubuntu switched to compressing its kernels with LZ4. At the time of writing (April 2020) BitFolk's hypervisor has a bug when trying to decompress LZ4 kernels which means that you cannot boot an LZ4-compressed kernel. It will report something like:
As of 19.10 Ubuntu switched to compressing its kernels with LZ4. At the time of writing (May 2020) BitFolk's does not support LZ4 kernels which means that you cannot boot an LZ4-compressed kernel. It will report something like:


<syntaxhighlight lang="text">
<syntaxhighlight lang="text">
Line 11: Line 11:
</syntaxhighlight>
</syntaxhighlight>


…and then go back to the bootloader menu. This is because BitFolk's hypervisor failed to decompress it.
…and then go back to the bootloader menu. This is because [https://lists.gnu.org/archive/html/grub-devel/2020-04/msg00198.html the PV kernel part of the grub bootloader doesn't recognise LZ4 compression].
 
This bug has [https://lore.kernel.org/xen-devel/20191206062535.GA13261@gentoo-tp.home/T/ since been fixed], but the fix has not yet been deployed.


====Resolution====
====Resolution====
BitFolk will need to deploy a new hypervisor in order to properly fix this. As that will require a reboot for everyone on each host BitFolk has decided not to schedule maintenance for this. As hosts with the fix become available customers who wish to use LZ4-compressed kernels will be moved to them. After the next security patch requires a reboot of all servers, LZ4-compressed kernels will be fully supported.
Either LZ4 support will need to be added to pvgrub or BitFolk will need to switch to PVH mode. BitFolk is (at the time of writing) preparing to switch to PVH mode but isn't ready yet.


====Workarounds====
====Workarounds====
=====Decompress your kernel=====
=====Decompress your kernel=====
Since the problem here is the type of compression used on the kernel image and not any actual functionality of the kernel, you can decompress your kernel image manually and then it will work without issue.
Since the problem here is the type of compression used on the kernel image and not any actual functionality of the kernel, you can decompress your kernel image manually and then it will work without issue. This can be done in [https://kernel-team.pages.debian.net/kernel-handbook/ch-update-hooks.html a kernel post-install hook script].
 
This workaround has already been applied to VMs ordered brand new or installed using [[Self-install|the BitFolk installer]]. Only those upgrading from a previous version of Ubuntu need to do something like this.


======Requirements======
======Requirements======
* A working VM. If your VM doesn't currently boot you can select the previous (18.04) kernel and that will work well enough to complete this procedure.
* A working VM. If your VM doesn't currently boot you can select the previous (18.04) kernel and that will work well enough to complete this procedure.
* <tt>'''lz4'''</tt> utility which is part of the '''[https://packages.ubuntu.com/focal/lz4 lz4]''' package; normally comes with the base Ubuntu install.
* <tt>'''lz4'''</tt> utility which is part of the '''[https://packages.ubuntu.com/focal/lz4 lz4]''' package; normally comes with the base Ubuntu install.
* <tt>'''readelf'''</tt> utility which is part of the '''[https://packages.ubuntu.com/focal/binutils binutils]''' package
* <tt>'''readelf'''</tt> utility which is part of the '''[https://packages.ubuntu.com/focal/binutils binutils]''' package.
* <tt>'''extract-vmlinux'''</tt> script [https://raw.githubusercontent.com/torvalds/linux/master/scripts/extract-vmlinux available from Linus Torvalds]
* <tt>'''extract-vmlinux'''</tt> script [https://raw.githubusercontent.com/torvalds/linux/master/scripts/extract-vmlinux available from the Linux kernel repository]. Put in <tt>'''/usr/local/sbin/'''</tt>.
* [https://github.com/bitfolk/decompress-lz4-kernels BitFolk's kernel post-install hook]. Put it in <tt>'''/etc/kernel/postinst.d/'''</tt>.


======Procedure======
======Procedure======


<syntaxhighlight lang="text">
<syntaxhighlight lang="text">
$ sudo apt install binutils lz4
### Download "extract-vmlinux" script and make it executable
### Download "extract-vmlinux" script and make it executable
$ curl https://raw.githubusercontent.com/torvalds/linux/master/scripts/extract-vmlinux > extract-vmlinux
$ curl https://raw.githubusercontent.com/torvalds/linux/master/scripts/extract-vmlinux | sudo tee /usr/local/sbin/extract-vmlinux >/dev/null
$ chmod +x extract-vmlinux
$ sudo chmod -c +x /usr/local/sbin/extract-vmlinux
### extract-vmlinux outputs its kernel image to standard output.
### Download the kernel post-install hook and make it executable
### Also by default Ubuntu kernels are mode 0600 (only root can read), so sudo is necessary
$ curl https://raw.githubusercontent.com/bitfolk/decompress-lz4-kernels/master/bitfolk-decompress-lz4-kernels | sudo tee /etc/kernel/postinst.d/bitfolk-decompress-lz4-kernels >/dev/null
$ sudo ./extract-vmlinux /boot/vmlinuz-5.4.0-26-generic | sudo tee /boot/vmlinuz-5.4.0-26-uncompressed >/dev/null
$ sudo chmod -c +x /etc/kernel/postinst.d/bitfolk-decompress-lz4-kernels
$ sudo chmod -c 0600 /boot/vmlinuz-5.4.0-26-uncompressed
### Verify that the current kernel is compressed (bzImage). Note that the kernel version number may be different to that shown below.
mode of '/boot/vmlinuz-5.4.0-26-uncompressed' changed from 0644 (rw-r--r--) to 0600 (rw-------)
$ sudo file /boot/vmlinuz-5.4.0-29-generic
$ sudo update-grub
/boot/vmlinuz-5.4.0-29-generic: Linux kernel x86 boot executable bzImage, version 5.4.0-29-generic (buildd@lgw01-amd64-035) #33-Ubuntu SMP Wed Apr 29 14:32:27 UTC 2020, RO-rootFS, swap_dev 0xB, Normal VGA
### Force reinstall of the kernel package so the hook gets called. Note that the package name may be different due to a different version number.
$ sudo apt reinstall linux-image-5.4.0-29-generic
Reading package lists... Done
Building dependency tree     
Reading state information... Done
0 to upgrade, 0 to newly install, 1 reinstalled, 0 to remove and 0 not to upgrade.
Need to get 8,871 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://apt-cacher.lon.bitfolk.com/ubuntu/gb.archive.ubuntu.com/ubuntu focal-updates/main amd64 linux-image-5.4.0-29-generic amd64 5.4.0-29.33 [8,871 kB]
Fetched 8,871 kB in 0s (25.8 MB/s)                   
(Reading database ... 50238 files and directories currently installed.)
Preparing to unpack .../linux-image-5.4.0-29-generic_5.4.0-29.33_amd64.deb ...
Unpacking linux-image-5.4.0-29-generic (5.4.0-29.33) over (5.4.0-29.33) ...
Setting up linux-image-5.4.0-29-generic (5.4.0-29.33) ...
Processing triggers for linux-image-5.4.0-29-generic (5.4.0-29.33) ...
/etc/kernel/postinst.d/bitfolk-decompress-lz4-kernels:
LZ4-compressed kernel /boot/vmlinuz-5.4.0-29-generic found; decompressing...
(This is a BitFolk-specific customisation. Please see https://tools.bitfolk.com/wiki/Ubuntu for more information.)
Successfully decompressed /boot/vmlinuz-5.4.0-29-generic.
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.4.0-29-generic
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.0-26-uncompressed
Found linux image: /boot/vmlinuz-5.4.0-29-generic
Found linux image: /boot/vmlinuz-5.4.0-26-generic
Found initrd image: /boot/initrd.img-5.4.0-29-generic
Found initrd image: /boot/initrd.img-5.4.0-26-generic
Found linux image: /boot/vmlinuz-4.15.0-96-generic
Found initrd image: /boot/initrd.img-4.15.0-96-generic
Found Ubuntu 20.04 LTS (20.04) on /dev/xvda1
done
done
$ ls -lh /boot
### Verify that the kernel image is no longer compressed (ELF 64-bit LSB executable).
total 140M
$ sudo file /boot/vmlinuz-5.4.0-29-generic
-rw------- 1 root root 3.9M Apr  1 03:24 System.map-4.15.0-96-generic
/boot/vmlinuz-5.4.0-29-generic: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=e54a270642a361346d36d5be07edb8d2bfa3fe10, stripped
-rw------- 1 root root 4.6M Apr 20 17:33 System.map-5.4.0-26-generic
-rw-r--r-- 1 root root 213K Apr  1 03:24 config-4.15.0-96-generic
-rw-r--r-- 1 root root 233K Apr 20 17:33 config-5.4.0-26-generic
drwxr-xr-x 5 root root 4.0K Apr 24 10:56 grub
-rw-r--r-- 1 root root  22M Apr 23 17:57 initrd.img-4.15.0-96-generic
-rw-r--r-- 1 root root  48M Apr 23 18:00 initrd.img-5.4.0-26-generic
-rw------- 1 root root 8.0M Apr  1 03:27 vmlinuz-4.15.0-96-generic
-rw------- 1 root root  12M Apr 20 17:41 vmlinuz-5.4.0-26-generic
-rw------- 1 root root  43M Apr 24 10:55 vmlinuz-5.4.0-26-uncompressed
</syntaxhighlight>
</syntaxhighlight>


Now halt your VM and boot it again, making sure to select the -uncompressed kernel from the Grub bootloader menu.
Now reboot.
 
Of course you will have to remember to repeat this process any time there is a kernel update.


=====Recompile a kernel that doesn't use LZ4 compression=====
=====Recompile a kernel that doesn't use LZ4 compression=====

Revision as of 20:20, 10 May 2020

Issues to be aware of when using Ubuntu at BitFolk.

Note that non-LTS releases will not be discussed here, so for example none of the 19.x releases will be covered.

20.04 (Focal Fossa) and beyond

No support for LZ4-compressed kernels at BitFolk

As of 19.10 Ubuntu switched to compressing its kernels with LZ4. At the time of writing (May 2020) BitFolk's does not support LZ4 kernels which means that you cannot boot an LZ4-compressed kernel. It will report something like:

not a Xen kernel

…and then go back to the bootloader menu. This is because the PV kernel part of the grub bootloader doesn't recognise LZ4 compression.

Resolution

Either LZ4 support will need to be added to pvgrub or BitFolk will need to switch to PVH mode. BitFolk is (at the time of writing) preparing to switch to PVH mode but isn't ready yet.

Workarounds

Decompress your kernel

Since the problem here is the type of compression used on the kernel image and not any actual functionality of the kernel, you can decompress your kernel image manually and then it will work without issue. This can be done in a kernel post-install hook script.

This workaround has already been applied to VMs ordered brand new or installed using the BitFolk installer. Only those upgrading from a previous version of Ubuntu need to do something like this.

Requirements
  • A working VM. If your VM doesn't currently boot you can select the previous (18.04) kernel and that will work well enough to complete this procedure.
  • lz4 utility which is part of the lz4 package; normally comes with the base Ubuntu install.
  • readelf utility which is part of the binutils package.
  • extract-vmlinux script available from the Linux kernel repository. Put in /usr/local/sbin/.
  • BitFolk's kernel post-install hook. Put it in /etc/kernel/postinst.d/.
Procedure
$ sudo apt install binutils lz4
### Download "extract-vmlinux" script and make it executable
$ curl https://raw.githubusercontent.com/torvalds/linux/master/scripts/extract-vmlinux | sudo tee /usr/local/sbin/extract-vmlinux >/dev/null
$ sudo chmod -c +x /usr/local/sbin/extract-vmlinux
### Download the kernel post-install hook and make it executable
$ curl https://raw.githubusercontent.com/bitfolk/decompress-lz4-kernels/master/bitfolk-decompress-lz4-kernels | sudo tee /etc/kernel/postinst.d/bitfolk-decompress-lz4-kernels >/dev/null
$ sudo chmod -c +x /etc/kernel/postinst.d/bitfolk-decompress-lz4-kernels
### Verify that the current kernel is compressed (bzImage). Note that the kernel version number may be different to that shown below.
$ sudo file /boot/vmlinuz-5.4.0-29-generic
/boot/vmlinuz-5.4.0-29-generic: Linux kernel x86 boot executable bzImage, version 5.4.0-29-generic (buildd@lgw01-amd64-035) #33-Ubuntu SMP Wed Apr 29 14:32:27 UTC 2020, RO-rootFS, swap_dev 0xB, Normal VGA
### Force reinstall of the kernel package so the hook gets called. Note that the package name may be different due to a different version number.
$ sudo apt reinstall linux-image-5.4.0-29-generic
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 to upgrade, 0 to newly install, 1 reinstalled, 0 to remove and 0 not to upgrade.
Need to get 8,871 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://apt-cacher.lon.bitfolk.com/ubuntu/gb.archive.ubuntu.com/ubuntu focal-updates/main amd64 linux-image-5.4.0-29-generic amd64 5.4.0-29.33 [8,871 kB]
Fetched 8,871 kB in 0s (25.8 MB/s)                     
(Reading database ... 50238 files and directories currently installed.)
Preparing to unpack .../linux-image-5.4.0-29-generic_5.4.0-29.33_amd64.deb ...
Unpacking linux-image-5.4.0-29-generic (5.4.0-29.33) over (5.4.0-29.33) ...
Setting up linux-image-5.4.0-29-generic (5.4.0-29.33) ...
Processing triggers for linux-image-5.4.0-29-generic (5.4.0-29.33) ...
/etc/kernel/postinst.d/bitfolk-decompress-lz4-kernels:
LZ4-compressed kernel /boot/vmlinuz-5.4.0-29-generic found; decompressing...
(This is a BitFolk-specific customisation. Please see https://tools.bitfolk.com/wiki/Ubuntu for more information.)
Successfully decompressed /boot/vmlinuz-5.4.0-29-generic.
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.4.0-29-generic
/etc/kernel/postinst.d/zz-update-grub:
Sourcing file `/etc/default/grub'
Sourcing file `/etc/default/grub.d/init-select.cfg'
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-5.4.0-29-generic
Found initrd image: /boot/initrd.img-5.4.0-29-generic
done
### Verify that the kernel image is no longer compressed (ELF 64-bit LSB executable).
$ sudo file /boot/vmlinuz-5.4.0-29-generic
/boot/vmlinuz-5.4.0-29-generic: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, BuildID[sha1]=e54a270642a361346d36d5be07edb8d2bfa3fe10, stripped

Now reboot.

Recompile a kernel that doesn't use LZ4 compression

It should work to:

  1. Take the regular Ubuntu kernel source package.
  2. Adjust its kernel config so that it doesn't use LZ4 compression. Choosing any of XZ, Bzip2, Gzip or even no compression should work.
  3. Rebuild it without any other changes.

That sounds a lot harder than the above option so it isn't yet documented here but if you do this please feel free to add your instructions here.

18.04 (Bionic Beaver) and beyond

The switch to netplan for configuring networking

By default in this release Ubuntu stopped using ifupdown (as configured in /etc/network/interfaces) to configure its networking, instead using netplan. netplan is supposed to ignore interfaces that are defined in /etc/network/interfaces but it doesn't seem to do that reliably, so those upgrading from earlier Ubuntu releases can experience networking problems. This is not a BitFolk bug.

Resolution

Migrate to netplan

BitFolk recommends that all Ubuntu users migrate their configuration to netplan before upgrading to 18.04. A typical netplan configuration (in /etc/netplan/01-netcfg.yaml) at BitFolk looks like this:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      addresses:
        - "85.119.82.225/21"
        - "85.119.83.73/32"
        - "2001:ba8:1f1:f004::2/64"
        - "2001:ba8:1f1:f004::22/128"
        gateway4: "85.119.80.1"
        gateway6: "2001:ba8:1f1:f004::1"

This assumes:

  • A main IPv4 address of 85.119.82.225.
  • An additional IPv4 address of 85.119.83.73.
  • An assigned IPv6 network of 2001:ba8:1f1:f004::/64.
  • An extra IPv6 address of 2001:ba8:1f1:f004::22/128 configured.

To update the config and then make it live:

$ sudo netplan generate
$ sudo netplan apply