Search This Blog


Linux System Recovery with GRUB

Master Boot Record

512 bytes total

Assembly Code = 446 bytes
Partition Table = 4x16 byte partition identifiers
Sentinel 2 byte field - 0xAA55 means bootable - The BIOS is what checks this sentinel value and allows it to load the boot loader from the MBR


Basic limitations making GPT appealing
  • Limited to 4 primary partitions
  • Extended partitions uses linked logical partitions and one lost link you can lose all data
  • Single byte partition code - meaning we're limited in the number of partition types we can define on a filesystem
  • Maximum disk size is 2TB due to the 32 bit addressing scheme

Advantages of GPT
  • GUID is used to identify the partition type
  • GUID for disk and partitions
  • 128 partitions per disk by default
  • 64 bit addressing allows for 2 ZB disks
  • Backup header and MBR information that is stored at the end of the disk for recovery
  • CRC32 checksums are available to validate integrity of the partition table


Location on the DiskPurpose
0-512 bytesProtective MBR - same as the original MBR but contains a single primary partition of the whole disk or up to 2TB
512-1024 bytesPrimary GPT header containing the GUID for the disk and the location of the partition table as well as the checksums of itself and the partition table
1024+16KB (34th sector)Primary GPT Tabl
16KB preceeding end of disk (32nd sector prior to the end)Secondary GPT table for recovery
Last 512 bytes of diskSecondary GPT header for recovery


gdisk - is able to do a partition table scan and is similar to fdisk

To tell if kernel supports GPT:

grep CONFIG_EFI_PARTITION /boot/config-$(uname -r)

Tools Demo:

gdisk /dev/sda
GPT fdisk (gdisk) version 0.8.6

Partition table scan:
MBR: MBR only
BSD: not present
APM: not present
GPT: not present

Found invalid GPT and valid MBR; converting MBR to GPT format.
you don't want to convert your MBR partitions to GPT format!

UEFI Unified Extensible Firmware Interface

Becomes the new way to boot systems avoiding the BIOS and MBR

Boot Loader Support

Both BIOS and UEFI
  • GRUB 2
  • Syslinux
  • Gummiboot
  • Clover
  • GRUB Legacy
  • LILO

GRUB Legacy

Configuration exists under /boot/grub/menu.lst - /etc/grub is normally symlinked to the menu.lst file

GRUB Root is generally a different partition on your disk and usually is located under the /boot directory but it could also share the same partition as your data.

You can access grub shell from a running system as well

The below is a method of locating where your grub boot loader for stage 1 grub is located

sudo grub
grub> find /boot/grub/stage1
Error 15: File not found
grub> find /grub/stage1

/boot/grub/stage1 - is a copy of the MBR which is 512 bytes

Troubleshooting GRUB Legacy

vga=ask: Append interactively to kernel line to be prompted with VGA modes that you can add to menu.lst
init=/bin/bash: Gain root access if sulogin is set for single user mode

re-install grub to the mbr
grub> root (hd0,0)
grub> setup (hd0) - reinstalls GRUB to the MBR


Configuration changes are not made directly to the cfg file located in /boot/grub2/grub.cfg

The grub configuration if you're running an EFI machine your config might exist under /boot/grub2/EFI/redhat/grub.cfg

To make configuration files we use the grub2-mkconfig -o command

We CAN however make changes to the defaults located under /etc/default/grub or for bigger changes /etc/grub.d/.

GRUB2 will automatically detect new kernels located under the /boot directory and adds them automatically

GRUB2 can automatically boot to ISO files as well

Adding our own Entries

It is generally a good idea if you're not sure what you're doing to pull in data from the /etc/grub2/grub.cfg file for example menuentry lines


menuentry "Single User Mode" {
# load some modules for filesystem support
insmod gzio
insmod part_msdos
insmod xfs
set root=(hd0,1)
# kernel line where instead of init=/bin/bash we use systemd unit files and point to systemd's rescue or single user mode
linux /boot/vmlinuz root=/dev/sda1 ro
initrd /boot/initrd

Check the Syntax first

grub2-script-check -v /etc/grub.d/40_custom

After verification create the .cfg file that we were not able to create manually before

grub2_mkconfig -o /boot/grub2/grub.cfg


No comments:

Post a Comment