Basics of Partitioning You Should Know When Installing Linux

 2024-02-11

 2024-02-11

 Linux

This article is the English version of the Japanese article titled ‘Linuxをインストールする時に知っておきたいパーティショニングの基礎’.

This time, I would like to write about the basics of partitioning, which is unavoidable when installing Linux. This may be the first wall that beginners who are thinking about installing Linux will hit. Recently, the installer will automatically partition the system, so there may be cases where you do not need to think about it, but I have summarized what I think is good to know in order to become an intermediate Linux user.

What is partitioning

First of all, what is partitioning? Partitioning is deciding what kind of table configuration to build for the storage to put the system, what capacity partitions to divide it into, and what role to assign to each partition. Each partition not only holds the system, but also has various roles such as being used when the system starts up and temporarily supplementing capacity when memory is insufficient. Partitioning is deciding the division of roles and capacity.

Types of partition tables

Currently, there are two main methods for hard disk partitioning table configurations. They are MBR (Master Boot Record) partition table and GPT (GUID Partition Table). In the past, when many systems started up with BIOS (now called Legacy BIOS) systems, MBR table partitions (also known as MS-DOS partitions) were used.

GPT has many advantages over the old MBR because it is a new standard. One of them is the number of partitions. With MBR, you can only have up to four primary partitions, and if you want to have more than five partitions, you had to create an extended partition within a logical partition. With GPT, there is no such restriction and you can create any number of partitions.

UEFI BIOS and Legacy BIOS

BIOS is a Basic Input Output System, and it starts up when the power is turned on and is responsible for starting the system. When the power is turned on, the BIOS checks the hardware status, initializes it, and then starts the OS. At this time, the BIOS calls something called a boot loader to start the system.

UEFI (Unfied Extensible Firmware Interface) BIOS has appeared as a newer system than the traditional BIOS. UEFI itself is an interface specification, so it is not dependent on a specific processor. The term BIOS includes UEFI BIOS and traditional BIOS (Legacy BIOS). It is often discussed in terms of BIOS vs. UEFI, but that is not accurate; there is Legacy BIOS (commonly known as BIOS) and UEFI BIOS. Booting with Legacy BIOS is sometimes called BIOS boot, and booting with UEFI BIOS is sometimes called UEFI boot.

It’s a little confusing, but many UEFI systems have CSM (Compatibility Support Module) support to maintain compatibility with Legacy BIOS, and some can boot with Legacy BIOS behavior under names such as “Legacy mode” or “BIOS mode”. This allows even a machine with UEFIJ BIOS to behave like a Legacy BIOS machine and boot an OS that does not support EFI boot.

UEFI BIOS has various technical advantages over Legacy BIOS. It supports GPT and makes it possible to boot the system from a hard disk exceeding 2TiB. Other advantages include faster booting and the ability to design an interface that is not bound by the 16-bit system interface.

Combination of BIOS type and partition table

There are recommended combinations for BIOS type (BIOS boot/UIFE boot) and partition table. When partitioning, you need to know whether your machine is UEFI BIOS or Legacy BIOS. The recommended combinations are as follows.

  • UEFI boot — GPT
  • BIOS boot — MBR

You can almost always partition with the above combination. Many distributions recommend installing with this combination.

So, does that mean the OS cannot be started with other combinations? It is not impossible. For example, even with a combination of UEFI BIOS and MBR partition, it can be started if the UEFI BIOS system supports MBR, but it cannot be started with some UEFI BIOS that do not support it. In addition, a BIOS boot partition is required to start with a combination of Legacy BIOS and GPT, and some Legacy BIOS older than 2010 may refuse to start if there is no MBR partition, so individual measures are required.

UEFI system requires ESP

When UEFI starts the system, an area called ESP (EFI System Partition) is required. This is where the UEFI boot loader, applications, and drivers called by the UEFI system are stored, and is a required partition for UEFI boot.

The ESP must be formatted using the FAT32 standard. The recommended capacity varies depending on the distribution, but it is better to reserve at least 512MiB (*3). The way to create an ESP varies depending on the partitioning tool. An example is shown below.

  • fdisk: Set the partition type to EFI System

  • gdisk: Set the partition type to EF00

  • GParted: Check esp in the flag settings

About swap

Swap is a capacity that stores the overflow when the system’s RAM (Read Access Memory: commonly called memory) is insufficient, and the hard disk takes over part of the RAM shortage. This may make you think that if you enable a lot of swap, it will be fine even if the memory is small, but it’s not that simple. The read/write speed of the hard disk is slower than the read/write speed of RAM, so using swap takes a very long time. This is only a relief measure, and frequent swap usage should be considered as a RAM shortage in the system.

How much swap space should be set aside? This is a common question when partitioning. When memory capacity was less than 2GB, it was said that it should be twice the amount of RAM. However, memory capacity has now increased to 16-64GB, and it is no longer appropriate to reserve swap space twice the amount of RAM. For reference, the settings recommended by Red Hat for RHEL (Red Hat Enterprise Linux) are shown here.

Partitioning tools

There are several partitioning tools that can be used with Linux. There are many types, from those that are easy for beginners to use with mouse operations to those that perform partitioning with command operations. For a comparison of partitioning tools that can be used with Linux, I have written an article at the following link. For your reference.

Should root and home be on separate partitions?

There is no right answer when it comes to partitioning, so there is no correct answer, but since I frequently switch Linux distributions, I have separate partitions for the root directory and the home directory. This prevents the files I created, settings related to the desktop environment, fonts installed under the home directory, etc. from being lost every time I update the system.

On the other hand, some desktop environment configuration files are recommended by the distribution, and there is a risk that if the home directory is not updated, the configuration files that the distribution does not recommend will be used. Another method is to use the same partition for root and home and a separate partition for the data storage directory.

Although it is a little off topic from the topic of partitions, in order to increase the OS boot speed, you can use the SSD for the root directory where the system is installed, and the non-volatile HDD for the home directory where data is stored.

I want to know the device name recognized by the system

Even if you use a partitioning tool to partition, you may want to know the name (sda, sdc, etc.) by which the system currently recognizes the device. In that case, try running the following command.

lsblk

This will display the storage devices currently recognized by the system. By the way, the command name `lsblkd` comes from list block device.

Finally

I have tried to summarize partitioning knowledge in a relatively short and easy way, but there may still be some omissions. I have tried to write the content carefully and accurately, but if there are any errors, I would appreciate it if you could contact me.

References(Japanese Only)