As Linux administrators, we need to view the partition table of our hard disk time and again. This helps us in re-organizing old drives by making space for further partitioning and also create space for new drives if necessary. You can create no more than 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 on your system.
The partition table, that contains the information about all your logical disks or partitions, resides in the 0 sector of your hard disk. Your device is listed in the partitions table as /dev/sda, /dev/sdb, and so on. The sd* device refers to SCSI or SATA disks on your system. For example, /dev/sda will be the first SATA/SCSI hard disk, /dev/sdb will be the second SATA/SCSI hard disk.
This article lists and explains the use of various Linux commands for you to view the partition table of your device. We will be using the CLI to run these commands. You can open the Ubuntu command line, the Terminal, either through the system Dash or the Ctrl+Alt+T shortcut.
We have run the commands and procedures mentioned in this article on an Ubuntu 20.04 LTS system.
View partition table through the 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 the 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.