As Linux administrators, we always need to look at the partition table of our hard drive. This helps us reorganize old drives by making room for more partitions, and also make room for new drives if needed. You can create a maximum of four primary partitions on a hard disk, but a number of logical or extended partitions, depending on the size of the hard disk you have installed in your system.
The partition table, which contains information about all your logical drives or partitions, is located in sector 0 of your hard disk. Your device is listed in the partition table as /dev/sda, /dev/sdb, and so on. The sd* device refers to SCSI or SATA hard disks in your system. For example, /dev/sda is the first SATA/SCSI disk, /dev/sdb is the second SATA/SCSI disk.
In this article, we will list and explain various Linux commands that you can use to view your device’s partition table. We will use the CLI to execute these commands. You can open the Ubuntu command line, the terminal, using either the System Dash or the Ctrl+Alt+T key combination.
We have run the commands and procedures mentioned in this article on an Ubuntu 20.04 LTS system.
View partition table using lsblk command
The lsblk command lists all the block devices of your system along with their logical partitions. Enter the following command in your Terminal to list the partition table:
In the above output, you can see all the logical partitions from sda1 till sda5 for my sda device. Here is what the seven columns indicate:
- Name – Name of the devices
- Maj:Min – Major and Min Device numbers
- RM – Whether the device is removable(1) or not (0)
- Size – Size of the device
- RO – Is the device read-only(1) or not (0)
- Type – Type of device, i.e, if it is a disk or partitions, etc.
- MountPoint – The mount point of the device(if applicable).
There are more Linux sysinfo commands.
Get list of partitions with fdisk command
The fdisk command that stands for Format-disk or Fixed-disk is basically used to create or delete hard disk partitions. It is also used to format the disk, however, here we will use it to list the partitions table by using a particular flag with it.
The -l flag is used with the fdisk to list the partitions table of the specified device and then exit. When you do not mention any device name, fdisk uses the devices mentioned in the /proc/partitions file.
The -l option shows the partition tables for the specified devices and then exit. If no devices are given, those mentioned in /proc/partitions (if that exists) are used. Enter the following command as sudo:
$ sudo fdisk -l
When you scroll down further, the output displays the partition table as follows:
This is what the various column indicate:
- Device – Name of the device/logical partition
- Boot – The * sign in this column indicated that the respective partition contains the bootloader information that is used to boot your system
- Start – The starting sector allotted to this partition.
- End – The ending sector allotted to this partition.
- Sectors – The number of sectors allocated for these partitions.
- Size – The size of the partition.
- ID – An ID used by the system for the partition
- Type – The file type or system used by this partition.
Using sfdisk command to view partitions
Though the sfdisk command is primarily used to manipulate partition tables on Linux, it can also be used to list the partitions tables of a device by using the following syntax:
$ sudo sfdisk -l/dev/devicename
$ sudo sfdisk -l /dev/sda
As you can see, this command gives the same information of the partition table as the fdisk command. You can only view the results of the fdisk and sfdisk command as an authorized sudo user.
Using the parted command to get harddisk partitions
Another way to list the partition table for a device is through the parted command. The parted command has an edge on the previously mentioned fdisk and sfdisk commands as the former ones do not list partitions whose size is greater than 2 TB.
Use the following syntax in order to view the partitions table for a device:
$ sudo parted /dev/devicename
$ sudo parted /dev/sda
The command will get into the “(parted)” prompt mode. Here you can enter the following values that will help you in viewing the partition table for a device.
Unit GB: Through this input, you can choose the output to be displayed in GBs.
Unit TB: Through this input, you can choose the output to be displayed in TBs.
Enter your choice after which the system will display the corresponding partition table.
To quit the parted command mode, simply type quit and then hit Enter.
Alternatively, you can use the following command to list all the partition layouts on all the block devices of your system:
$ sudo parted -l
Since sda is my only block device, the command displays the partition for that only.
Note: The lsscsi command that is basically used to list the SCSI devices and their attributes also lists the partition tables on some systems. You can install it through this command:
$ sudo apt-get install lsscsi
Through the various Linux commands we explained in this article, you are now able to view the partition table of your hard disk devices. Some of the commands have many other basic functions but since they also list the partition table, we have included them in our article. You will now be able to manage disk space and partitions of your storage devices even better.