Skip to content

Instantly share code, notes, and snippets.

@baloo
Created February 21, 2020 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baloo/200a07e27ea25559ddf619dab05391fb to your computer and use it in GitHub Desktop.
Save baloo/200a07e27ea25559ddf619dab05391fb to your computer and use it in GitHub Desktop.
{ pkgs
, lkl
, systemd
, glibc
, libfaketime
, luksTpmInitramfs
}:
let
in
pkgs.stdenv.mkDerivation {
name = "vfat-kernel-fs.img";
nativeBuildInputs = [ lkl systemd libfaketime ];
buildCommand =
''
img=$out
set -x
echo ${systemd.out}
systemdstub=${systemd.out}/lib/systemd/boot/efi/linuxx64.efi.stub
#echo -n "console=ttyS0 " > kernel-command-line.txt
echo -n "console=tty0 " > kernel-command-line.txt
echo -n "console=ttyS0,115200n8 " >> kernel-command-line.txt
echo -n "panic=3 " >> kernel-command-line.txt
vmlinuz_file=/home/baloo/dev/kernel-builder/build/build-5.5.5/arch/x86/boot/bzImage
initrd_file="${luksTpmInitramfs.initrd}/initrd"
objcopy \
--add-section .osrel="/usr/lib/os-release" --change-section-vma .osrel=0x20000 \
--add-section .cmdline="kernel-command-line.txt" --change-section-vma .cmdline=0x30000 \
--add-section .linux="$vmlinuz_file" --change-section-vma .linux=0x40000 \
--add-section .initrd="$initrd_file" --change-section-vma .initrd=0x3000000 \
$systemdstub linux.efi
ls -la linux.efi
IMAGE_ROOTFS_ALIGNMENT=$((2048 * 512))
PART1_SIZE=$(( 80 * 1024 * 1024))
truncate -s $PART1_SIZE part1
faketime -f "1970-01-01 00:00:01" ${pkgs.dosfstools}/bin/mkfs.fat -n EFISYS -s2 -F32 part1
faketime -f "1970-01-01 00:00:01" mkdir EFI
faketime -f "1970-01-01 00:00:01" mkdir EFI/Linux
faketime -f "1970-01-01 00:00:01" mkdir EFI/boot
faketime -f "1970-01-01 00:00:01" install linux.efi EFI/Linux/
faketime -f "1970-01-01 00:00:01" install linux.efi EFI/boot/BOOTX64.EFI
#find EFI -ls
# Copy to /EFI/Linux/
type cptofs
cptofs -t vfat -i part1 EFI /
#cptofs -t vfat -i part1 EFI/Linux /EFI/Linux
#cptofs -t vfat -i part1 EFI/Linux/linux.efi /EFI/Linux/
truncate -s $IMAGE_ROOTFS_ALIGNMENT $img
cat part1 >> $img
truncate -s +4096 $img
${pkgs.parted}/sbin/parted \
--script \
--align optimal \
$img \
mklabel gpt mkpart ESP $IMAGE_ROOTFS_ALIGNMENT"B" '100%' set 1 boot on
${pkgs.gptfdisk}/bin/sgdisk \
--disk-guid=97FD5997-D90B-4AA3-8D16-C1723AEA73C1 \
--partition-guid=1:1C06F03B-704E-4657-B9CD-681A087A2FDC \
$img
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment