Grub
Note: this guide is intended for BIOS systems and may not be correct for UEFI ones (but it may be, I didn't check).
Grub (GRand Unified Bootloader) is the de facto boot loader for Linux. It resides on the MBR (Master Boot Record, fancy name for the first sector of a disk) and is in charge of starting the operative system.
The structure of the MBR is the following: 446 bytes for the bootloader + 64 bytes of partition table + 2 bytes of signature = 512 bytes.
Install Grub
Normally GRUB should be installed by the installation process. If for any reason this didn't happen, or if the installation has become corrupt, you can reinstall it with this method.
Note: I only tested this in a virtual machine.
- Boot on a live system
- Mount the root filesystem of the main Linux OS
- Eventually mount the
/bootpartition to{rootfs mountpoint}/boot(in case your installation has it on a different partition) grub-install --boot-directory={/boot of the mounted root filesystem} {hard disk (e.g. /dev/sda)}
Customize Grub
- Modify
/etc/default/grubto suit your needs update-grub
Change the timeout
To change the timeout of grub menu, i.e. the time to wait before grub automatically launch the first option of the boot menu, set GRUB_TIMEOUT={seconds}
Add kernel resume option
For hibernation to work correctly, the linux kernel has to know from which partition to resume (the swap partition).
Set GRUB_CMDLINE_LINUX="resume={swap partition}"
Disable OS probing
By default when update-grub is run, it searches through all hard drives to find all OSes and add them to the menu.
You can disable this (and just have your running OS in Grub menu) by setting GRUB_DISABLE_OS_PROBER=true.
Delete Grub
If you want to remove Grub from an hard drive (installed by mistake, hard drive no longer contains a bootable system, etc) do the following. If you don't have any other hard drive with a bootloader installed, you won't be able to boot into the machine any more.
Note: as always when dealing with operations that write to disk, do a backup before in case anything goes wrong. In this case also backup the partition table (sfdisk --dump {hard drive} > {output file}).
dd if=/dev/zero of={hard drive (e.g. /dev/sda)} bs={see below} count=1- Use a block size of 446 to only erase the bootloader
- Use a block size of 512 to erase bootloader and partition table