summary refs log tree commit diff
path: root/pkgs/tools/misc/memtest86-efi
diff options
context:
space:
mode:
authorEmily <vcs@emily.moe>2020-05-03 01:49:30 +0100
committerEmily <vcs@emily.moe>2020-05-03 03:12:27 +0100
commit3ae05b64b6b25ef6bdefa085ec485a9ed16afb44 (patch)
tree0c6710b5354d25d92a1d0a177dcde337b8b61662 /pkgs/tools/misc/memtest86-efi
parentac8066c144c76dfbc99a866049b61acaaccb470f (diff)
downloadnixpkgs-3ae05b64b6b25ef6bdefa085ec485a9ed16afb44.tar
nixpkgs-3ae05b64b6b25ef6bdefa085ec485a9ed16afb44.tar.gz
nixpkgs-3ae05b64b6b25ef6bdefa085ec485a9ed16afb44.tar.bz2
nixpkgs-3ae05b64b6b25ef6bdefa085ec485a9ed16afb44.tar.lz
nixpkgs-3ae05b64b6b25ef6bdefa085ec485a9ed16afb44.tar.xz
nixpkgs-3ae05b64b6b25ef6bdefa085ec485a9ed16afb44.tar.zst
nixpkgs-3ae05b64b6b25ef6bdefa085ec485a9ed16afb44.zip
memtest86-efi: compute ESP offset from partitions
Diffstat (limited to 'pkgs/tools/misc/memtest86-efi')
-rw-r--r--pkgs/tools/misc/memtest86-efi/default.nix33
1 files changed, 24 insertions, 9 deletions
diff --git a/pkgs/tools/misc/memtest86-efi/default.nix b/pkgs/tools/misc/memtest86-efi/default.nix
index f2adadc0840..c33aa074404 100644
--- a/pkgs/tools/misc/memtest86-efi/default.nix
+++ b/pkgs/tools/misc/memtest86-efi/default.nix
@@ -1,4 +1,10 @@
-{ fetchzip, lib, stdenv, mtools }:
+{ stdenv
+, lib
+, fetchzip
+, utillinux
+, jq
+, mtools
+}:
 
 stdenv.mkDerivation rec {
   pname = "memtest86-efi";
@@ -22,19 +28,28 @@ stdenv.mkDerivation rec {
     stripRoot = false;
   };
 
-  nativeBuildInputs = [ mtools ];
+  nativeBuildInputs = [
+    utillinux
+    jq
+    mtools
+  ];
 
   installPhase = ''
-    mkdir -p $out $TEMP/memtest86-files
-
     # memtest86 is distributed as a bootable USB image.  It contains the actual
     # memtest86 EFI app.
     #
-    # The following uses dd and mcopy to extract the actual EFI app from the
-    # usb image so that it can be installed directly on the hard drive.
-    dd if=$src/memtest86-usb.img of=$TEMP/ESP.img skip=2048
-    mcopy -i $TEMP/ESP.img ::/EFI/BOOT/ $TEMP/memtest86-files/
-    mv $TEMP/memtest86-files/BOOT/* $out/
+    # The following uses sfdisk to calculate the offset of the FAT EFI System
+    # Partition in the disk image, and mcopy to extract the actual EFI app from
+    # the filesystem so that it can be installed directly on the hard drive.
+    IMG=$src/memtest86-usb.img
+    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; {