mirror_zfs/contrib/initramfs
Serapheim Dimitropoulos 48df24d4ce
Remove zdb and libzpool from initramfs image
= Motivation

At Delphix we are heavy users of kernel crash dumps that are captured
through a crash kernel that is spawned whenever the main kernel panics.
The way that this works internally is that a certain amount of memory is
reserved while the main system is running so the initramfs of the crash
kernel can be loaded when a panic occurs.

In order to keep reserved memory at minimum we've been historically
trying to identify the binaries that are part of the kernel's initramfs
that are big and finding ways of either making them smaller or do not
include them in the initramfs image. An example is always stripping the
DWARF info of the ZFS kernel module copy that is included in the
initramfs image of both our running and our crash kernel (the difference
in size there is 76MB vs 4MB).

We've recently identified that libzpool has been the largest binary in
our initramfs images - currently sized around 17MB.

= This Patch

The ZFS scripts do not explicitly copy libzpool to initramfs. They copy
zdb which pulls in libzpool as a dependency. Given that both zdb and
libzpool are not really essential for initramfs (e.g. we'll still have
access to the once the root filesystem is unpacked) this patch removes
them from initramfs.

Reviewed-by: Richard Laager <rlaager@wiktel.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Matthew Ahrens <mahrens@delphix.com>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Signed-off-by: Serapheim Dimitropoulos <serapheim@delphix.com>
Closes #12616
2021-10-07 10:52:03 -06:00
..
conf-hooks.d Cleanup contrib/initramfs automake 2020-05-07 16:39:08 -07:00
conf.d Cleanup contrib/initramfs automake 2020-05-07 16:39:08 -07:00
hooks Remove zdb and libzpool from initramfs image 2021-10-07 10:52:03 -06:00
scripts i-t: don't try to import from empty cache 2021-06-04 14:01:08 -07:00
Makefile.am Turn shellcheck into a normal make target. Fix new files it caught 2021-06-01 11:38:49 -07:00
README.initramfs.markdown Remove vestigial settings related to initramfs 2020-08-22 11:04:49 -07:00
zfsunlock Silence 'make checkbashisms' 2020-08-20 13:45:47 -07:00

Description

These scripts are intended to be used with initramfs-tools, which is a similar software product to dracut (which is used in Red Hat based distributions), and is mainly used by Debian GNU/Linux and derivatives.

These scripts share some common functionality with the SysV init scripts, primarily the /etc/zfs/zfs-functions script.

Configuration

Root pool/filesystem

Different distributions have their own standard on what to specify on the kernel command line to boot off a ZFS filesystem.

This script supports the following kernel command line argument combinations (in this order - first match wins):

  • rpool=<pool>
  • bootfs=<pool>/<dataset>
  • rpool=<pool> bootfs=<pool>/<dataset>
  • -B zfs-bootfs=<pool>/<fs>
  • root=<pool>/<dataset>
  • root=ZFS=<pool>/<dataset>
  • root=zfs:AUTO
  • root=zfs:<pool>/<dataset>
  • rpool=rpool

If a pool is specified, it will be used. Otherwise, in AUTO mode, all pools will be searched. Pools may be excluded from the search by listing them in ZFS_POOL_EXCEPTIONS in /etc/default/zfs.

Pools will be imported as follows:

  • Try /dev/disk/by-vdev if it exists; see /etc/zfs/vdev_id.conf.
  • Try /dev/disk/by-id and any other /dev/disk/by-* directories.
  • Try /dev.
  • Use the cache file if nothing else worked.

This order may be modified by setting ZPOOL_IMPORT_PATH in /etc/default/zfs.

If a dataset is specified, it will be used as the root filesystem. Otherwise, this script will attempt to find a root filesystem automatically (in the specified pool or all pools, as described above).

Filesystems below the root filesystem will be automatically mounted with no additional configuration necessary. For example, if the root filesystem is rpool/ROOT/rootfs, rpool/root/rootfs/var, rpool/root/rootfs/usr, etc. will be mounted (if they exist).

Snapshots

The <dataset> can be a snapshot. In this case, the snapshot will be cloned and the clone used as the root filesystem. Note:

  • If the snapshot does not exist, the base dataset (the part before @) is used as the boot filesystem instead.
  • If the resulting clone dataset already exists, it is destroyed.
  • The clone is created with mountpoint=none and canmount=noauto. The root filesystem is mounted manually by the initramfs script.
  • If no snapshot is specified on the root= kernel command line, but there is an @, the user will be prompted to choose a snapshot to use.

Extra options

The following kernel command line arguments are supported:

  • zfsdebug=(on,yes,1): Show extra debugging information
  • zfsforce=(on,yes,1): Force import the pool
  • rollback=(on,yes,1): Rollback to (instead of clone) the snapshot

Unlocking a ZFS encrypted root over SSH

To use this feature:

  1. Install the dropbear-initramfs package. You may wish to uninstall the cryptsetup-initramfs package to avoid warnings.
  2. Add your SSH key(s) to /etc/dropbear-initramfs/authorized_keys. Note that Dropbear does not support ed25519 keys; use RSA (2048-bit or more) instead.
  3. Rebuild the initramfs with your keys: update-initramfs -u
  4. During the system boot, login via SSH and run: zfsunlock