Merge pull request #86623 from emilazy/refactor-memtest86-efi

memtest86-efi: compute ESP offset from partitions
This commit is contained in:
Dennis Gosnell 2020-05-04 10:17:58 +09:00 committed by GitHub
commit d9b517fab9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,10 @@
{ fetchzip, lib, stdenv, mtools }: { stdenv
, lib
, fetchzip
, utillinux
, jq
, mtools
}:
stdenv.mkDerivation rec { stdenv.mkDerivation rec {
pname = "memtest86-efi"; pname = "memtest86-efi";
@ -22,19 +28,28 @@ stdenv.mkDerivation rec {
stripRoot = false; stripRoot = false;
}; };
nativeBuildInputs = [ mtools ]; nativeBuildInputs = [
utillinux
jq
mtools
];
installPhase = '' installPhase = ''
mkdir -p $out $TEMP/memtest86-files
# memtest86 is distributed as a bootable USB image. It contains the actual # memtest86 is distributed as a bootable USB image. It contains the actual
# memtest86 EFI app. # memtest86 EFI app.
# #
# The following uses dd and mcopy to extract the actual EFI app from the # The following uses sfdisk to calculate the offset of the FAT EFI System
# usb image so that it can be installed directly on the hard drive. # Partition in the disk image, and mcopy to extract the actual EFI app from
dd if=$src/memtest86-usb.img of=$TEMP/ESP.img skip=2048 # the filesystem so that it can be installed directly on the hard drive.
mcopy -i $TEMP/ESP.img ::/EFI/BOOT/ $TEMP/memtest86-files/ IMG=$src/memtest86-usb.img
mv $TEMP/memtest86-files/BOOT/* $out/ ESP_OFFSET=$(sfdisk --json $IMG | jq -r '
# Partition type GUID identifying EFI System Partitions
def ESP_GUID: "C12A7328-F81F-11D2-BA4B-00A0C93EC93B";
.partitiontable |
.sectorsize * (.partitions[] | select(.type == ESP_GUID) | .start)
')
mkdir $out
mcopy -vsi $IMG@@$ESP_OFFSET ::'/EFI/BOOT/*' $out/
''; '';
meta = with lib; { meta = with lib; {