@@ -125,10 +125,12 @@ sgdisk "$ARTIFACT_NAME.img" --print
125125# consumers can easily build the names of the individual partitions as
126126# needed.
127127#
128- LOOPNAME=$( kpartx -asv " $ARTIFACT_NAME .img" |
129- head -n1 |
130- awk ' { print $3 }' |
131- sed ' s/^\(loop[0-9]\+\)p[0-9]\+$/\1/' )
128+ # LOOPNAME=$(kpartx -asv "$ARTIFACT_NAME.img" |
129+ # head -n1 |
130+ # awk '{ print $3 }' |
131+ # sed 's/^\(loop[0-9]\+\)p[0-9]\+$/\1/')
132+
133+ LOOPNAME=$( losetup --find --partscan --show " $ARTIFACT_NAME .img" )
132134
133135#
134136# We use a consistent naming scheme for the root filesystems that are
@@ -146,7 +148,7 @@ zpool create -d \
146148 -O compression=on \
147149 -R " $DIRECTORY " \
148150 -t " $FSNAME " \
149- rpool " /dev/mapper/ ${LOOPNAME} p1"
151+ rpool " ${LOOPNAME} p1"
150152
151153zfs create \
152154 -o canmount=off \
@@ -293,7 +295,7 @@ mkdir -p "/var/crash"
293295mount -t zfs " $FSNAME /crashdump" " /var/crash"
294296
295297# Make the vfat partition
296- mkfs.vfat -F32 /dev/mapper/ ${LOOPNAME} p2
298+ mkfs.vfat -F32 ${LOOPNAME} p2
297299
298300#
299301# Populate the root filesystem with the contents of the "binary" directory
@@ -345,16 +347,25 @@ for dir in /dev /proc /sys; do
345347done
346348
347349#
348- # Mount /boot/efi and do grub and bootctl install
350+ # Mount ESP and bootctl install
349351#
350- EFI_DIR=" /mnt/boot/efi"
351- chroot " $DIRECTORY " mkdir -p $EFI_DIR
352- chroot " $DIRECTORY " mount /dev/mapper/${LOOPNAME} p2 $EFI_DIR
352+ EFI_DIR=$( chroot " $DIRECTORY " mktemp -d -p " /var/tmp/" -t delphix_efi.XXXXXXX)
353+ chroot " $DIRECTORY " mount -o umask=077 ${LOOPNAME} p2 $EFI_DIR
354+
355+ ESP=$EFI_DIR
356+ BOOTLOADER_ID=" ${BOOTLOADER_ID:- systemd} "
357+ echo " [*] Installing systemd-boot to $ESP ..."
358+ # 1. Create required directories
359+ chroot " $DIRECTORY " mkdir -p " $ESP /EFI/systemd" " $ESP /EFI/BOOT" " $ESP /loader/entries"
360+
361+ # 2. Copy systemd-boot binaries
362+ chroot " $DIRECTORY " cp /usr/lib/systemd/boot/efi/systemd-bootx64.efi " $ESP /EFI/$BOOTLOADER_ID /"
363+ chroot " $DIRECTORY " cp /usr/lib/systemd/boot/efi/systemd-bootx64.efi " $ESP /EFI/BOOT/BOOTX64.EFI"
353364
354365# Copy the latest kernel into EFI boot directory
355366chroot " $DIRECTORY " cp /boot/initrd.img $EFI_DIR
356367chroot " $DIRECTORY " cp /boot/vmlinuz $EFI_DIR
357- chroot " $DIRECTORY " bootctl --esp-path=$EFI_DIR install --no-variables
368+ # chroot "$DIRECTORY" bootctl --esp-path=$EFI_DIR install --no-variables
358369
359370# Use GRUB_CMDLINE_LINUX_DEFAULT boot options
360371source $DIRECTORY /etc/default/grub.d/override.cfg
@@ -385,6 +396,7 @@ auto-firmware yes
385396EOF
386397
387398chroot " $DIRECTORY " umount $EFI_DIR
399+ chroot " $DIRECTORY " rm -r $EFI_DIR
388400
389401for dir in /dev /proc /sys; do
390402 retry 5 10 umount -R " ${DIRECTORY}${dir} "
@@ -398,4 +410,5 @@ umount "$DIRECTORY/var/tmp"
398410umount " /var/crash"
399411retry 5 10 zfs umount " $FSNAME /ROOT/$FSNAME /root"
400412retry 5 10 zpool export " $FSNAME "
401- kpartx -d " $ARTIFACT_NAME .img"
413+ # kpartx -d "$ARTIFACT_NAME.img"
414+ losetup -d $LOOPNAME
0 commit comments