Debian Codegraph @

doc/user-guide/15-EFISTUB.adoc

raw
1 # EFISTUB support
2
3 EFISTUB booting allows EFI firmware to directly load Linux kernel as an EFI executable. At the time of writing, EFISTUB support in kernel is widely available across all major distributions like SLES, Debian, Ubuntu, Fedora, Arch ...
4 When using traditional boot-loaders ((E)LILO, Grub), ReaR does not auto-magically recreate booting information on restore, but respective code must exist and this also applies for EFISTUB booting.
5
6 ## Prerequisites
7 There is plenty of ways how EFISTUB can be setup on source system but for the start I've decided to keep first EFISTUB implementation as simple as possible and eventually cover more robust configuration later (if need arise). For this reason ReaR currently offers very basic implementation, where:
8
9 - active Linux kernel must be compiled with **CONFIG_EFI_STUB=y**
10 - active Linux kernel and initrd are located directly on **vfat** partition
11 - **no intermediate boot loader** (ELILO, Grub, systemd-boot, ...) is in use and OS is booted directly from UEFI boot menu
12 - systemd-boot binary (for booting of ReaR recovery system) is available on system (usually as part of Systemd)
13 - currently works only with **OUTPUT=ISO**
14
15 ## ReaR Configuration
16 By default EFISTUB is disabled in ReaR and user must explicitly enable this functionality. Detection of EFISTUB booting is quite a problematic topic since it can co-exist with traditional boot loaders. Many Linux distributions are shipping Linux kernels with enabled EFISTUB support despite a fact that it is not used, and OS is using traditional intermediate boot loaders instead. You should enable EFISTUB in ReaR only if your system is really configured to boot this way, otherwise ReaR will try to perform migration.
17
18 To enable EFISTUB booting in ReaR one must specify following variable in _local.conf_ or _site.conf_
19 ```
20 EFI_STUB="yes"
21 ```
22
23 ## Migration
24 Migrating from traditional boot-loader to EFISTUB is kind of side effect of current implementation. Current EFISTUB code can't reliably determine if system is configured with EFISTUB boot hence user must explicitly specify that he wishes his system is considered EFISTUB bootable by ReaR.
25 If operating system is set to boot using intermediate boot loaders and despite this `EFI_STUB="yes"` is explicitly set, ReaR will omit installation of intermediate boot loaders and just creates UEFI boot entry pointing directly to EFISTUB boot capable kernel when system is restored.
26
27 ## Checks done by ReaR
28 When user enables EFISTUB, ReaR does some basic checks and tries to ensure that ReaR recovery runs without problems and resulting operating system is able to boot. However it is very hard to cover all configuration possibilities and corner cases, so it is important to ALWAYS TEST full ReaR backup and restore before relying on it. Short list of checks done by ReaR during `rear mkbackup/mkrescue` includes:
29
30 - check if Systemd boot loader (systemd-bootx64.efi) exists and is regular file
31 - check if some of basic EFISTUB symbols are present in Linux kernel file in use
32 - check if Linux kernel in use is located on vfat partition
33
34 ## Tests
35 Current code was primarily created and tested with Arch Linux, since most requests for EFISTUB functionality in ReaR keeps coming from this community.
36 Test system was running under VirtualBox host with following configuration:
37
38 - OS version
39
40 ```
41 arch-efi:(/root)(root)# lsb_release -a
42 LSB Version: 1.4
43 Distributor ID: Arch
44 Description: Arch Linux
45 Release: rolling
46 Codename: n/a
47
48 arch-efi:(/root)(root)# uname -a
49 Linux arch-efi.virtual.sk 4.20.5-arch1-1-ARCH #1 SMP PREEMPT Sat Jan 26 12:59:18 UTC 2019 x86_64 GNU/Linux
50 ```
51
52 - boot entry for Arch Linux (_Boot0003_) created in UEFI
53
54
55 ```
56 arch-efi:(/root)(root)# efibootmgr -v
57 BootCurrent: 0003
58 BootOrder: 0003,0000,0001,0002
59 Boot0000* EFI DVD/CDROM PciRoot(0x0)/Pci(0x1,0x1)/Ata(1,0,0)
60 Boot0001* EFI Hard Drive PciRoot(0x0)/Pci(0xd,0x0)/Sata(0,0,0)
61 Boot0002* EFI Internal Shell MemoryMapped(11,0x2100000,0x28fffff)/FvFile(7c04a583-9e3e-4f1c-ad65-e05268d0b4d1)
62 Boot0003* Arch Linux HD(1,GPT,e3b3601c-8037-4bf6-a938-4772cfb1ad9f,0x800,0x113000)/File(vmlinuz-linux)i.n.i.t.r.d.=.i.n.i.t.r.a.m.f.s.-.l.i.n.u.x...i.m.g. .r.o.o.t.=./.d.e.v./.s.d.a.2.
63 ```
64
65 - ReaR configuration
66
67 ```
68 arch-efi:(/root)(root)# cat /etc/rear/local.conf
69 BACKUP=NETFS
70 OUTPUT=ISO
71
72 BACKUP_URL=nfs://backup.virtual.sk/mnt/rear
73 OUTPUT_URL=nfs://backup.virtual.sk/mnt/rear/iso
74
75 BACKUP_OPTIONS="nfsvers=3,nolock"
76
77 EFI_STUB=yes
78 ```
79
80 - File system layout
81
82 ```
83 arch-efi:(/root)(root)# df -Th
84 Filesystem Type Size Used Avail Use% Mounted on
85 dev devtmpfs 485M 0 485M 0% /dev
86 run tmpfs 492M 404K 491M 1% /run
87 /dev/sda2 ext4 7.3G 2.1G 4.9G 30% /
88 tmpfs tmpfs 492M 0 492M 0% /dev/shm
89 tmpfs tmpfs 492M 0 492M 0% /sys/fs/cgroup
90 /dev/sda1 vfat 549M 41M 509M 8% /boot
91 tmpfs tmpfs 99M 0 99M 0% /run/user/0
92 ```
93
94 - Content of /boot
95
96 ```
97 arch-efi:(/root)(root)# ls -l /boot
98 total 41684
99 -rwxr-xr-x 1 root root 31232 Jan 22 10:14 amd-ucode.img
100 -rwxr-xr-x 1 root root 29094161 Feb 3 09:09 initramfs-linux-fallback.img
101 -rwxr-xr-x 1 root root 7686652 Feb 3 09:09 initramfs-linux.img
102 drwxr-xr-x 2 root root 4096 Jan 31 14:56 syslinux
103 -rwxr-xr-x 1 root root 5855104 Jan 31 09:17 vmlinuz-linux
104
105 ```
106
107 ## Migration from GRUB2 to EFISTUB on SLES12 SP2
108 WARNING: Do not start migration to EFISTUB until you are familiar with all the eventualities. It might happen that you end up with un-bootable system. Most of the time it is possible to fix un-bootable system, but some deeper knowledge might be required to succeed.
109
110 When prerequisites are fulfilled one can use ReaR EFISTUB code to migrate system from intermediate boot loaders like GRUB, ELILO to EFISTUB.
111 For the demonstration purposes I've tried migration from GRUB2 to EFISTUB on SLES12 SP2.
112
113 - OS version
114
115 ```
116 sp2:~ # cat /etc/os-release
117 NAME="SLES_SAP"
118 VERSION="12-SP2"
119 VERSION_ID="12.2"
120 PRETTY_NAME="SUSE Linux Enterprise Server for SAP Applications 12 SP2"
121 ID="sles_sap"
122 ANSI_COLOR="0;32"
123 CPE_NAME="cpe:/o:suse:sles_sap:12:sp2"
124 ```
125
126 - Basic ReaR configuration (does not include all EFISTUB configuration pieces yet)
127
128 ```
129 sp2:~ # cat /etc/rear/local.conf
130 BACKUP=NETFS
131 OUTPUT=ISO
132
133 BACKUP_URL=nfs://backup.virtual.sk/mnt/rear
134 OUTPUT_URL=nfs://backup.virtual.sk/mnt/rear/iso
135
136 BACKUP_OPTIONS="nfsvers=3,nolock"
137
138 BACKUP_PROG_EXCLUDE+=( /mnt )
139
140 #BTRFS stuff
141 REQUIRED_PROGS+=( snapper chattr lsattr xfs_repair )
142 COPY_AS_IS+=( /usr/lib/snapper/installation-helper /etc/snapper/config-templates/default )
143 BACKUP_PROG_INCLUDE=( $(findmnt -n -r -t btrfs | cut -d ' ' -f 1 | grep -v '^/$' | grep -Ev 'snapshots|crash' ) )
144
145 EFI_STUB=y
146 ```
147
148 - File system layout
149
150 ```
151 Filesystem Type Size Used Avail Use% Mounted on
152 devtmpfs devtmpfs 235M 0 235M 0% /dev
153 tmpfs tmpfs 8.0G 0 8.0G 0% /dev/shm
154 tmpfs tmpfs 244M 4.8M 239M 2% /run
155 tmpfs tmpfs 244M 0 244M 0% /sys/fs/cgroup
156 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /
157 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /var/lib/named
158 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /home
159 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /var/lib/pgsql
160 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /var/cache
161 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /var/tmp
162 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /var/lib/mailman
163 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /var/log
164 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /var/lib/libvirt/images
165 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /usr/local
166 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /boot/grub2/x86_64-efi
167 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /var/spool
168 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /var/crash
169 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /opt
170 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /var/lib/mariadb
171 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /tmp
172 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /var/opt
173 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /srv
174 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /var/lib/mysql
175 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /var/lib/machines
176 /dev/mapper/system-root btrfs 7.8G 3.9G 3.3G 55% /boot/grub2/i386-pc
177 /dev/sda1 vfat 156M 26M 131M 17% /boot/efi
178 tmpfs tmpfs 49M 0 49M 0% /run/user/0
179
180 ```
181
182 Since we don't have condition that active Linux kernel and initrd must reside on vfat file system, we can fulfill this requirement in two ways:
183
184 **1. Copy active Linux kernel and initrd files to vfat file system and configure ReaR to use alternate kernel file.**
185
186 In this particular case active kernel and initrd image are represented by following files:
187
188 ```
189 sp2:~ # ls -al /boot/vmlinuz-* /boot/initrd-*
190 -rw------- 1 root root 16365388 Aug 30 17:29 /boot/initrd-4.4.21-69-default
191 -rw-r--r-- 1 root root 5742352 Oct 25 2016 /boot/vmlinuz-4.4.21-69-default
192 ```
193
194 To copy files to vfat file system _/boot/efi_:
195
196 ```
197 sp2:~ # cp /boot/initrd-4.4.21-69-default /boot/efi
198 sp2:~ # cp /boot/vmlinuz-4.4.21-69-default /boot/efi
199 ```
200
201 Now we need to tell ReaR that we have kernel on vfat file system by adding `KERNEL_FILE="/boot/efi/vmlinuz-4.4.21-69-default"` configuration option into _/etc/rear/local.conf_
202
203 WARNING: Using kernel and initrd from other location than _/boot_, might require to perform some additional steps every time kernel and initrd changes (e.g. after each kernel or initrd update), like copy updated files to alternate location.
204
205 **2. Convert /boot to vfat file system**
206
207 There is several ways how one can convert _/boot_ into vfat. Easiest one is to create additional partition, format it with vfat and mount it under _/boot_.
208 As to cover this topic can be quite exhausting, it is not part of this document. In general if you don't know how to migrate _/boot_ to vfat, you should consider your decision to migrate system to EFISTUB carefully once more...
209
210 Whether you've decided to use _1st_ or _2nd_ method, last thing remaining is to configure custom boot attributes for EFISTUB. Normally when ReaR is configured to backup EFISTUB enabled system, it takes boots option from `/proc/cmdline`. During migration however `/proc/cmdline` does not contain sufficient information for successful EFISTUB boot. In our case:
211
212 ```
213 sp2:~ # cat /proc/cmdline
214 BOOT_IMAGE=/boot/vmlinuz-4.4.21-69-default root=/dev/mapper/system-root ro resume=/dev/system/swap splash=silent quiet showopts
215
216 ```
217 lacks information about which _initrd_ image should be booted. This information can be passed to ReaR by `EFI_STUB_EFIBOOTMGR_ARGS` configuration option. In our case we will add
218
219 ```
220 EFI_STUB_EFIBOOTMGR_ARGS="initrd=initrd-4.4.21-69-default root=/dev/mapper/system-root ro resume=/dev/system/swap splash=silent quiet showopts"
221 ```
222
223 configuration directive into _/etc/rear/local.conf_.
224
225 With ReaR configured as described in previous lines, we can start OS backup with `rear mkbackup`.
226
227 When ReaR recovery system is booted, we can start restore process as usual with `rear recover`. Once operation is over and you've used 1st method (_Copy active Linux kernel and initrd files to vfat file system and configure ReaR to use alternate kernel file_) you must copy _initrd_ image file, recently modified by ReaR, from _/mnt/local/boot_ into its alternate location (_/mnt/local/boot/efi_ in our case)
228
229
230 ```
231 RESCUE sp2:~ # cp /mnt/local/boot/initrd-4.4.21-69-default /mnt/local/boot/efi/
232 ```
233
234 because of reason mentioned in _WARNING_ section of 1st method. If you've been using 2nd method (_Convert /boot to vfat file system_), you can reboot ReaR recovery system without any further modifications.
235
236 Now restored system is ready for reboot!