5 .
/usr
/share
/pve-kernel-helper
/scripts
/functions
7 _add_entry_to_list_file
() {
11 if [ -e "$file" ]; then
12 cp "$file" "$file.new"
14 echo "$entry" >> "$file.new"
15 sort -uo "$file.new" "$file.new"
16 mv "$file.new" "$file"
19 _remove_entry_from_list_file
() {
23 # guard against removing whole file by accident!
24 if [ -z "$entry" ]; then
25 echo "cannot remove empty entry from '$file'."
29 if [ -e "$file" ]; then
30 grep -vFx "$entry" "$file" > "$file.new" || true
31 mv "$file.new" "$file"
33 echo "'$file' does not exist.."
37 _get_partition_info
() {
38 if [ ! -e "$1" ]; then
39 warn
"E: '$1' does not exist!"
43 if [ ! -b "$bdev" ]; then
44 warn
"E: '$bdev' is not a block device!"
52 -o 'UUID,SIZE,FSTYPE,PARTTYPE,PKNAME,MOUNTPOINT' \
55 if [ -z "$bdev_info" ]; then
56 warn
"E: unable to get information about block device '$1'!"
60 count
=$
(echo "$bdev_info" |
grep -c '^')
61 if [ "$count" -ne '1' ]; then
63 warn
"E: block device '$1' has children!"
70 if [ -z "$PKNAME" ]; then
71 warn
"E: cannot determine parent device of '$1' - please provide a partition, not a full disk."
75 if [ -n "$SIZE" ] && [ "$SIZE" -lt 268435456 ]; then
76 warn
"E: '$1' is too small (<256M)."
80 if [ -n "$MOUNTPOINT" ]; then
81 warn
"E: '$1' is mounted on '$MOUNTPOINT' - exiting."
90 _get_partition_info
"$part"
92 if [ -n "$FSTYPE" ]; then
93 if [ -z "$force" ] ||
[ "$force" != '--force' ]; then
94 warn
"E: '$part' contains a filesystem ('$FSTYPE') - exiting (use --force to override)"
99 part_basename
=$
(basename "$part")
100 if [ -z "$part_basename" ]; then
101 warn
"E: unable to determine basename of '$part'"
105 part_num
=$
(cat /sys
/block
/"$PKNAME"/"$part_basename"/partition
)
106 if [ -z "$part_num" ]; then
107 warn
"E: unable to determine partition number of '$part'"
111 if [ -z "$PARTTYPE" ] ||
[ "$PARTTYPE" != "$ESPTYPE" ]; then
112 echo "Setting partition type of '$part' to '$ESPTYPE'.."
113 sgdisk
"-t$part_num:$ESPTYPE" "/dev/$PKNAME"
114 echo "Calling 'udevadm settle'.."
115 udevadm settle
--timeout=5
118 echo "Formatting '$part' as vfat.."
119 mkfs.vfat
-F 32 "$part"
127 _get_partition_info
"$part"
129 if [ -z "$PARTTYPE" ] ||
[ "$PARTTYPE" != "$ESPTYPE" ]; then
130 warn
"E: '$part' has wrong partition type (!= $ESPTYPE)."
134 if [ -z "$FSTYPE" ] ||
[ "$FSTYPE" != 'vfat' ]; then
135 warn
"E: '$part' has wrong filesystem (!= vfat)."
139 if [ -z "$UUID" ]; then
140 warn
"E: '$part' has no UUID set, required for mounting."
144 esp_mp
="/var/tmp/espmounts/$UUID"
147 echo "Mounting '$part' on '$esp_mp'."
148 mount
-t vfat
"$part" "$esp_mp"
150 echo "Installing systemd-boot.."
151 mkdir
-p "$esp_mp/$PMX_ESP_DIR"
152 bootctl
--path "$esp_mp" install
154 echo "Configuring systemd-boot.."
155 echo "timeout 3" > "$esp_mp/$PMX_LOADER_CONF.tmp"
156 echo "default proxmox-*" >> "$esp_mp/$PMX_LOADER_CONF.tmp"
157 mv "$esp_mp/$PMX_LOADER_CONF.tmp" "$esp_mp/$PMX_LOADER_CONF"
158 echo "Unmounting '$part'."
161 echo "Adding '$part' to list of synced ESPs.."
162 _add_entry_to_list_file
"$ESP_LIST" "$UUID"
164 echo "Refreshing kernels and initrds.."
169 if [ ! -e "/dev/disk/by-uuid/" ]; then
170 warn
'E: /dev/disk/by-uuid does not exist, aborting!'
173 echo -n "Checking whether ESP '$curr_uuid' exists.. "
174 if [ -e "/dev/disk/by-uuid/$curr_uuid" ]; then
178 if [ -z "$dry_run" ] ||
[ "$dry_run" != '--dry-run' ]; then
179 _remove_entry_from_list_file
"$ESP_LIST" "$curr_uuid"
186 rm -f "$ESP_LIST".tmp
187 loop_esp_list _clean_impl
188 if [ "$?" -eq 2 ]; then
189 warn
"E: $ESP_LIST does not exist."
192 if [ -e "$ESP_LIST".tmp
]; then
193 mv "$ESP_LIST".tmp
"$ESP_LIST"
199 hookscripts
='pve-auto-removal zz-pve-efiboot'
201 if [ -n "$hook" ]; then
202 if echo "$hookscripts" |
grep -sqE "(^|[[:space:]]+)$hook([[:space:]]+|$)"; then
205 warn
"E: '$hook' is not a valid hook script name.";
210 for script in $hookscripts; do
211 scriptpath
="/etc/kernel/postinst.d/$script"
212 if [ -f "$scriptpath" ] && [ -x "$scriptpath" ]; then
213 echo "Running hook script '$script'.."
216 warn
"Hook script '$script' not found or not executable, skipping."
224 if [ -z "$ver" ]; then
225 warn
"E: <kernel-version> is mandatory"
230 if [ ! -e "/boot/vmlinuz-$ver" ]; then
231 warn
"E: no kernel image found in /boot for '$ver', not adding."
234 _add_entry_to_list_file
"$MANUAL_KERNEL_LIST" "$ver"
235 echo "Added kernel '$ver' to manual kernel list. Use the 'refresh' command to update the ESPs."
241 if [ -z "$ver" ]; then
242 warn
"E: <kernel-version> is mandatory"
247 if grep -sqFx "$ver" "$MANUAL_KERNEL_LIST"; then
248 _remove_entry_from_list_file
"$MANUAL_KERNEL_LIST" "$ver"
249 echo "Removed kernel '$ver' from manual kernel list. Use the 'refresh' command to update the ESPs."
251 echo "Kernel '$ver' not found in manual kernel list."
256 boot_kernels
="$(boot_kernel_list)"
258 if [ -e "$MANUAL_KERNEL_LIST" ]; then
259 manual_kernels
="$(cat "$MANUAL_KERNEL_LIST" || true)"
260 boot_kernels
="$(echo "$boot_kernels" | grep -Fxv -f "$MANUAL_KERNEL_LIST" || true)"
263 if [ -z "$manual_kernels" ]; then
264 manual_kernels
="None."
267 echo "Manually selected kernels:"
268 echo "$manual_kernels"
270 echo "Automatically selected kernels:"
275 warn
"USAGE: $0 <commands> [ARGS]"
277 warn
" $0 format <partition> [--force]"
278 warn
" $0 init <partition>"
279 warn
" $0 clean [--dry-run]"
280 warn
" $0 refresh [--hook <name>]"
281 warn
" $0 kernel <add|remove> <kernel-version>"
282 warn
" $0 kernel list"
287 echo "USAGE: $0 format <partition> [--force]"
289 echo " format <partition> as EFI system partition. Use --force to format even if <partition> is currently in use."
291 echo "USAGE: $0 init <partition>"
293 echo " initialize EFI system partition at <partition> for automatic synchronization of pve-kernels and their associated initrds."
295 echo "USAGE: $0 clean [--dry-run]"
297 echo " remove no longer existing EFI system partition UUIDs from $ESP_LIST. Use --dry-run to only print outdated entries instead of removing them."
299 echo "USAGE: $0 refresh [--hook <name>]"
301 echo " refresh all configured EFI system partitions. Use --hook to only run the specified hook, omit to run all."
303 echo "USAGE: $0 kernel <add|remove> <kernel-version>"
305 echo " add/remove pve-kernel with ABI <kernel-version> to list of synced kernels, in addition to automatically selected ones."
306 echo " NOTE: you need to manually run 'refresh' once you're finished with adding/removing kernels from the list"
308 echo "USAGE: $0 kernel list"
310 echo " list kernel versions currently selected for inclusion on ESPs."
323 warn
"E: <partition> is mandatory."
332 reexec_in_mountns
"$@"
335 warn
"E: <partition> is mandatory."
350 if [ "$#" -eq 0 ]; then
352 elif [ "$#" -eq 2 ] && [ "$1" = "--hook" ]; then
363 warn
"E: subcommand is mandatory for 'kernel'."
383 warn
"E: invalid 'kernel' subcommand '$cmd'."
396 warn
"Invalid/unknown command '$1'."