The first thing that we need to know is there is no C drive or E drive in Linux. We will see something like /dev/sda, /dev/sdb, /dev/sdc, … etc. instead. The dev is short for device. The sd was short for Small Computer System Interface (SCSI) mass-storage driver.
- /dev/sda – The first SCSI disk SCSI ID address-wise.
- /dev/sdb – The second SCSI disk address-wise and so on.
- /dev/sda1 – The first partition of disk sda
- /dev/sdb1- The first partition of disk sdb
You can list disk partitions in Linux by using the fdisk, parted, or lsblk commands. Once you have opened the Terminal window, enter the command above. Press Enter to run the command. You will get all the disk partitions from the command output.
Table of Contents
Procedure to Check Disk Partition in Linux
- Open the terminal.
- Type fdisk -l and press Enter. The output will show information about the disk partitions.
- Type blkid and press Enter. The output will show information about the block devices on the system.
- Type df -h and press Enter. The output will show the disk partitions and their sizes as well as the amount of free space on each partition.
- Type mount and press Enter. The output will show information about the mounted file systems.
Understanding Disk Partition Tables
A partition table shows the partitions of a Hard Drive or any other storage device. There are two standards for the partition table:
- Master Boot Record (MBR) – MBR also know as MS-DOS, is what us might call the original standard. MBR is still the most widely used partition table, it comes with two major limitations.
- GUID Partition Table (GPT) – GPT came later. While MBR is still in use, the limitations are what led to the development of GPT. GPT overcomes the two limitations of MBR. We can have multiple primary partitions, and the drive sizes can exceed 2 TB.
The limitation of MBR:
- It does not allow us to create more than four main partitions. Those partitions are called primary partitions.
- Disk partitions may not exceed 2 TB.
Related: 5 Ways to Check disk size in Linux
Understanding Disk Partitions and Partition Numbering
To install an operating system on a hard drive, we have to divide it into distinct storage units. We call those storage units partitions. Under MBR – which is the default on virtually all Linux distributions, there are three different types of partitions – Primary, Extended, and Logical.
- Primary – Holds the operating system files. Only four primary partitions can be created.
- Extended – Special type of partition in which more than the four primary partitions can be created.
- Logical – Partition that has been created inside of an extended partition.
With MBR any partition that is not explicitly created as an extended or logical partition, is a primary partition.
Any unallocated space is shown as Free. While it may be free, we cannot use it in that state. As far as the system is concerned that free space does not exist until it is partitioned.
Names without a trailing digit refer to the whole disk, while names with a trailing digit refer to a partition of that whole disk. By convention, SCSI disks have a maximum of 16 minor numbers mapped to a single disk.
Thus, for each whole disk, there is a maximum of 15 partitions per disk because one minor number is used to describe the entire disk (for example /dev/sda), and the other 15 minor numbers are used to refer to partitions for that disk (for example /dev/sda1, /dev/sda2, etc).
Understanding Disk Extended Partition
By tagging a partition as an extended partition, it is possible to create many more partitions under the extended partition. Those partitions are called logical partitions, and there is effectively no limit to the number of logical partitions that us can create.
This means us can have three primary partitions and one extended partition and then create numerous partitions from there.
Check disk Partition with fdisk command in Linux
Fdisk is the most commonly used command to check disk partition in Linux. It is a text-based utility for viewing and manipulating disk partitions. Typing fdisk -l at the command prompt and press enter. It will list all of the partitions on your Linux system.
You can also use the fdisk command to create, delete, or resize partitions. For more information on using fdisk, consult the man page by typing: man fdisk at the command prompt.
parted -l and fdisk -l can both list disk partitions on Linux.
- Model – Model of the storage device.
- Disk – Name and size of the disk.
- Sector size – Logical and physical size of the memory. Not to be confused with available disk space.
- Partition Table – Partition table type (msdos, gpt, aix, amiga, bsd, dvh, mac, pc98, sun, and loop).
- Disk Flags – Partitions with information on size, type, file system, and flags.
Related: 2 ways to check disk IOPS in Linux
Check disk Partition with ls command in Linux
Here we can see that there are 3 partitions on disk sda.
- # ls -l /dev/sda*
- brw-rw—- 1 root disk 8, 0 May 24 08:09 /dev/sda
- brw-rw—- 1 root disk 8, 1 May 24 08:09 /dev/sda1
- brw-rw—- 1 root disk 8, 10 May 24 08:09 /dev/sda2
- brw-rw—- 1 root disk 8, 11 May 24 08:09 /dev/sda3
Check disk partition with cat /proc/partitions in Linux
/proc/partitions file also has much important info about disk and disk Partitions.
# cat /proc/partitions
- major minor # blocks name
- 8 0 17774160 sda
- 8 1 1052226 sda1
- 8 10 208845 sda2
- 8 11 10490445 sda3
What is the difference between a partition and a filesystem?
A partition is a section of a disk that is allocated for use by an operating system. A filesystem is a method for organizing and storing files on a partition.
What is the purpose of disk partitions?
Partitions are used to separate different types of data. For example, you might have a partition for your operating system and another partition for your personal files. Partitions can help to improve performance and stability by isolating different types of files.
For example, you can use a separate partition for your operating system files and another partition for your personal data files. This way, if one partition becomes corrupted, the other partition will not be affected.
What is the difference between primary and extended partitions?
Primary partitions are the first four partitions on a disk. Extended partitions are any partitions after the fourth partition. You can create up to four primary partitions or three primary partitions and one extended partition.
How do I delete a partition in Linux?
You can use the fdisk command to delete partitions in Linux. First, you need to find the device name of your disk. You can do this by running the lsblk command. Next, you need to run the fdisk command with the device name as an argument.
Then, you will need to enter d to delete a partition. Finally, you will need to enter w to write the changes to the disk.