Put boot image into ESP
This commit is contained in:
parent
fe3e0da51d
commit
5006257230
|
@ -10,6 +10,8 @@ pkgs.stdenv.mkDerivation {
|
|||
zstd
|
||||
];
|
||||
|
||||
inherit espImage;
|
||||
|
||||
buildCommand = ''
|
||||
img=./temp.raw
|
||||
blockSize=512
|
||||
|
@ -24,8 +26,8 @@ pkgs.stdenv.mkDerivation {
|
|||
truncate --size=$esbByteOffset $img
|
||||
|
||||
# Concatentenate the ESP
|
||||
echo "Concatenate ESP ${espImage}"
|
||||
zstdcat ${espImage} >> $img
|
||||
echo "Concatenate ESP $espImage"
|
||||
zstdcat $espImage >> $img
|
||||
|
||||
imgBytes=$(stat --format=%s $img)
|
||||
echo "Image is $(( $imgBytes >> 20 )) MiB with ESP partition"
|
||||
|
|
|
@ -23,29 +23,32 @@ in pkgs.stdenv.mkDerivation {
|
|||
"configfile"
|
||||
"efi_gop"
|
||||
"efi_uga"
|
||||
"ext2"
|
||||
"fat"
|
||||
"gzio"
|
||||
"multiboot"
|
||||
"multiboot2"
|
||||
"normal"
|
||||
"part_gpt"
|
||||
"search_fs_uuid"
|
||||
"search"
|
||||
];
|
||||
|
||||
buildCommand = ''
|
||||
img=tmp.raw
|
||||
bootdir=EFI/boot/
|
||||
mkdir -p $bootdir
|
||||
bootdir=./espRoot/boot/
|
||||
grubdir=./espRoot/boot/grub
|
||||
efidir=./espRoot/EFI/boot
|
||||
|
||||
mkdir -p $bootdir $efidir $grubdir
|
||||
|
||||
cat <<EOF > embedded.cfg
|
||||
insmod configfile
|
||||
insmod efi_gop
|
||||
insmod efi_uga
|
||||
insmod ext2
|
||||
insmod fat
|
||||
insmod normal
|
||||
insmod part_gpt
|
||||
insmod search_fs_uuid
|
||||
search.fs_uuid ${config.genode.boot.storeFsUuid} root
|
||||
search --set=root --label EFIBOOT
|
||||
set prefix=($root)/boot/grub
|
||||
configfile /boot/grub/grub.cfg
|
||||
EOF
|
||||
|
@ -54,17 +57,34 @@ in pkgs.stdenv.mkDerivation {
|
|||
|
||||
${grub'}/bin/grub-mkimage \
|
||||
--config=embedded.cfg \
|
||||
--output=$bootdir/boot${targetArch}.efi \
|
||||
--prefix=/boot/grub \
|
||||
--output=$efidir/boot${targetArch}.efi \
|
||||
--prefix=/sigil/grub \
|
||||
--format=${grub'.grubTarget} \
|
||||
$MODULES
|
||||
|
||||
cat > extraPrepareConfig.sh <<< '${config.boot.loader.grub.extraPrepareConfig}'
|
||||
substituteInPlace extraPrepareConfig.sh \
|
||||
--replace '${pkgs.coreutils}' '${pkgs.buildPackages.coreutils}' \
|
||||
--replace '@bootPath@' "$bootdir"
|
||||
source extraPrepareConfig.sh
|
||||
|
||||
cat <<EOF > $grubdir/grub.cfg
|
||||
set timeout=3
|
||||
set default=0
|
||||
set gfxpayload=auto
|
||||
|
||||
${config.boot.loader.grub.extraEntries}
|
||||
EOF
|
||||
|
||||
grub-script-check $grubdir/grub.cfg
|
||||
|
||||
|
||||
# Make the ESP image twice as large as necessary
|
||||
imageBytes=$(du --summarize --block-size=4096 --total $bootdir | tail -1 | awk '{ print int($1 * 8192) }')
|
||||
imageBytes=$(du --summarize --block-size=4096 --total espRoot | tail -1 | awk '{ print int($1 * 8192) }')
|
||||
|
||||
truncate --size=$imageBytes $img
|
||||
mkfs.vfat -n EFIBOOT --invariant $img
|
||||
mcopy -sv -i $img EFI ::
|
||||
mcopy -sv -i $img espRoot/* ::
|
||||
fsck.vfat -nv $img
|
||||
|
||||
zstd --verbose --no-progress ./$img -o $out
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
{ config, lib, pkgs, extraInputs ? [ ], contents }:
|
||||
|
||||
let
|
||||
grub' = pkgs.buildPackages.grub2_efi;
|
||||
|
||||
copyEris = lib.strings.concatMapStrings ({ source, target }: ''
|
||||
cp -a --reflink=auto "${source}" "./rootImage/${target}"
|
||||
'') contents;
|
||||
|
@ -12,7 +10,6 @@ in pkgs.stdenv.mkDerivation {
|
|||
|
||||
nativeBuildInputs = with pkgs.buildPackages; [
|
||||
e2fsprogs.bin
|
||||
grub'
|
||||
libfaketime
|
||||
perl
|
||||
fakeroot
|
||||
|
@ -23,23 +20,7 @@ in pkgs.stdenv.mkDerivation {
|
|||
img=temp.raw
|
||||
|
||||
# Create nix/store before copying path
|
||||
mkdir -p ./rootImage/boot/grub ./rootImage/nix/store
|
||||
|
||||
cat > extraPrepareConfig.sh <<< '${config.boot.loader.grub.extraPrepareConfig}'
|
||||
substituteInPlace extraPrepareConfig.sh \
|
||||
--replace '${pkgs.coreutils}' '${pkgs.buildPackages.coreutils}' \
|
||||
--replace '@bootPath@' './rootImage/boot'
|
||||
source extraPrepareConfig.sh
|
||||
|
||||
cat <<EOF > ./rootImage/boot/grub/grub.cfg
|
||||
set timeout=3
|
||||
set default=0
|
||||
set gfxpayload=auto
|
||||
|
||||
${config.boot.loader.grub.extraEntries}
|
||||
EOF
|
||||
|
||||
grub-script-check ./rootImage/boot/grub/grub.cfg
|
||||
mkdir -p ./rootImage/nix/store
|
||||
|
||||
(
|
||||
GLOBIGNORE=".:.."
|
||||
|
@ -65,7 +46,8 @@ in pkgs.stdenv.mkDerivation {
|
|||
faketime -f "1970-01-01 00:00:01" fakeroot mkfs.ext2 -L NIXOS_GENODE -U ${config.genode.boot.storeFsUuid} -d ./rootImage $img
|
||||
|
||||
export EXT2FS_NO_MTAB_OK=yes
|
||||
# I have ended up with corrupted images sometimes, I suspect that happens when the build machine's disk gets full during the build.
|
||||
# I have ended up with corrupted images sometimes, I suspect that
|
||||
# happens when the build machine's disk gets full during the build.
|
||||
if ! fsck.ext2 -n -f $img; then
|
||||
echo "--- Fsck failed for EXT2 image of $bytes bytes (numInodes=$numInodes, numDataBlocks=$numDataBlocks) ---"
|
||||
cat errorlog
|
||||
|
|
Loading…
Reference in New Issue