10 KiB
arch-zbm
Helper script to install Arch Linux with ZFSBootMenu from within a running Arch Linux live CD ISO image
Prep
We expect minimal prep on your end. Please make sure that before execution the following conditions are met.
- Arch Linux live CD ISO image sees exactly one partition with partition type code
BF00
("Solaris root") - Arch Linux live CD ISO image sees exactly one partition with partition type code
EF00
("EFI system partition") - No ZFS zpool exists
The script will create a single ZFS zpool zpool
on the BF00
partition with dataset child zpool/root
which itself has one child zpool/root/archlinux
, that's where Arch Linux gets installed. Parallel to zpool/root
it'll create zpool/data
with a zpool/data/home
child dataset that gets mounted at /home
.
The script will use the EF00
partition to install a ZFSBootMenu EFI executable if efibootmgr
says that no such ZFSBootMenu
entry exists. If ZFSBootMenu gets added to the EFI partition it'll become primary boot option.
How to run this?
- Boot an Arch Linux live CD ISO image
- Run:
During execution the script will call itself when it changes into itsexport SCRIPT_URL='https://quico.space/quico-os-setup/arch-zbm/raw/branch/main/setup.sh' curl -s "${SCRIPT_URL}" | bash
chroot
, that's why weexport SCRIPT_URL
. Feel free to update"${SCRIPT_URL}"
with whatever branch or revision you want to use from quico.space/quico-os-setup/arch-zbm. Typically.../branch/main/setup.sh
as shown above is what you want.
Steps
The scripts takes the following installation steps.
- Install ZFS tools and kernel module with github.com/eoli3n/archiso-zfs
- Create one encrypted ZFS zpool on top of
BF00
partition, passwordpassword
- Create dataset for Arch Linux and
/home
- Install Arch Linux into pool
- Add ZFSBootMenu to
EF00
partition if it doesn't exist already - Exit into Arch Linux live CD ISO image shell for you to
reboot
and frolick
Flavor choices
We make the following opinionated flavor choices. Feel free to change them to your liking.
- Arch Linux locale is set to
en_US.UTF-8
- Keymap is
de-latin1
- Consult
/etc/vconsole.conf
- Change
zfs set org.zfsbootmenu:commandline=...
- Consult
- No X.Org Server, Wayland compositors or other GUI elements get installed
- Timezone is
Etc/UTC
- Check
timedatectl set-timezone <tzdata-zone>
- Check
Post-run manual steps
After installation you're going to want to at least touch these points in your new Arch Linux install:
- Package manager hook:
pacman
does not have a hook to do ZFS snapshots- See this GitHub gist and zfs-snapshotter.bash for inspiration
- Hostname: Installation chose a pseudo-randomly generated 8-character string with
pwgen
- Check
hostnamectl set-hostname <hostname>
- Check
- Unprivileged user accounts: The OS was installed with
root
and unprivilegedbuild
users - Passwords
- ZFS: The password for all datasets underneath
zpool
ispassword
. - Local
root
account: The localroot
account's password ispassword
.
- ZFS: The password for all datasets underneath
- Arch User Repository (AUR) helper: We installed paru as our AUR helper, we installed from GitHub via
makepkg -si
.
ZFS setup explained
The ZFS pool and dataset setup that makes this tick, explained in plain English.
- Create zpool with options:
-R /mnt
(aka-o cachefile=none -o altroot=/mnt
). The pool is never cached, i.e. it's considered temporary. All pool and dataset mount paths have/mnt
prepended. Fromman zpoolprops
:This can be used when examining an unknown pool where the mount points cannot be trusted, or in an alternate boot environment, where the typical paths are not valid.
altroot
is not a persistent property. It is valid only while the system is up.-O canmount=off
: Note the capital-O
which makes this a file system property, not a pool property. File system cannot be mounted, and is ignored byzfs mount -a
. This property is not inherited.-O mountpoint=none
: What it says on the tin, the pool has no mountpoint configured.-O encryption=on
: Makes this ourencryptionroot
and passes theencryption
setting to all child datasets. Selectingencryption=on
when creating a dataset indicates that the default encryption suite will be selected, which is currentlyaes-256-gcm
.-O keylocation=file://...
: This property is only set for encrypted datasets which are encryption roots. Controls where the user's encryption key will be loaded from by default for commands such aszfs load-key
.-O keyformat=passphrase
: Controls what format the user's encryption key will be provided as. Passphrases must be between 8 and 512 bytes long.
- At this time the newly created zpool is not mounted anywhere. Next we create the "root" dataset, that's an arbitary term for the parent dataset of all boot environments. Boot environments in your case may be for example different operating systems all of which live on separate datasets underneath the root.
-o mountpoint=none
: Same as above, the root dataset has - just like the pool - no mountpoint configured.zfs set org.zfsbootmenu:commandline=...
: Set a common kernel command line for all boot environment such as"ro quiet"
.
- Neither the root dataset nor the pool are mounted at this time. We now create one boot environment dataset where we want to install Arch Linux.
-o mountpoint=/
: Our Arch Linux dataset will be mounted at/
.-o canmount=noauto
: When set tonoauto
, a dataset can only be mounted and unmounted explicitly. The dataset is not mounted automatically when the dataset is created or imported, nor is it mounted by thezfs mount -a
command or unmounted by thezfs unmount -a
command.- We then
zpool set bootfs="zpool/root/archlinux" zpool
: ZFSBootMenu uses thebootfs
property to identify suitable boot environments. If only one pool has it - as is the case here - it identifies the pool's preferred boot dataset that will be booted with a 10-second countdown allowing manual interaction in ZFSBootMenu. - We explicitly mount the boot environment. Since the entire pool is still subject to our initial
-R /mnt
during creation azfs mount zpool/root/archlinux
will mount the Arch Linux dataset not into/
but instead into/mnt
.
- We also create a
data
dataset that - at least for now - we use to store only our/home
data.- For
zpool/data
:-o mountpoint=/
: We use themountpoint
property here only for inheritance.-o canmount=off
: Thezpool/data
dataset itself cannot actually be mounted.
- For a
zpool/data/home
child dataset:- We do not specify any properties. Since
canmount
cannot be inherited the parent'scanmount=off
does not apply, it instead defaults tocanmount=on
. The parent'smountpoint=/
property on the other hand is inherited so for ahome
child dataset it conveniently equalsmountpoint=/home
. - In effect this
zpool/data/home
dataset is subject tozfs mount -a
and will happily automount into/home
.
- We do not specify any properties. Since
- For
- We export the zpool once, we then reimport it by scanning only inside
/dev/disk/by-id
, again setting-R /mnt
as we did during pool creation a moment ago and we do not mount any file systems. - We
zfs load-key <encryptionroot>
which will load the key fromkeylocation
after which thekeystatus
property for<encryptionroot>
and all child datasets will change fromunavailable
toavailable
. - We mount our Arch Linux boot environment dataset. It automatically get prepended with
-R /mnt
since that's how we imported the pool. - We
zfs mount -a
which automountszpool/data/home
into/home
, which again gets auto-prepended by/mnt
. - We lastly mount our EFI partition into
/mnt/efi
. - We instruct ZFS to save its pool configuration via
zpool set cachefile=/etc/zfs/zpool.cache zpool
.
The complete ZFS structure now exists and is mounted at /mnt
ready for any pacstrap
, debootstrap, dnf --installroot
or other bootstrapping action.
Development
Conventional commits
This project uses Conventional Commits for its commit messages.
Commit types
Commit types besides fix
and feat
are:
build
: Project structure, directory layout, build instructions for roll-outrefactor
: Keeping functionality while streamlining or otherwise improving function flowtest
: Working on test coveragedocs
: Documentation for project or components
Commit scopes
The following scopes are known for this project. A Conventional Commits commit message may optionally use one of the following scopes or none:
iso
: Changing Arch Linux ISO CDzbm
: Adjusting ZFSBootMenu's behaviorzfs
: A change to how ZFS interacts with the system, either a pool or a datasetos
: Getting an perating system set up to correctly work in a ZFS boot environmentmeta
: Affects the project's repo layout, readme content, file names etc.
Credits
Most of what's here was shamelessly copied and slightly adapted for personal use from Jonathan Kirszling at GitHub.
Thanks to:
- Jonathan Kirszling:
- Maurizio Oliveri:
- Zach Dykstra, Andrew J. Hesford and all other ZFSBootMenu contributors:
- github.com/kongkrit: