Skip to content

fluffywaffles/initcpio-hooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Custom initcpio hooks

On Arch Linux, the pre-OS boot environment (often called the "rootfs", or "initramfs"; part of the Linux Kernel) is generated by a tool called mkinitcpio. This tool provides for adding binaries, files, and other customizations to the initramfs the kernel pre-boots into during initialization. This is often used, for instance, to decrypt an encrypted root partition before invoking switch_root to instate it as your / directory.

This repo contains custom initcpio hooks used for my desktop environment setup, 'numen'.

mount-numen

I use btrfs as my filesystem of choice. It's robust, it works well, and its copy-on-write and snapshotting capabilities make it an excellent choice for a consumer filesystem. RedHat agrees with me. Eat it, ext4.

I also encrypt my root partition, including /boot. The only things I don't encrypt are /boot/efi, which cannot be encrypted unless... well, I dunno, unless you flash your own BIOS I guess... and my swapspace. (I'm just not paranoid enough to bother encrypting swap.)

A nice feature of btrfs is subvolumes. This allows multiple logical hard-drives to be kept together on a single physical disk partition. It's similar in principle to Linux Logical Volume Manager (LVM), but with additional features from btrfs (like snapshotting, etc.). Subvolumes can be mounted, backed up, defragmented, and in just about every way, treated, as entirely independent disks.

I decided to create subvolumes for /, /bin, /lib, /etc, /var, /home, and a snapshot storage space at /snapshots. This will allow me to keep my binaries, libraries, settings, cache-files and logs, and home directories, all separate. So, if I want to wipe out /var, I can just... unmount it, and mount a backup in its place. Same for /bin, or /lib, or any of the others.

The trouble with doing this is: once you've entered your initramfs, and you want to invoke switch_root, you need your entire File System Hierarchy (FHS; see man 7 file-hierarchy) to be mounted at the new root. In particular, you need /sbin/init and /etc/fstab, at the very least, to get your system up and running correctly.

The best way to hook into the initramfs and teach it to mount my new subvolumes in their correct places before trying to invoke switch_root was with initcpio hooks, provided to mkinitcpio in my /etc/mkinitcpio.conf in the HOOKS array. And so, here we are!

mount-numen does the following, assuming that you have encrypted your root partition using the built-in encrypt initcpio hook (which it copies from so it can parse your encrypted drive's location from your encrypt configuration, without your needing to specify it a 2nd time):

  • mounts subvolume @lib at /new_root/usr/lib (in Arch, lib is a symlink to /usr/lib)
  • mounts subvolume @bin at /new_root/usr/bin (in Arch, bin is a symlink to /usr/bin)
  • mounts subvolume @var at /new_root/var
  • mounts subvolume @etc at /new_root/etc

and that's it. It just has to mount the necessary FHS directory subvolumes in their correct places, and switch_root goes off without a hitch! No more fumbling around in the [rootfs] recovery prompt, trying to decrypt my disk and mount things so that I can boot... 🎉

About

Custom Arch Linux initcpio hooks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages