Skip to content

Instantly share code, notes, and snippets.

@craigphicks
Last active March 6, 2019 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save craigphicks/8e24f0e7e5ed52ee27864bff286c0b4c to your computer and use it in GitHub Desktop.
Save craigphicks/8e24f0e7e5ed52ee27864bff286c0b4c to your computer and use it in GitHub Desktop.
multi os booting with `systemd-boot` / `boot-ctl` --- case examples: LVM, LUKS with LVM, on SSD

multi os booting with systemd-boot

We set up multiple OS to be booted from a UBS SD.

Both are Ubuntu.

  • ub16 is on an LVM2 partition.
  • ub18 is on an encrypted LUKS partition with LVM2 on the inside. As it happen, the disk is SSD.

Formatting the USB SD

I used gparted.

  • Create a FAT32 partition with Partition | New
  • partition name: sysd-boot (e.g.)
  • label: M1-EFI (e.g.)
  • select Edit | Apply all operations
  • Partition | Flags
  • select esp, then boot will also be selected automatically.

USB SD content

Mount the SD

mkdir /mnt/M1-MNT
sudo mount LABEL=M1-MNT /mnt/M1-MNT

Initialize

bootctl --path=/mnt/M1-EFI install

The dir tree will be

/mnt/M1-EFI/
├── EFI
│   ├── BOOT
│   │   └── BOOTX64.EFI
│   └── systemd
│       └── systemd-bootx64.efi
└── loader
    └── loader.conf

We'll place all the necessary files (vmlinuz-*, initrd.img-*) in an installs directory:

/mnt/M1-EFI/
...
├── installs
│   ├── ub16
│   │   ├── initrd.img-4.13.0-45-generic.new
│   │   └── vmlinuz-4.13.0-45-generic
│   └── ub18
│       ├── initrd.img-4.18.0-15-generic
│       └── vmlinuz-4.18.0-15-generic
...

ub16.conf - config for an LVM partition

These will get referenced from two configure files, ub16.conf and ub18.conf, placed under .../loader/entries:

/mnt/M1-EFI/
...
└── loader
    ├── entries
    │   ├── ub16.conf
    │   └── ub18.conf
...

The content of ub16.conf, for an LVM2 partition is:

title		ub16 (Ubuntu 16.04 / lvm)
linux		/installs/ub16/vmlinuz-4.13.0-45-generic
#initrd		/installs/ub16/intel-ucode.img
initrd		/installs/ub16/initrd.img-4.13.0-45-generic.new
options    root=/dev/mapper/ubuntu--vg-root
options    resume=/dev/mapper/ubuntu--vg-swap
options    rw quiet

Note: The root and resume parameters use the LV names. That means lvm2has performed some initialization during the initramfs process so that the LV names become visible. It so happens that one trigger for that process is seeing /dev/mapper/* as the value for root or resume. So don't try using, e.g. root=UUID=7ffh993.... because then LVM will not initialize and the partition with UUID=7ffh993.... will not even be placed in the blockid table, and the system will not boot!

The initramfs process is kind enough to trigger on these alternate values as well:

  • options root=/dev/ubuntu--vg/root
  • options resume=/dev/ubuntu--vg/swap

ub18.conf - config for a LUKS partition with LVM on the inside

The content of ub18.conf, for a LUKS encrypted partition with LVM inside is:

title		ub18 (Ubuntu 18.04 / encrypted luks-lvm)
linux		/installs/ub18/vmlinuz-4.18.0-15-generic
#initrd		/installs/ub18/intel-ucode.img
initrd		/installs/ub18/initrd.img-4.18.0-15-generic
options    cryptdevice=UUID=7398fyhiu-oikj98-kkkjr:lvm:allow-discards
options    resume=/dev/mapper/crypt1--vg-swap
options    root=/dev/mapper/crypt1--vg-root
options    rw quiet

Note: In the encrypted LUKS case, the UUID of the partition must be used, because the LVM is not visible until the disk has been decrypted.

Note: The :lvm and :allow-discards parameters, added to the end of the crypdevice parameter line. :lvm is obviously only necessary for lvm. allow-discards is a parameter only for SSD disks - not needed for hard drives.

The loader/loader.conf file - controlling menu and default selection, etc.

We backed up the original loader.conf file that was installed with the bootctl initalize, and added a new one:

...
└── loader
    ...
    ├── loader.conf
    └── loader.conf.orig

The content of loader.conf is

default  ub18
timeout  4
#console-mode max
editor   no

About /boot

This systemd-boot does not require a target OS to have a /boot or /boot/efi partition mounted as boot occurs. But it does require that nothing incorrect is mounted on /boot during boot time, or the system may hang on boot.

When the kernel is updated it is desirable to have the files under, e.g. installs/ub18 automatically updated.
For that purpose we want the OS mount point boot to point to the directory to be updated, e.g., .../installs/ub18.

To the /etc/fstabs file is added

LABEL=M1-EFI /media/M1-EFI vfat umask=0077 0 0
/media/M1-EFI/installs/ub18 /boot none defaults,bind 0 0

Entire tree

/media/M1-EFI/
├── EFI
│   ├── BOOT
│   │   └── BOOTX64.EFI
│   └── systemd
│       └── systemd-bootx64.efi
├── installs
│   ├── ub16
│   │   ├── initrd.img-4.13.0-45-generic.new
│   │   └── vmlinuz-4.13.0-45-generic
│   └── ub18
│       ├── grub
│       │   └── grubenv
│       ├── initrd.img-4.18.0-15-generic
│       └── vmlinuz-4.18.0-15-generic
└── loader
    ├── entries
    │   ├── ub16.conf
    │   └── ub18.conf
    ├── loader.conf
    └── loader.conf.orig

Conclusion

This seems easier to manage than grub2. The bootscreen is a downgrade but that doesn't matter.

Thanks

John Ramsden's blog on systemd-boot was especially helpful.

Other references

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment