Rpi4, usb boot+gpt

I broke a few microsd due to too many writes on the rpi4, so I’m looking into going full usb.

I am also using it as a custom small NAS, with 2x4TB hd
…so I also need GPT, otherwise I would waste half of the disks with only MBR.

So I took my usb key and started doing tests:

My strategy was (tested first with raspberry-os)

  1. flash the latest successful hydra build on a usb key (don’t boot yet, gpt requires some space at the end of the disk and at first boot the os will resize to max space, making you unable to create a gpt without manually resizing down again)
  2. gdisk /dev/your_usb_key
  3. if asked, select 1 - MBR and ignore possible old corrupt backup GPT
  4. x r f (advanced, recovery, load from MBR to create GPT Note: we might have now changed the partitions GUID)
  5. unclear if the next step are needed, probably not. I did it anyway in case the boot process kept looking for the MBR partition
  6. h (make hybrid MBR)
  7. 1 2 (select gpt partition 1 and 2 to be written to mbr)
  8. N (first partition is NOT EFI GPT)
  9. 0b N (first gpt partition will become first mbr, type 0b, non bootable)
  10. 83 Y (second gpt partition will become second mbr, type 83, bootable)
  11. o and p to print the MBR and GPT tables
  12. N, m (Ignore additional space, go to normal menu)
  13. t 1 ef00 w (type of first partition to ef00, then write and exit)

This works up until u-boot, which recognizes the usb key, but then goes directly to network boot.

After many little variations in how the partitions were (re)created, forcing the new partitions to have the same GUIDs as the old ones I never went further.

Has anyone tried anything similar? Any info on what u-boot needs and why it can’t go further?

How did you wear out your sd card? to my rebuilds/build? I’m interesting in getting nix build slaves and nix cross compilation going to the platform.

I’m also wanna think about ipxe booting…so much code, so little time.

Don’t really know for sure, but I did lots of tests and left running an almost empty system with 5-6 containers (samba, freeipa, pihole, nextcloud and more) for a couple of months.

The containers (podman) were on the hard disk though (both the base and the mounted dirs), so my guess is that it probably was a lot of logging through journald. No active services should have touched the microsd.

Going back on topic, I think the problem I have with booting is with 4TB drives + gpt and u-boot.
Basically I found out I can easily boot with GPT no problem…on a 8GB usb key.
I can not on a 4TB drive, the errors I have are related to wrong GPT signatures.
Something tells me it’s u-boot, maybe it’s the 32bit version and drives > 2TB require the 64bit version, but I am not sure and I do not know how to verify or test.

I tried opening a ticket here, too:
https://github.com/NixOS/nixpkgs/issues/114157

Some quick googling indicates that u-boot might not support partitions/disks larger than 2TB…

Yes/no.
In the u-boot source I found this ( https://github.com/mwalle/u-boot/blob/efad30ae5cc2bb96a08c781855f27aadd790b7c7/disk/part_efi.c#L9 ) :

/*
 * NOTE:
 *   when CONFIG_SYS_64BIT_LBA is not defined, lbaint_t is 32 bits; this
 *   limits the maximum size of addressable storage to < 2 tebibytes
 */

so maybe it would be enough to recompile u-boot with that defined?
I have zero experience with u-boot unfortunately and I don’t understand nixos enough to recompile u-boot properly

It may be as simple to patch include/config/rpi.h defines that…, i’m not uboot build expert, but i’d like to get there.

So I tried:

file: pkgs/misc/uboot/default.nix

   ubootRaspberryPi4_64bit = buildUBoot {
     defconfig = "rpi_4_defconfig";
     extraMeta.platforms = ["aarch64-linux"];
+    extraMakeFlags = [ "CONFIG_LBA48=1" "CONFIG_SYS_64BIT_LBA=1" ];
     filesToInstall = ["u-boot.bin"];
   };

then patched (badly) a few other things, recompiled the whole raspberrypi4 nixos sd image, copied all the /boot to my 4TB drive, still the same

I still get the GPT invalid header signature just like before :frowning: