BIOS – Linux Hint https://linuxhint.com Exploring and Master Linux Ecosystem Tue, 26 Jan 2021 02:18:39 +0000 en-US hourly 1 https://wordpress.org/?v=5.6.2 GPT vs. MBR Booting https://linuxhint.com/gpt-vs-mbr-booting/ Sun, 24 Jan 2021 05:15:01 +0000 https://linuxhint.com/?p=87343 Most of the time, we let our computers’ boot just happen, but sometimes we need to control it. One of those times is when you want to dual boot. The way your disk is organized affects what you need to do and think about. The way computers boot and have been booting is by using the Master Boot Record. That was the old way, but you will still see partitioning software give you the option to use this system. GPT means GUID Partition Table; it was introduced to address BIOS limitations, one being the size of disk it can address. To use GPT, you must have a UEFI based computer. In 2021, you do! Just watch out for decades-old hardware if you are a tinkerer. Note that you can still keep using MBR if you wish to do so.

The standards in your start-up.

Let’s make sure we know which standard does what:

BIOS checks your hardware before it looks for the disk and the MBR. The MBR is a section of the disk at the physical beginning. This space is only at that beginning. So BIOS looks for the MBR, which in turns points to the Operating System.

UEFI does the same job as the BIOS, but instead of pointing to a specific address on the disk, it searches for your ESP. The ESP is the partition where you have all the files that run your boot manager. You can point to any *.efi file; these files are executable and most commonly run grub.

The interesting part is that UEFI can also point to your MBR partitioned disk. This was necessary since many systems only had those disks and needed to stick with them for a few generations. This means that you can still choose to partition your disk using MBR. You will also have no problems doing this unless your disk is over 2.2 terabytes.

Using GPT on your disk has many advantages, though, and the added complexity is very small. A final detail that you can add to your disk is the PMBR. The PMBR will act as the MBR when the hardware cannot handle it. It is only a backward compatibility issue.

How do I use this?

This is interesting for you to know when you install a new distribution. Most distributions have built-in partitioning, but some do not. When you have finished the installing process, you may still need to partition new disks; hence you should know the difference between the partitioning standards. If you have no particular demands, you should use GPT and any standard that the distribution suggests.

Reasons to choose GPT over MBR

This is the simplest way to partition your drive, don’t make that your reason for doing so! Even compatibility is usually not a reason since your partitioning software will create the PMBR mentioned earlier. You would be forced to have, at least, PMBR on any USB drive that you plan to use on really old hardware. Any hard disk that you install in a machine with UEFI, you should use GPT. The reasons are many. Your disk’s size is not your main concern; in this case, instead, you have many features that speak for GPT.

One feature is that you can have as many partitions as your OS allows. The initial limitation is usually 128 partitions, but the standard allows many more. If you need more partitions, you probably have chosen the wrong strategy and should think again. The second feature you should appreciate is that the table is in two places on the disk. On an MBR disk, you have the table on the first sector and nowhere else! Using GPT, you have the table in two places; the beginning and end of the disk. On top of that, it is really simple to make a backup copy of the ESP to external media. GPT also uses CRC to check that the partition table is healthy. This can give you ample warning that one of the copies is corrupted. In this case, the system uses the second copy and boots as usual. If this is your situation, start gdisk ‘/dev/sdX’, type ‘v’ to verify your disk, and then ‘w’. You will end up with both tables in a good state. WARNING: If you have physical problems with the disk, you may end up with an un-bootable disk. Keep Backups!

Moving from MBR to GPT

Since you most likely want to use GPT, there is a way to move to MBR. You can usually achieve this without re-writing the entire disk, though you should keep backups!

The earlier mentioned ‘gdisk’ utility can do it for you. It is even simpler to use ‘cgdisk’, where you have a list of partitions listed and options at the bottom. It looks the same as ‘cfdisk’ and works almost the same. When you start ‘cgdisk’, you get warnings that the disk is an MBR disk and that ‘gdisk’ will convert your disk. This happens in memory, and you can back out at any time. When you have verified that the changes are good, cross your fingers and write to disk. If you have a decent and healthy disk, you should end up with a GPT disk. This can fail since some programs that create MBR disks do not align correctly, and ‘gdisk’ will not recover your disk.

Conclusion

In your current system, using MBR is usually unnecessary. If you have very old hardware, you may have some use of it, but during the operation of hardware newer than 2007, you are close to guaranteed to have support for GPT. With GPT being more robust and secure, you should use GPT except in extremely rare cases. Have fun with your portable media, and if you can still keep a BIOS machine running; Kudos! It is an achievement in itself!

]]>
Understanding the Boot process — BIOS vs UEFI https://linuxhint.com/understanding_boot_process_bios_uefi/ Mon, 14 Jan 2019 10:00:50 +0000 https://linuxhint.com/?p=35386 The boot process is universe unto its own. A lot of steps are needed to happen before your operating system takes over and you get a running system. In some sense, there is a tiny embedded OS involved in this whole process. While the process differs from one hardware platform to another, and from one OS to another, let’s look at some of the commonalities that will help us gain a practical understanding of the boot process.

Let’s talk about the regular, non-UEFI, boot process first. What happens between that point in time where you press the power ON button to the point where your OS boots and presents you with a login prompt.

Legacy BIOS — Basic Input/Output System

Step1: The CPU is hardwired to run instructions from a physical component, called NVRAM or ROM, upon startup. These instructions constitute the system’s firmware. And it is this firmware where the distinction between BIOS and UEFI is drawn. For now let’s focus on BIOS.

It is the responsibility of the firmware, the BIOS, to probe various components connected to the system like disk controllers, network interfaces, audio and video cards, etc. It then tries to find and load the next set of bootstrapping code.

The firmware goes through storage devices (and network interfaces) in a predefined order, and tries to find a bootloader stored within them. This process is not something a user typically involves herself with. However, there’s a rudimentary UI that you can use to tweak various parameters concerning the system firmware, including the boot order.

You enter this UI by typically holding F12, F2 or DEL key as the system boots. To look for specific key in your case, refer your motherboard’s manual.

Step2: BIOS, then assumes that the boot device starts with an MBR (Master Boot Record) which containers a first-stage boot loader and a disk partition table. Since this first block, the boot-block, is small and the bootloader is very minimalist and can’t do much else, for example, read a file system or load a kernel image.

So the second stage bootloader is called into being.

Step3: The second stage bootloader is responsible for locating and loading the proper Operating System kernel into the memory. The most common example, for Linux users, is the GRUB bootloader. In case you are dual-booting, it even provider you with a simple UI to select the appropriate OS to start.

Even when you have a single OS installed, GRUB menu lets you boot into advanced mode, or rescue a corrupt system by logging into single user mode. Other operating systems have different boot loaders. FreeBSD comes with one of its own so do other Unices.

Step4: Once the appropriate kernel is loaded, there’s still a whole list of userland processes are waiting to be initialized. This includes your SSH server, your GUI, etc if you are running in multiuser mode, or a set of utilities to troubleshoot your system if you are running in single user mode.

Either way an init system is required to handle the initial process creation and continued management  of critical processes. Here, again we have a list of different options from traditional init shell scripts that primitive Unices used, to immensely complex systemd implementation which has taken over the Linux world and has its own controversial status in the community. BSDs have their own variant of init which differs from the two mentioned above.

This is a brief overview of the boot process. A lot of complexities have been omitted, in order to make the description friendly for the uninitiated.

UEFI specifics

The part where UEFI vs BIOS difference shows up is in the very first part. If the firmware is of a more modern variant, called UEFI, or Unified Extensible Firmware Interface, it offers a lot more features and customizations. It is supposed to be much more standardized so motherboard manufacturers don’t have to worry about every specific OS that might run on top of them and vice versa.

One key difference between UEFI and BIOS is that UEFI supports a more modern GPT partitioning scheme and UEFI firmware has the capability to read files from a small FAT system.

Often, this means that your UEFI configuration and binaries sit on a GPT partition on your hard disk. This is often known as ESP (EFI System Partition) mounted at /efi, typically.

Having a mountable file system means that your running OS can read the same file system (and dangerously enough, edit it as well!). Many malware exploit this capability to infect the very firmware of your system, which persists even after an OS reinstall.

UEFI being more flexible, eliminates the necessity of having a second stage boot loader like GRUB. Often times, if you are installing a single (well-supported) operating system like Ubuntu desktop or Windows with UEFI enabled, you can get away with not using GRUB or any other intermediate bootloader.

However, most UEFI systems still support a legacy BIOS option, you can fall back to this if something goes wrong. Similarly, if the system is installed with both BIOS and UEFI support in mind, it will have an MBR compatible block in the first few sectors of the hard disk. Similarly, if you need to dual boot your computer, or just use second stage bootloader for other reasons, you are free to use GRUB or any other bootloader that suits your use case.

Conclusion

UEFI was meant to unify the modern hardware platform so operating system vendors can freely develop on top of them. However, it has slowly turned into a bit of a controversial piece of technology especially if you are trying to run open source OS on top of it. That said, it does have its merit and it is better to not ignore its existence.

On the flip-side, legacy BIOS is also going to stick around for at least a few more years in the future. Its understanding is equally important in case you need to fall back to BIOS mode to troubleshoot a system. Hope this article informed you well enough about both these technologies so that the next time you encounter a new system in the wild you can follow along the instructions of obscure manuals and feel right at home.

]]>