+sub prepare_systemd_boot_esp {
+ my ($espdev, $targetdir) = @_;
+
+ my $espuuid = find_dev_by_uuid($espdev);
+ my $espmp = "var/tmp/$espuuid";
+ mkdir "$targetdir/$espmp";
+
+ syscmd("mount -n $espdev -t vfat $targetdir/$espmp") == 0 ||
+ die "unable to mount ESP $espdev\n";
+
+ File::Path::make_path("$targetdir/$espmp/EFI/proxmox") ||
+ die "unable to create directory $targetdir/$espmp/EFI/proxmox\n";
+
+ syscmd("chroot $targetdir bootctl --no-variables --path /$espmp install") == 0 ||
+ die "unable to install systemd-boot loader\n";
+ write_config("timeout 3\ndefault proxmox-*\n",
+ "$targetdir/$espmp/loader/loader.conf");
+ syscmd("chroot $targetdir /etc/kernel/postinst.d/zz-pve-efiboot") == 0 ||
+ die "unable to generate systemd-boot config\n";
+
+ syscmd("umount $targetdir/$espmp") == 0 ||
+ die "unable to umount ESP $targetdir/$espmp\n";
+
+}