3

I remember that when mobos used to use BIOS and the bootloader was located in the MBR, moving the Windows partition caused the system to fail to boot. I just finished moving (accidentally) the C partition (attempting to resize it) on a friend's PC which has a GPT partition table and a UEFI motherboard and - to my surprise and delight, the PC started up perfectly without complaining about the change of the partition's first sector (and my friend isn't mad at me). I believe that's because UEFI bootloaders use the partitions' UIDs instead of addresses.

This makes me wonder if this means that I can freely move the OS partition on a GPT system. Also does this only apply to Windows or to GRUB too?

  • 2
    This question is pretty clear to me, and so IMHO it should not be closed. – Rod Smith Apr 25 '17 at 15:59
5

I believe that's because UEFI bootloaders use the partitions' UIDs instead of addresses.

That's partly, but not quite completely, correct. BIOS-mode boot loaders, as your statement above implies, often rely on sector numbers to help identify follow-on code. That is, the BIOS reads the MBR and executes whatever code it contains. The MBR is too small to hold a really flexible boot loader, so it passes on control to code located elsewhere, typically identifying it by its sector number of by locating a partition with a boot flag set and running the code in the EBR (first sector) of that partition. This secondary boot loader code may repeat this process, again often relying on sector numbers. Thus, moving partitions or resizing them from their start points can render an OS unbootable because the boot loader code itself is moved.

In EFI, by contrast, boot loaders are not stored in the MBR or in partitions' EBRs. Instead, boot loaders are stored as EFI program files on the EFI System Partition (ESP). These program files can be as large as needed (up to limits imposed by file sizes, RAM size, etc.), so the boot loader does not need to be split up in the awkward way that BIOS boot loaders are typically divided. Furthermore, the EFI understands partitions, unlike the BIOS, so an EFI-mode boot loader can reference partitions if it needs to do so.

Although an EFI boot loader might locate a partition by its GUID or in some other way, that's not really the key distinction that's important to your question. BIOS-mode boot loaders often break when you move partitions because the boot loader code itself moves; but in EFI, the boot loader is in a file, not code that's locked to a particular sector. Thus, moving the OS partition does not move the boot loader code. Even if you moved the ESP (where the boot loader lives), the EFI understands partitions and the FAT filesystem, and so can continue to locate the boot loader, so long as the ESP's identifying information and the boot loader's filename don't change as a result.

This makes me wonder if this means that I can freely move the OS partition on a GPT system. Also does this only apply to Windows or to GRUB too?

As a general rule, it's safer to move partitions on EFI-based systems than on BIOS-based systems. I wouldn't say it's absolutely 100% safe, though. First, there's always the risk that a partition-moving operation will result in filesystem damage. That's just a standard caveat whenever discussing such operations, though. The issue that's more to the point of your question is that boot loaders can do whatever they want in whatever way they want. Although I know of no examples of this, an EFI-based boot loader could rely on raw sector numbers to identify an OS's kernel, which would make it unsafe to move the partition on which the kernel resides. If the boot loader uses features like partition numbers to identify a partition with a kernel, and if moving the partition changes the partition number, then the boot process could fail after moving the partition. OTOH, moving the partition might create no problems if the partition number did not change. Thus, the safety of the partition-move operation depends on the boot loader and the details of what happens when you move the partition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.