How to check if a specific partition table is used in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check the partition table used on your Linux system. Understanding partition tables is essential for managing disk storage and troubleshooting disk-related issues. You will use standard Linux command-line tools to inspect disk partitions and identify the partition table type.

The lab will guide you through using fdisk -l to list disk partitions, examining the /proc/partitions file for partition information, and utilizing parted -l to get detailed partition table information. By the end of this lab, you will be able to determine the partition table type (e.g., MBR or GPT) used on your disks.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/BasicSystemCommandsGroup(["Basic System Commands"]) linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux(("Linux")) -.-> linux/UserandGroupManagementGroup(["User and Group Management"]) linux/BasicSystemCommandsGroup -.-> linux/help("Command Assistance") linux/BasicSystemCommandsGroup -.-> linux/man("Manual Access") linux/BasicFileOperationsGroup -.-> linux/ls("Content Listing") linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/UserandGroupManagementGroup -.-> linux/sudo("Privilege Granting") subgraph Lab Skills linux/help -.-> lab-558762{{"How to check if a specific partition table is used in Linux"}} linux/man -.-> lab-558762{{"How to check if a specific partition table is used in Linux"}} linux/ls -.-> lab-558762{{"How to check if a specific partition table is used in Linux"}} linux/cat -.-> lab-558762{{"How to check if a specific partition table is used in Linux"}} linux/sudo -.-> lab-558762{{"How to check if a specific partition table is used in Linux"}} end

Check partitions with fdisk -l

In this step, you will learn how to view the disk partitions on your system using the fdisk command. Disk partitioning is the process of dividing a hard drive into multiple logical storage units called partitions. Each partition can be formatted with a different file system and used independently.

The fdisk command is a powerful utility for managing disk partitions. When used with the -l option, it lists the partition tables for the specified devices. If no device is specified, it lists the partition tables for all devices.

Open your terminal if it's not already open. You can do this by clicking the Xfce Terminal icon on the left side of your desktop.

Now, type the following command and press Enter:

sudo fdisk -l

You need to use sudo because viewing partition information requires administrative privileges. sudo allows you to run commands as the superuser (root).

You will see output similar to this:

Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Disk identifier: 0x...
...

Device     Boot Start      End  Sectors Size Id Type
/dev/sda1  *     2048 41943006 41940959  20G 83 Linux

This output provides information about the disks and their partitions.

  • /dev/sda: This is the name of the disk device. /dev/sda typically refers to the first hard drive.
  • Disk /dev/sda: ...: This line shows the total size of the disk.
  • Device: The name of the partition (e.g., /dev/sda1).
  • Boot: Indicates if the partition is bootable.
  • Start, End, Sectors: The start and end sectors of the partition.
  • Size: The size of the partition.
  • Id: The partition type ID.
  • Type: The type of the partition (e.g., Linux).

In this example, you can see one partition, /dev/sda1, which is a Linux partition.

Understanding disk partitions is crucial for managing storage and installing operating systems.

Click Continue to proceed to the next step.

Verify partition table in /proc/partitions

In this step, you will explore another way to view partition information in Linux by examining the /proc/partitions file.

The /proc filesystem is a virtual filesystem that provides information about processes and other system information. It doesn't contain real files on the disk but rather provides a window into the kernel's data structures. The /proc/partitions file specifically contains information about the block devices and their partitions known to the kernel.

You can view the contents of this file using commands like cat or less. Let's use cat to display the content directly in the terminal.

Type the following command and press Enter:

cat /proc/partitions

You will see output similar to this:

major minor  #blocks  name

   8        0 20971520 sda
   8        1 20970479 sda1

Let's break down the columns:

  • major: The major device number, which identifies the device driver.
  • minor: The minor device number, which identifies the specific device instance or partition.
  • #blocks: The size of the device or partition in 1KB blocks.
  • name: The name of the device or partition (e.g., sda, sda1).

You can see the sda device (the whole disk) and the sda1 partition listed here, matching the information you saw with fdisk -l. The #blocks value for sda1 is approximately the size of the partition in 1KB blocks.

Comparing the output of fdisk -l and cat /proc/partitions can be helpful for understanding how the system views your disk layout. /proc/partitions provides a more raw, kernel-level view.

Click Continue to move on.

Inspect table with parted -l

In this step, you will use the parted command to view disk partition information. parted is another powerful command-line tool for managing disk partitions, often considered more modern and flexible than fdisk, especially for disks larger than 2TB and for working with GUID Partition Tables (GPT).

Similar to fdisk, you can use parted with the -l option to list the partition layout of all block devices.

Open your terminal if it's not already open.

Type the following command and press Enter:

sudo parted -l

Again, you need sudo because this command requires administrative privileges to access disk information.

You will see output similar to this:

Model: VMware Virtual disk (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  21.5GB  21.5GB  primary  ext4         boot

Let's look at the key information provided by parted -l:

  • Model: The model of the disk.
  • Disk /dev/sda: The device name and its total size.
  • Sector size: The logical and physical sector sizes.
  • Partition Table: The type of partition table (e.g., msdos for MBR, gpt for GPT).
  • Number: The partition number.
  • Start, End, Size: The start and end points and size of the partition. parted often uses more human-readable units like MB or GB.
  • Type: The partition type (e.g., primary, logical).
  • File system: The file system on the partition (e.g., ext4).
  • Flags: Various flags associated with the partition (e.g., boot).

You can see that parted -l provides similar information to fdisk -l but with a slightly different format and potentially more details, especially regarding file systems and flags.

You have now learned three different ways to view disk partition information in Linux: using fdisk -l, examining /proc/partitions, and using parted -l. Each method provides a slightly different perspective and can be useful in different situations.

Click Continue to complete this lab.

Summary

In this lab, you learned how to check the partition table used in Linux. You started by using the sudo fdisk -l command to list the partition tables for all devices, understanding the output details such as device names, sizes, and partition types. This initial step provided a comprehensive overview of the disk layout and existing partitions on your system.