1. Overview

Storage is a crucial component in the Linux system, as it impacts the overall system stability and performance. Because of this, monitoring storage configuration is essential for administrators.

In this tutorial, we’re going to cover an important aspect of monitoring storage configuration: checking the partitioning scheme of a storage disk. We’ll explain the basics of partition tables and their types, then we’ll show how to check the partitioning scheme using multiple commands.

2. How Partition Tables Work

Partitioning is a way to divide a physical storage disk into multiple logical parts. Each part can store its own data and have its own filesystem. These logical parts on the storage disk are called partitions.

A partition table stores information about how a disk is divided into partitions. For example, it stores the number of partitions on the disk, the beginning and ending sectors for each partition, which filesystem is used for formatting the partition, and which partition is a boot partition. So, we can think of a partition table as a map that describes the structure of the disk.

Partition table information is typically stored at the beginning of the disk. The size of this information is usually quite small and may vary depending on the type of the partition table.

3. Types of Partition Tables

There are multiple types of partition tables, with MBR and GPT being the most used. Each enables specific configuration related to maximum disk size, number of partitions, and how information is stored on the disk.

So, let’s check the main differences between them.

3.1. MBR Partition Table

MBR is the legacy partition table format used to store information about disk partitions. It is typically used with older BIOS firmware. MBR stands for “Master Boot Record”, which refers to the first sector on the disk that contains the partition table information.

Because MBR uses only 32-bit logical block addressing, it has a limitation for supporting a maximum disk size of only 2 TB. So, if we’re to use MBR on a disk larger than 2 TB, only 2 TB of it can be used. MBR also has a maximum of only four primary partitions, but we can create more than four partitions by using an extended partition type.

The MBR sector also contains a small boot loader code that runs as part of the OS boot process.

3.2. GPT Partition Table

GPT or GUID Partition Table is the newer standard for partitioning layout on storage devices. It overcomes the limitations of MBR by supporting bigger disk sizes and a greater number of maximum partitions.

GPT uses 64-bit for logical block addressing, which allows a disk size of almost 9 ZB. Although this size seems impossible to find in a single hard disk, it can appear when using external storage arrays. GPT also allows the creation of up to 128 partitions. This overcomes the MBR limitation and provides more flexibility for creating different filesystems for multiple partitions.

The GPT partition layout requires the newer UEFI firmware instead of the legacy BIOS. However, GPT can sometimes be supported with BIOS only for non-boot partitions.

4. Checking the Partition Scheme of a Storage Disk

There are multiple tools available to check the partition table type on a specific storage device. We’ll cover the most common tools that are almost always available on every Linux machine.

4.1. Using parted

parted is a command-line utility for modifying partition tables. We can use parted to create, extend, or remove partitions. It’s one of the simplest tools to use and comes by default with most Linux distributions.

Let’s check the partition table using the parted command:

$ sudo parted -l
Disk /dev/xvda: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
--------------OUTPUT TRIMMED-------------

Disk /dev/xvdb: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
---------------OUTPUT TRIMMED------------

Here, we use the -l flag with the parted command to list the partition table.

The parted -l command, by default, shows the partition table for all the available devices. In the output, we have two devices, /dev/xvda and /dev/xvdb. We can see the Partition Table entry in the output is showing gpt for /dev/xvda and msdos for /dev/xvdb. The msdos is the MBR partition table.

If we want to list the partition table for a specific device, we can add the device name after the -l flag:

$ sudo parted -l /dev/xvda
Disk /dev/xvda: 8590MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 
-------------OUTPUT TRIMMED-----------

The -l flag is useful when we have multiple devices and want to filter the output.

4.2. Using fdisk

fdisk is another useful command for modifying and listing partition tables on our device. It’s also common on most Linux distributions and supports different partition table types.

To list the partition table type, let’s use the fdisk -l command:

$ sudo fdisk -l
Disk /dev/xvda: 8 GiB, 8589934592 bytes, 16777216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
------------------OUTPUT TRIMMED-------------------

Disk /dev/xvdb: 1 GiB, 1073741824 bytes, 2097152 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
-------------------OUTPUT TRIMMED-------------------

Again, we can see the two devices showing with their respective partition table types. The output is similar to the parted command, with some slightly different information.

4.3. Using lsblk

We can also use the well-known lsblk command to display the partition table types. lsblk is a common utility that admins use to list the storage devices available and information about them.

By using a few command options, we can filter the output to print the partition table for a specific disk:

$ lsblk /dev/xvda -dno pttype
gpt
$ lsblk /dev/xvdb -dno pttype
dos

Here, we use the lsblk command and specify the device name to print the partition table type. The -d option omits the children or slave devices to filter the output only for the selected device. The -n option omits the header line from the output. Finally, the -o option specifies which column or field we need to print, which we set to the pttype field to display the partition table type.

5. Conclusion

In this article, we’ve covered the basics of partition tables and how we can check the partition table type on a specific device. Partition tables store information about the logical partitions’ layout on a disk. The two most common partition table types today are MBR and GPT.

There are multiple commands available to quickly check which partition table type we have. We can use the parted command, which is a popular tool for modifying disk partitions. The fdisk is also a common tool that we can find in most Linux distributions. We can also use the lsblk command by specifying some command options to filter the output and print the partition table type.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.