Saturday, May 25, 2019

boot - What does it mean to install loader to sdaX?



During linux installation all of us are asked to install bootloader somewhere. For example we have following partitions:




sda
sda1
sda2
sda5


First sector (512 bytes) is MBR with 446 bytes for boot loader. Second sector belongs to sda1 (first partition). BIOS loads bootloader located in MBR.



So if we install loader to sda the logic is simple: those 446 bytes is our loader (or part of loader which loads full loader from another place) and this loader offers us to load desirable OS.




But what does it mean to install loader to sdaX?




  1. The loader in MBR won't be updated (First 446 bytes of sda won't be touched)

  2. Only part of loader would be installed to MBR (the parts which loads loader from sdaX MBR)



First, your question is about BIOS-mode booting. This is on the way out. It's still relevant for many computers, but we're in a transitional period during which it's imperative that one not make assumptions about the boot mode. The up-and-coming boot method uses the Extensible Firmware Interface (EFI) or its version-2.x variant, Unified EFI (UEFI).



Second, the BIOS boot loader should really limit itself to the first 440 bytes of the MBR, not the first 446 bytes. Those extra six bytes are used as a serial number for the disk. Although I've heard some BIOS-mode boot loaders spread into that area, doing so is a bit dangerous, and you shouldn't try overwriting that area yourself (say, with dd to erase an unwanted boot loader), since some tools may rely on the serial number remaining unchanged.




Third, /dev/sda1 does not normally begin on the second sector of the disk (although it could). Most partitioning tools today assign sector 2048 as the first sector of the first partition (which might or might not be /dev/sda1). In the past, sector 63 was used for this purpose, but the standard has shifted to 2048 because of changes in hard disk technology. The space between the MBR and the first sector allocated to a partition is officially unallocated/unused, but in reality it may be used....



Finally, when you install GRUB to the MBR (/dev/sda, /dev/sdb, or whatever), its code actually goes in several places, including the MBR, the officially-unallocated space between the MBR and the first allocated sector, and files in /boot/grub (assuming an Ubuntu installation). When you install GRUB to the Partition Boot Record (PBR) of a partition (/dev/sda1, /dev/sdb3, or whatever), some of those locations change, and GRUB must then be launched by another boot loader that resides in the MBR. In the past, this type of configuration was common so as to leave the DOS/Windows boot loader in the MBR and manage the earliest stages of the boot process in the traditional DOS manner of setting a "boot flag" on the partition you want to boot. GRUB 2, however, prefers being installed to the MBR, so this is the most common way to do it today (on BIOS-based computers).



As noted earlier, none of this applies to EFI-mode booting, which is the more common way of booting newer computers. (Since Windows 8, most new computers have shipped configured to boot in EFI mode.) With EFI, boot loaders are ordinary files on the EFI System Partition (ESP). Boot code does not go in the MBR, in the PBR, or in unallocated space before your partitions. Information on what file to use as a boot loader goes in the computer's NVRAM, which can be manipulated (in Linux) with the efibootmgr utility.


No comments:

Post a Comment

11.10 - Can't boot from USB after installing Ubuntu

I bought a Samsung series 5 notebook and a very strange thing happened: I installed Ubuntu 11.10 from a usb pen drive but when I restarted (...