We set up multiple OS to be booted from a UBS SD.
Both are Ubuntu.
ub16is on an LVM2 partition.ub18is on an encrypted LUKS partition with LVM2 on the inside. As it happen, the disk is SSD.
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, thenbootwill also be selected automatically.
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
...
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
rootandresumeparameters use the LV names. That meanslvm2has performed some initialization during theinitramfsprocess so that the LV names become visible. It so happens that one trigger for that process is seeing/dev/mapper/*as the value forrootorresume. So don't try using, e.g.root=UUID=7ffh993....because then LVM will not initialize and the partition withUUID=7ffh993....will not even be placed in the blockid table, and the system will not boot!
The
initramfsprocess is kind enough to trigger on these alternate values as well:
options root=/dev/ubuntu--vg/rootoptions resume=/dev/ubuntu--vg/swap
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
:lvmand:allow-discardsparameters, added to the end of thecrypdeviceparameter line.:lvmis obviously only necessary forlvm.allow-discardsis a parameter only for SSD disks - not needed for hard drives.
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
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
/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
This seems easier to manage than grub2. The bootscreen is a downgrade but that doesn't matter.
John Ramsden's blog on systemd-boot was especially helpful.
Other references
- https://www.freedesktop.org/software/systemd/man/bootctl.html#
- https://www.freedesktop.org/software/systemd/man/loader.conf.html#
- https://www.freedesktop.org/software/systemd/man/systemd-boot.html
- https://systemd.io/BOOT_LOADER_SPECIFICATION
- https://www.linuxsecrets.com/archlinux-wiki/wiki.archlinux.org/index.php/Systemd-boot.html
- https://wiki.archlinux.org/index.php/systemd-boot#Loader_configuration
- https://wiki.archlinux.org/index.php/Dm-crypt/System_configuration#Kernel_parameters
- https://gist.github.com/heppu/6e58b7a174803bc4c43da99642b6094b