help-grub
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What to backup before installing GRUB on a GPT disk?


From: Jordan Uggla
Subject: Re: What to backup before installing GRUB on a GPT disk?
Date: Fri, 30 May 2014 14:14:57 -0700

On Wed, May 28, 2014 at 11:14 PM, Ariszló <address@hidden> wrote:
> On Tue, May 27, 2014 at 10:00 PM, Jordan Uggla wrote:
>>
>> > What should one backup on a GPT disk before installing GRUB?
>>
>> Generally nothing. grub-install won't touch the partition table,
>
> It does overwrite the MBR on an MBR disk.

grub-install preserves the partition table  when installing a BIOS
based boot sector to a disk. The only portion of the MBR that is
modified is the first 440 bytes, which contains boot code but not the
partition table. In such a BIOS based install grub will also modify
the embedding area, which for an msdos labeled disk is the post-mbr
gap, and will write files to /boot/grub/ using normal filesystem
operations. To "undo" all of that would require backing up the MBR,
the post MBR gap, and making a full image backup of the filesystem
containing /boot/grub/.

If you just want to get a BIOS based Windows' bootmgr to run by
default again without going through grub, then restoring a backup of
the first 440 bytes of the MBR pre-grub-install would achieve that,
but so would "apt-get install mbr; install-mbr /dev/sdX" from a Debian
based GNU/Linux. I find "install-mbr" to be both easier and much less
prone to disastrous user-error compared to using dd to restore a
backup, and so I never even make such a backup when installing grub to
the MBR of an msdos labeled disk (whether or not the disk contains a
Windows installation).

> Do you mean it won't touch
> the first sector of a GPT disk?

grub-install still preserves the partition table when installing a
BIOS based boot sector to a GPT labeled disk. Again, the only portion
of the MBR (GPT labeled disks *do* have an MBR) modified is the first
440 bytes.

> Then how does GRUB steps ahead of the
> Windows 8 bootmgr?

On BIOS based systems with an msdos labeled disk, grub "steps ahead"
of bootmgr by modifying the first 440 bytes of the MBR. On UEFI based
systems with a GPT labeled disk grub "steps ahead" of bootmgr by
modifying the UEFI boot order in your machine's firmware, not by
changing anything "on disk". Microsoft doesn't support booting from
GPT labeled disks via BIOS, but if they did then grub would still be
installing to the MBR as it does for any other BIOS based system with
a GPT disk. (Grub and GNU/Linux do support booting via BIOS from GPT
disks, it's only Windows that doesn't).

>
>> What is your end goal?
>
> I want to know how to restore a GPT disk to its original state after
> removing GRUB. Is it possible to do it from a live Linux session, or
> does one have to use a Windows 8 recovery drive?

Since you're asking about Windows and a GPT disk, I'll assume that
you're booting via UEFI rather than BIOS. In that case, "grub-install
--target=x86_64-efi" really doesn't modify the MBR at all, because for
UEFI there is no concept of a "boot sector", only bootable images
stored as files in a FAT filesystem. What grub-install does do in this
case is create an appropriate file in the EFI System Partition and
then uses efibootmgr to "register" this file with your boot firmware,
creating and entry, and then configures that entry to be first in the
boot order. Do "undo" this, you would need to restore a backup of the
entire EFI system partition, as well as the filesystem containing
/boot/grub/, then remove the entry created by grub-install using
efibootmgr. More practically though, you'd just remove the entry in
the boot firmware, and maybe delete the one directory containing one
file that grub-install adds to the EFI System Partition. Note that at
no point does grub-install remove Windows' own entry in the firmware,
it just puts its own entry ahead of Windows' in the boot order.

-- 
Jordan Uggla (Jordan_U on irc.freenode.net)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]