You are not logged in.

#1 2016-05-29 15:22:42

duane
Member
Registered: 2016-05-25
Posts: 8

Fitting UEFI + GPT into an existing disk partition structure

I moved a hard drive into a new system with GPT and UEFI. I didn't want to repartition or resize partitions to handle the EFI system partition (ESP). Luckily, I had originally partitioned the drive on 1MB boundaries: the first partition started on sector 2048 (512B sectors) and I had almost 1 MB of space at the end of the drive. This easily allowed the GPT to fit at the start and the backup GPT to fit at the end of the disk. I still had from sector 34 through sector 1023 to install the ESP.

Everyone says this partition must be at least 256MB in size. This number is determined by the minimum number (65525) of clusters FAT32 (default ESP file system) requires. If the number of bytes/sector is 512, the number is 32MB. This is assuming that you are formatting the FAT file system with 1 sector/cluster. The default is 2 sectors/cluster, so you would have to double the aformentioned sized. This takes a lot of space IMHO. There is a fix though.

The UEFI standard also says the firmware must also support FAT16 and FAT12 for removable devices. You can use one of these file systems for the ESP. There is just one small problem. After seeing FAT12/16, the firmware will treat the partition as on a removable device and only allow one boot loader. Instead of multiple boot loaders in EFI/vendor/something<arch>.EFI, you can only have EFI/BOOT/BOOT<arch>.EFI where <arch> is the system architecture like "X64".
You can tell grub to load its boot loader in EFI/BOOT/BOOT<arch>.EFI by appending the --removable option to grub-install.

grub-install --efi-directory=/boot/efi --removable         # ESP partition mounted on boot/efi, could have been temporary mount point on /mnt

The FAT12/16 file system will fit in sectors 34-2047 for 512 B sector size disks (sectors 5-255 on 4096B sector size disks). This is about 1MB, the grub boot loader on my system was about 22kB, leaving lots of room.
BTW I started my EPS on sector 40 without thinking just because I'm used to aligning my file systems on 4kB boundaries, but FAT is a 512B file system so it doesn't require this. Oh well, still left plenty of space for grub.

If you want to dual boot, you can use GRUB like always for this purpose. It just resides inside the EPS instead of in the first few sectors of unallocated space after the MBR.

Last edited by duane (2016-06-01 12:24:26)

Offline

#2 2016-05-29 16:46:05

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,772

Re: Fitting UEFI + GPT into an existing disk partition structure

This is really good information.  Would you consider adding it to the Wiki?  It would be the better place for this.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2016-05-31 08:29:18

Head_on_a_Stick
Member
From: London
Registered: 2014-02-20
Posts: 7,732
Website

Re: Fitting UEFI + GPT into an existing disk partition structure

duane wrote:

I moved a hard drive into a new system with GPT and UEFI. I didn't want to repartition or resize partitions to handle the GPT partition. Luckily, I had originally partitioned the drive on 1MB boundaries: the first partition started on sector 2048 (512B sectors) and I had almost 1 MB of space at the end of the drive. This easily allowed the GPT to fit at the start and the backup GPT to fit at the end of the disk. I still had from sector 34 through sector 1023 to install the EFI system partition (ESP).

I don't understand this at all hmm

Did your disk have an MBR-style partition table originally?

the GPT partition

^ This doesn't make any sense -- "GPT" is a type of partition table which contains partitions within.

See https://en.wikipedia.org/wiki/GUID_Partition_Table

It sounds like you may have converted your MBR disk to a GPT type and added a very small EFI system partition.

The output of `parted -l` would show the full picture.

duane wrote:

The FAT12/16 file system will fit in sectors 34-2047 for 512 B sector size disks (sectors 5-255 on 4096B sector size disks). This is about 1MB, the grub boot loader on my system was about 22kB, leaving lots of room.

This would only apply to users who have mounted the EFI system partition to /boot/efi and are using GRUB to boot the system.

The Arch installation guide recommends mounting the ESP to /boot and using systemd-boot -- this requires space for the kernel image & initramfs along with all the other configuration files so a few hundred MiB is needed.

Just to note that I have one laptop that will only boot UEFI systems off the hard drive if the ESP is 512MiB, I think that is the general recommendation.

Offline

#4 2016-05-31 10:15:41

syg00
Member
Registered: 2006-01-11
Posts: 31

Re: Fitting UEFI + GPT into an existing disk partition structure

I too am confused by the OP, and generally agree with the above. However, this is news to me - been a while since I last went through the install guide though

Head_on_a_Stick wrote:

The Arch installation guide recommends mounting the ESP to /boot and using systemd-boot

Edit: ok, I see the beginners guide has this recommendation. My bad.

Last edited by syg00 (2016-05-31 10:19:46)

Offline

#5 2016-06-01 15:07:04

duane
Member
Registered: 2016-05-25
Posts: 8

Re: Fitting UEFI + GPT into an existing disk partition structure

Head_on_a_Stick wrote:
duane wrote:

the GPT partition

^ This doesn't make any sense

I mistyped in the second sentence, I meant EFI system partition instead of GPT partition. I corrected the post.

Head_on_a_Stick wrote:

It sounds like you may have converted your MBR disk to a GPT type and added a very small EFI system partition.

Yes, I started with a MBR+BIOS disk and changed it to a GPT+EFI disk.

Head_on_a_Stick wrote:
duane wrote:

The FAT12/16 file system will fit in sectors 34-2047 for 512 B sector size disks (sectors 5-255 on 4096B sector size disks). This is about 1MB, the grub boot loader on my system was about 22kB, leaving lots of room.

This would only apply to users who have mounted the EFI system partition to /boot/efi and are using GRUB to boot the system.

I used /boot/efi in the example, you only need to mount the EFI system partition somewhere on the occasion that you're reinstalling the boot loader.

Head_on_a_Stick wrote:

The Arch installation guide recommends mounting the ESP to /boot and using systemd-boot -- this requires space for the kernel image & initramfs along with all the other configuration files so a few hundred MiB is needed.

Just to note that I have one laptop that will only boot UEFI systems off the hard drive if the ESP is 512MiB, I think that is the general recommendation.

While neither the "Installation guide" nor "Boot loaders" recommends systemd-boot over other boot loaders, the "Beginners' guide" does indicate the installation software installs systemd-boot when it finds a UEFI system, so to that extent it is implicitly recommended.
You also are correct about systemd-boot requiring the kernel and initramfs be on the ESP, but this and its inability to boot legacy OS's is why I stay away from it. (Also, I have an wholely encrypted system so my LUKS key is in the initramfs, I wouldn't want that on an ESP FAT drive.)

There are many different boot loaders, systemd-boot is just one alternative. In an existing system which contains a MBR+BIOS, systemd-boot wouldn't already be installed because it is a UEFI-only boot loader. I presented a solution which required the fewest modifications.

Last edited by duane (2016-06-01 15:13:38)

Offline

Board footer

Powered by FluxBB