-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathrootfs.cfg
413 lines (369 loc) · 15.3 KB
/
rootfs.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# Initiating EVE boot sequence
#
# This GRUB configuration file gets evaluated in 2 different contexts:
# 1. by a GRUB sitting next to it (in one of the EVE rootfs images)
# 2. as a GRUB's configfile argument of an external GRUB
# Either way, the goal of this file is to setup a few variables
# that would describe how to load at least a Hypervisor and/or Dom0
# (both of which are expected to reside in a rootfs next to each other).
#
# In addition to that, this configuration will also discover how to
# load required initramfs and devicetree files (the later only useful
# for ARM architecture).
#
# All of this is accomplished by probing the environment and recording
# our findings in a set of variables that get exported from this context
# or could be used directly by the default boot menuentry. A second menu
# entry allows for further customization of the same variables and happens
# to be a simple UI sugar on top of running GRUB's 'set' command explicitly.
#
# Finally, further customization of the same variables is possible if we
# detect either grub-hv.cfg next to whether this configuration came from OR
# we detect grub.cfg file in the CONFIG EVE partition. Both of these files
# will be 'source'd in sequence and they can provide final overrides for any
# kind of settings.
#
# Output variables (can NOT be longer than 20 characters)
# load_hv_cmd GRUB command to load a hypervisor
# load_dom0_cmd GRUB command to load Dom0
# load_initrd_cmd GRUB command to load initrd/initrootfs
# load_devicetree_cmd GRUB command to load a devicetree DTB file (ARM only)
#
# hv hypervisor filename (rooted at either '/' or (XXX))
# dom0 Dom0 kernel filename (rooted at either '/' or (XXX))
# initrd initrd/initrootfs filename (rooted at either '/' or (XXX))
# devicetree devicetree filename (rooted at either '/' or (XXX))
#
# hv_console settings for having a viable hypervisor console output
# hv_platform_tweaks any kind of platform specific (hardware/etc.) hypervisor settings
# hv_dom0_mem_settings Dom0 RAM settings (size, etc.)
# hv_dom0_cpu_settings Dom0 CPU settings (how many cores are available, etc.)
# hv_eve_mem_settings EVE services RAM settings (Should be <= hv_dom0_mem_settings)
# hv_eve_cpu_settings EVE services CPU settings (Should be <= hv_dom0_cpu_settings)
# hv_ctrd_mem_settings Containerd RAM settings (Should be <= hv_dom0_mem_settings)
# hv_ctrd_cpu_settings Containerd CPU settings (Should be <= hv_dom0_cpu_settings)
# hv_watchdog_timer Sets EVE watchdog timer to monitor services
# hv_extra_args any additional hypervisor settings
#
# dom0_console settings for having a viable Dom0 console output
# dom0_rootfs pointer to a root filesystem we expect Dom0 to use
# dom0_platform_tweaks any kind of platform specific (hardware/etc.) Dom0 settings
# dom0_cmdline additional static Dom0 settings (see linuxkit_cmdline below)
# dom0_extra_args additional dynamic Dom0 settings
#
# Note that when using override config files (either grub-hv.cfg or CONFIG/grub.cfg)
# it only makes sense to override the above output variables. Tweaking input and private
# variables (described below) will have absolutely 0 effect. The reverse is true for
# when this configfile is evaluated in the outside context. There you can only rely
# on setting input variables to affect behavior (and yes this is by design to limit
# what kind of control external context will have over this config file).
#
# Input variables (can NOT be longer than 20 characters)
# eve_flavor can set to be either xen or kvm to indicated required boot sequence
# rootfs_root name of a rootfilesystem recognizable by Dom0, if not set in the
# outer context, the default value will be dynamically discovered
# by running a partprobe command with an EVE rootfs UUID.
# rootfs_title_suffix a string that will be displayed as a suffix in the boot menu title
# do_extra_submenus name of a grub function -- if defined will be called to generate
# additional submenus in the Settings menu
# dom0_extra_args output variable with an initial value taken from the input
# initrd output variable with an initial value taken from the input
# linuxkit_cmdline is special because we expect it to be tweaked during build phase (via sed)
set linuxkit_cmdline=
# Kernel behaviour on panic: seconds before rebooting
set panic_timeout="panic=120"
# Tweaking behaviour of GRUB itself (can be further tweaked by override settings)
# Note on gfxpayload: on most EFI platforms, setting gfxpayload is actually detrimental
# however, on BIOS platforms and weird archictetures make sure to experiment with it
# starting from: set gfxpayload=text
set timeout=5
set default=0
set pager=1
# the following variables are considered to be private and are not expected to be touched
set grub_virt=
set rootfs_title=EVE
function set_global {
set $1="$2"
export $1
}
function do_if_args {
if [ -n "$2" ]; then
"$@"
fi
}
function set_to_existing_file {
if [ -f "$2" ]; then
set_global "$1" "$2"
fi
}
function set_grub_virt {
if [ "$arch" == "riscv64"]; then
set_global grub_virt qemu
else
smbios -t 1 -s 0 --set smb_vendor
if [ "$smb_vendor" == QEMU ]; then
set_global grub_virt qemu
elif [ "$smb_vendor" == Google ]; then
set_global grub_virt qemu
else
set_global grub_virt baremetal
fi
fi
}
function set_rootfs_root {
if [ -z "$rootfs_root" ]; then
measurefs $root --pcr 13
probe --set partuuid --part-uuid $root
set_global rootfs_root "PARTUUID=$partuuid"
fi
}
function set_config_overrides {
set self_dev="$cmddevice"
if [ -z "$self_dev" ]; then
set self_dev="$root"
fi
regexp --set self_drive "^([^,]*,)gpt" "$self_dev"
if [ -n "$self_drive" ]; then
search.part_label CONFIG config_part "$self_drive"
if [ -n "$config_part" ]; then
set_to_existing_file config_grub_cfg "($config_part)/grub.cfg"
if [ "$grub_virt" != qemu ]; then
set_to_existing_file devicetree "($config_part)/eve.dtb"
fi
fi
fi
}
function set_rootfs_title {
cat -s rootfs_title /etc/eve-release
}
function set_crashkernel {
if [ "$eve_flavor" != xen ]; then
set_global crashkernel "crashkernel=2G-64G:128M,64G-1T:256M,1T-:512M"
fi
}
function set_generic {
set_global hv_dom0_mem_settings "dom0_mem=800M,max:800M"
set_global hv_dom0_cpu_settings "dom0_max_vcpus=1 dom0_vcpus_pin"
set_global hv_eve_mem_settings "eve_mem=650M,max:650M"
set_global hv_eve_cpu_settings "eve_max_vcpus=1"
set_global hv_ctrd_mem_settings "ctrd_mem=400M,max:400M"
set_global hv_ctrd_cpu_settings "ctrd_max_vcpus=1"
set_global hv_platform_tweaks "smt=false"
set_global hv_watchdog_timer "change=500"
set_global hv_extra_args "$hv_extra_args"
set_global dom0 /boot/kernel
set_global dom0_rootfs "root=$rootfs_root"
set_global dom0_cmdline "$linuxkit_cmdline $panic_timeout rfkill.default_state=0"
}
function set_x86_64 {
set_crashkernel
set_global load_hv_cmd multiboot2
set_global load_dom0_cmd module2
set_global load_initrd_cmd module2
set_global hv /boot/xen.gz
}
function set_x86_64_baremetal {
set_generic
set_x86_64
set_global hv_console "console=vga"
set_global hv_platform_tweaks "$hv_platform_tweaks efi=attr=uc"
set_global dom0_platform_tweaks " "
set_global dom0_console "console=tty0"
# experimental feature where we're trying to provide workarounds based
# on well known vendor/product pairs from SMBIOS. This may appear harmless
# but we need to make sure that we don't see coredumps on weird SMBIOS
# implementations
smbios -t 1 -s 0 --set smb_vendor
if [ "$smb_vendor" = "HPE" ]; then
smbios -t 1 -s 5 --set smb_product
if [ "$smb_product" = "ProLiant DL360 Gen10" ]; then
set_global hv_platform_tweaks "$hv_platform_tweaks cmos-rtc-probe=1"
fi
# On m750 BAR registers are not correctly reassigned by Linux
# if there are devices with 64bit BARs. Using UEFI assignments
if regexp -- "m750" "$smb_product"; then
set_global dom0_platform_tweaks "$dom0_platform_tweaks pci=realloc=off"
fi
fi
}
function set_x86_64_qemu {
set_generic
set_x86_64
set_global hv_console "console=com1"
set_global hv_platform_tweaks "$hv_platform_tweaks clocksource=pit"
set_global dom0_platform_tweaks "clocksource=tsc clocksource_failover=xen"
set_global dom0_console "console=ttyS0 console=hvc0"
}
function set_arm64 {
set_global load_hv_cmd xen_hypervisor
set_global load_dom0_cmd xen_module
set_global load_initrd_cmd xen_module
set_global load_devicetree_cmd devicetree
set_global hv /boot/xen.efi
set_global hv_console "console=dtuart sync_console"
set_global hv_platform_tweaks " "
set_global dom0_console "console=tty0 console=ttyS0,115200 console=hvc0"
}
function set_arm64_baremetal {
set_generic
set_arm64
set_global dom0_platform_tweaks " "
# experimental feature where we're trying to find known device trees on ARM
# note that we would rather rely on UEFI providing device tree information,
# but sometimes this can be useful and besides it is only triggered on well
# known IDs of products below:
smbios -t 1 -s 0 --set smb_vendor
if [ "$smb_vendor" = "nvidia" ]; then
smbios -t 1 -s 5 --set smb_product
if [ "$smb_product" = "p3450-0000" ]; then
set_to_existing_file devicetree /boot/dtb/nvidia/tegra210-p3450-0000.dtb
fi
fi
if [ "$smb_vendor" = "raspberrypi" ]; then
smbios -t 1 -s 5 --set smb_product
if [ "$smb_product" = "rpi" ]; then
set_to_existing_file devicetree /boot/dtb/broadcom/bcm2711-rpi-4-b.dtb
elif [ "$smb_product" = "uno-220" ]; then
set_to_existing_file devicetree /boot/dtb/broadcom/raspberrypi-uno-220.dtb
fi
fi
if [ "$smb_vendor" = "Huawei" ]; then
smbios -t 1 -s 5 --set smb_product
# turns out smb_product contains non-printable characters
# this makes grepping for XR320 our best option
if regexp -- "XR320" "$smb_product"; then
set_global dom0_console "console=ttyAMA0,115200n8"
set_global dom0_platform_tweaks "pcie_aspm=off pci=pcie_bus_perf"
fi
fi
if [ "$smb_vendor" = "rockchip" ]; then
smbios -t 1 -s 5 --set smb_product
if [ "$smb_product" = "evb_rk3399" ]; then
set_to_existing_file devicetree /boot/dtb/rockchip/rockchip-evb_rk3399.dtb
set_global dom0_console "console=ttyS2 console=ttyS2,115200n8"
set_global dom0_platform_tweaks "video=HDMI-A-1 coherent_pool=1M drm.debug=0x04"
fi
fi
}
function set_arm64_qemu {
set_generic
set_arm64
set_global dom0_console "$dom0_console console=ttyAMA0"
set_global dom0_platform_tweaks "hmp-unsafe=true"
# if running under QEMU, make sure to check dynamic partition for device trees
search.fs_label QEMU_DTB qemu_part
set_to_existing_file devicetree "($qemu_part)/eve.dtb"
}
function set_riscv64 {
set_global load_hv_cmd mini_hypervisor
set_global load_dom0_cmd mini_module
set_global load_initrd_cmd mini_module
set_global load_devicetree_cmd devicetree
set_global hv /boot/mini.efi
set_global hv_console "console=dtuart sync_console"
set_global hv_platform_tweaks " "
set_global dom0_console "console=tty0 console=ttyS0,115200 console=hvc0"
}
function set_riscv64_baremetal {
set_generic
set_riscv64
set_global dom0_platform_tweaks " "
}
function set_riscv64_qemu {
set_generic
set_riscv64
set_global dom0_console "$dom0_console console=ttyAMA0"
set_global dom0_platform_tweaks "hmp-unsafe=true"
# if running under QEMU, make sure to check dynamic partition for device trees
search.fs_label QEMU_DTB qemu_part
set_to_existing_file devicetree "($qemu_part)/eve.dtb"
}
function set_kvm_boot {
set_global load_hv_cmd echo
set_global load_dom0_cmd linux
set_global load_initrd_cmd initrd
set_global dom0_extra_args "$dom0_extra_args pcie_acs_override=downstream,multifunction"
# this may strike readers as circular, but it really isn't
# the reason we have to also set eve_flavor to kvm here is
# that it used to be that set_kvm_boot was a sanctioned way
# to flip to KVM boot sequence. IOW, it used to be an elaborate
# way to setup the value of eve_flavor and we need to keep it
# like that for now.
set_global eve_flavor kvm
}
function set_xen_boot {
# see the set_global eve_flavor kvm comment in set_kvm_boot
set_global eve_flavor xen
}
function set_eve_flavor {
# if eve_flavor is not set explicitly we assume it is
# embedded in the name of the image
if [ "$eve_flavor" != xen -a "$eve_flavor" != kvm ] ; then
if regexp -- '-xen(-|$)' $rootfs_title ; then
eve_flavor=xen
else
eve_flavor=kvm
fi
fi
}
set arch=${grub_cpu}
if [ "$arch" = "i386" ]; then
# grub CPU i386 means we are running in legacy BIOS mode
# but we can still use configuration from x86_64
arch=x86_64
fi
set_grub_virt
set_rootfs_root
set_rootfs_title
set_eve_flavor
set_${arch}_${grub_virt}
# now set a few override file names (if files exist)
set_config_overrides
set_to_existing_file efi_grub_cfg "/EFI/BOOT/grub-hv.cfg"
# process the overrides
do_if_args source $efi_grub_cfg
do_if_args source $config_grub_cfg
# setup bootflow per EVE's flavor
set_${eve_flavor}_boot
menuentry "Boot ${rootfs_title}${rootfs_title_suffix}" {
$load_hv_cmd $hv $hv_console $hv_platform_tweaks $hv_dom0_mem_settings $hv_dom0_cpu_settings $hv_extra_args
$load_dom0_cmd $dom0 $dom0_console $dom0_rootfs $hv_dom0_mem_settings $hv_dom0_cpu_settings $hv_eve_mem_settings $hv_eve_cpu_settings $hv_ctrd_mem_settings $hv_ctrd_cpu_settings $hv_watchdog_timer $dom0_platform_tweaks $dom0_cmdline $dom0_extra_args $crashkernel
do_if_args $load_devicetree_cmd $devicetree
do_if_args $load_initrd_cmd $initrd
}
submenu 'Set Boot Options' {
menuentry 'force serial console on x86/baremetal com1' {
set_global hv_console "com1=115200,8n1 console=com1"
set_global dom0_console "console=hvc0"
}
menuentry 'set x86/baremetal boot options' {
set_x86_64_baremetal
}
menuentry 'set x86/qemu boot options' {
set_x86_64_qemu
}
menuentry 'set ARM/baremetal boot options' {
set_arm64_baremetal
}
menuentry 'set ARM/qemu boot options' {
set_arm64_qemu
}
menuentry 'set RISCV/baremetal boot options' {
set_riscv64_baremetal
}
menuentry 'set RISCV/qemu boot options' {
set_riscv64_qemu
}
menuentry 'skip hypervisor booting' {
set_kvm_boot
}
menuentry 'show boot options' {
set_global zboot1 "$load_hv_cmd $hv $hv_console $hv_platform_tweaks $hv_dom0_mem_settings $hv_dom0_cpu_settings $hv_extra_args"
set_global zboot2 "$load_dom0_cmd $dom0 $dom0_console $dom0_rootfs $hv_dom0_mem_settings $hv_dom0_cpu_settings $hv_eve_mem_settings $hv_eve_cpu_settings $hv_ctrd_mem_settings $hv_ctrd_cpu_settings $hv_watchdog_timer $dom0_platform_tweaks $dom0_cmdline $dom0_extra_args"
set_global zboot3 "do_if_args $load_devicetree_cmd $devicetree"
set_global zboot4 "do_if_args $load_initrd_cmd $initrd"
}
if [ -n "$do_extra_submenus" ]; then
$do_extra_submenus
fi
}