1c03c5b1cSMartin Matuska## Description 2c03c5b1cSMartin Matuska 3c03c5b1cSMartin MatuskaThese scripts are intended to be used with `initramfs-tools`, which is a 4c03c5b1cSMartin Matuskasimilar software product to `dracut` (which is used in Red Hat based 5c03c5b1cSMartin Matuskadistributions), and is mainly used by Debian GNU/Linux and derivatives. 6c03c5b1cSMartin Matuska 7c03c5b1cSMartin MatuskaThese scripts share some common functionality with the SysV init scripts, 8c03c5b1cSMartin Matuskaprimarily the `/etc/zfs/zfs-functions` script. 9c03c5b1cSMartin Matuska 10c03c5b1cSMartin Matuska## Configuration 11c03c5b1cSMartin Matuska 12c03c5b1cSMartin Matuska### Root pool/filesystem 13c03c5b1cSMartin Matuska 14c03c5b1cSMartin MatuskaDifferent distributions have their own standard on what to specify on the 15c03c5b1cSMartin Matuskakernel command line to boot off a ZFS filesystem. 16c03c5b1cSMartin Matuska 17c03c5b1cSMartin MatuskaThis script supports the following kernel command line argument combinations 18c03c5b1cSMartin Matuska(in this order - first match wins): 19c03c5b1cSMartin Matuska 20c03c5b1cSMartin Matuska* `rpool=<pool>` 21c03c5b1cSMartin Matuska* `bootfs=<pool>/<dataset>` 22c03c5b1cSMartin Matuska* `rpool=<pool> bootfs=<pool>/<dataset>` 23c03c5b1cSMartin Matuska* `-B zfs-bootfs=<pool>/<fs>` 24c03c5b1cSMartin Matuska* `root=<pool>/<dataset>` 25c03c5b1cSMartin Matuska* `root=ZFS=<pool>/<dataset>` 26c03c5b1cSMartin Matuska* `root=zfs:AUTO` 27c03c5b1cSMartin Matuska* `root=zfs:<pool>/<dataset>` 28c03c5b1cSMartin Matuska* `rpool=rpool` 29c03c5b1cSMartin Matuska 30c03c5b1cSMartin MatuskaIf a pool is specified, it will be used. Otherwise, in `AUTO` mode, all pools 31c03c5b1cSMartin Matuskawill be searched. Pools may be excluded from the search by listing them in 32c03c5b1cSMartin Matuska`ZFS_POOL_EXCEPTIONS` in `/etc/default/zfs`. 33c03c5b1cSMartin Matuska 34c03c5b1cSMartin MatuskaPools will be imported as follows: 35c03c5b1cSMartin Matuska 36c03c5b1cSMartin Matuska* Try `/dev/disk/by-vdev` if it exists; see `/etc/zfs/vdev_id.conf`. 37c03c5b1cSMartin Matuska* Try `/dev/disk/by-id` and any other `/dev/disk/by-*` directories. 38c03c5b1cSMartin Matuska* Try `/dev`. 39c03c5b1cSMartin Matuska* Use the cache file if nothing else worked. 40c03c5b1cSMartin Matuska 41c03c5b1cSMartin MatuskaThis order may be modified by setting `ZPOOL_IMPORT_PATH` in 42c03c5b1cSMartin Matuska`/etc/default/zfs`. 43c03c5b1cSMartin Matuska 44c03c5b1cSMartin MatuskaIf a dataset is specified, it will be used as the root filesystem. Otherwise, 45c03c5b1cSMartin Matuskathis script will attempt to find a root filesystem automatically (in the 46c03c5b1cSMartin Matuskaspecified pool or all pools, as described above). 47c03c5b1cSMartin Matuska 48c03c5b1cSMartin MatuskaFilesystems below the root filesystem will be automatically mounted with no 49c03c5b1cSMartin Matuskaadditional configuration necessary. For example, if the root filesystem is 50c03c5b1cSMartin Matuska`rpool/ROOT/rootfs`, `rpool/root/rootfs/var`, `rpool/root/rootfs/usr`, etc. 51c03c5b1cSMartin Matuskawill be mounted (if they exist). 52c03c5b1cSMartin Matuska 53c03c5b1cSMartin Matuska### Snapshots 54c03c5b1cSMartin Matuska 55c03c5b1cSMartin MatuskaThe `<dataset>` can be a snapshot. In this case, the snapshot will be cloned 56c03c5b1cSMartin Matuskaand the clone used as the root filesystem. Note: 57c03c5b1cSMartin Matuska 58c03c5b1cSMartin Matuska* If the snapshot does not exist, the base dataset (the part before `@`) is 59c03c5b1cSMartin Matuska used as the boot filesystem instead. 60c03c5b1cSMartin Matuska* If the resulting clone dataset already exists, it is destroyed. 61c03c5b1cSMartin Matuska* The clone is created with `mountpoint=none` and `canmount=noauto`. The root 62c03c5b1cSMartin Matuska filesystem is mounted manually by the initramfs script. 63c03c5b1cSMartin Matuska* If no snapshot is specified on the `root=` kernel command line, but 64c03c5b1cSMartin Matuska there is an `@`, the user will be prompted to choose a snapshot to use. 65c03c5b1cSMartin Matuska 66c03c5b1cSMartin Matuska### Extra options 67c03c5b1cSMartin Matuska 68c03c5b1cSMartin MatuskaThe following kernel command line arguments are supported: 69c03c5b1cSMartin Matuska 70c03c5b1cSMartin Matuska* `zfsdebug=(on,yes,1)`: Show extra debugging information 71c03c5b1cSMartin Matuska* `zfsforce=(on,yes,1)`: Force import the pool 72c03c5b1cSMartin Matuska* `rollback=(on,yes,1)`: Rollback to (instead of clone) the snapshot 73c03c5b1cSMartin Matuska 74c03c5b1cSMartin Matuska### Unlocking a ZFS encrypted root over SSH 75c03c5b1cSMartin Matuska 76c03c5b1cSMartin MatuskaTo use this feature: 77c03c5b1cSMartin Matuska 78c03c5b1cSMartin Matuska1. Install the `dropbear-initramfs` package. You may wish to uninstall the 79c03c5b1cSMartin Matuska `cryptsetup-initramfs` package to avoid warnings. 80c03c5b1cSMartin Matuska2. Add your SSH key(s) to `/etc/dropbear-initramfs/authorized_keys`. Note 81c03c5b1cSMartin Matuska that Dropbear does not support ed25519 keys before version 2020.79; 82c03c5b1cSMartin Matuska in that case, use RSA (2048-bit or more) instead. 83c03c5b1cSMartin Matuska3. Rebuild the initramfs with your keys: `update-initramfs -u` 84c03c5b1cSMartin Matuska4. During the system boot, login via SSH and run: `zfsunlock` 85*d411c1d6SMartin Matuska 86*d411c1d6SMartin Matuska### Unlocking a ZFS encrypted root via alternate means 87*d411c1d6SMartin Matuska 88*d411c1d6SMartin MatuskaIf present, a shell program at `/etc/zfs/initramfs-tools-load-key` 89*d411c1d6SMartin Matuskaand files matching `/etc/zfs/initramfs-tools-load-key.d/*` 90*d411c1d6SMartin Matuskawill be copied to the initramfs during generation 91*d411c1d6SMartin Matuskaand sourced to load the key, if required. 92*d411c1d6SMartin Matuska 93*d411c1d6SMartin MatuskaThe `$ENCRYPTIONROOT` to load the key for and `$KEYLOCATION` variables are set, 94*d411c1d6SMartin Matuskaand all initramfs-tools functions are available; 95*d411c1d6SMartin Matuskause unquoted `$ZPOOL` and `$ZFS` to run `zpool` and `zfs`. 96*d411c1d6SMartin Matuska 97*d411c1d6SMartin MatuskaA successful return (and loaded key) stops the search. 98*d411c1d6SMartin MatuskaA failure return is non-fatal, 99*d411c1d6SMartin Matuskaand loading keys proceeds as normal if no hook succeeds. 100*d411c1d6SMartin Matuska 101*d411c1d6SMartin MatuskaA trivial example of a key-loading drop-in that uses the BLAKE2 checksum 102*d411c1d6SMartin Matuskaof the file at the `keylocation` as the key follows. 103*d411c1d6SMartin Matuska 104*d411c1d6SMartin Matuska```sh 105*d411c1d6SMartin Matuskakey="$(b2sum "${KEYLOCATION#file://}")" || return 106*d411c1d6SMartin Matuskaprintf '%s\n' "${key%% *}" | $ZFS load-key -L prompt "$ENCRYPTIONROOT" 107*d411c1d6SMartin Matuska``` 108