How to list partitions on Linux? Here are the terminal commands to check hard disk partitions on Linux Ubuntu Systems. See which file type is used to represent a hard disk partition in Linux using these commands.
Partitons in Linux
A hard disk can be divided into several partitions. Each partition functions as if it were a separate hard disk. The idea is that if you have one hard disk, and want to have, say, two operating systems on it, you can divide the disk into two partitions. Each operating system uses its partition as it wishes and doesn’t touch the other ones. This way the two operating systems can co-exist peacefully on the same hard disk. Without partitions one would have to buy a hard disk for each operating system.
The information about how a hard disk has been partitioned is stored in its first sector (that is, the first sector of the first track on the first disk surface).
The first sector is the master boot record (MBR) of the disk; this is the sector that the BIOS reads in and starts when the machine is first booted. The master boot record contains a small program that reads the partition table, checks which partition is active (that is, marked bootable), and reads the first sector of that partition, the partition’s boot sector (the MBR is also a boot sector, but it has a special status and therefore a special name).
This boot sector contains another small program that reads the first part of the operating system stored on that partition (assuming it is bootable), and then starts it.
Each partition and extended partition has its own device file. The naming convention for these files is that a partition’s number is appended after the name of the whole disk, with the convention that 1-4 are primary partitions (regardless of how many primary partitions there are) and number greater than 5 are logical partitions (regardless of within which primary partition they reside). For example, /dev/hda1 is the first primary partition on the first IDE hard disk, and /dev/sdb7 is the third extended partition on the second SCSI hard disk.
There are many programs for creating and removing partitions. Most operating systems have their own, and it can be a good idea to use each operating system’s own, just in case it does something unusual that the others can’t. Many of the programs are called fdisk, including the Linux one, or variations thereof. Details on using the Linux fdisk given on its man page. The cfdisk command is similar to fdisk, but has a nicer (full screen) user interface.
1. fdisk -l
fdisk is a dialog-driven program for creation and manipulation of partition tables. It understands GPT, MBR, Sun, SGI and BSD partition
tables. Block devices can be divided into one or more logical disks called partitions. This division is recorded in the partition table, usually found in sector 0 of the disk.
fdisk -l command is used to list the partition tables for the specified devices and then exit. If no devices are given, those mentioned in /proc/partitions (if that file exists) are used.
2. lsblk
lsblk lists information about all available or the specified block devices. The lsblk command reads the sysfs filesystem and udev db to gather information. The command prints all block devices (except RAM disks) in a tree-like format by default.
The default output, as well as the default output from options like –fs and –topology, is subject to change. So whenever possible, you should avoid using default outputs in your scripts. Always explicitly define expected columns by using –output columns-list in environments where a stable output is required.
You can also use lsblk command with arguments -f or –fs. It displays info about filesystems. This option is equivalent to -o NAME,FSTYPE,LABEL,UUID,MOUNTPOINT.
If you are not sure about the output, use lsblk –help to get a list of all available columns.
3. parted
The parted comamnd is a program to manipulate disk partitions. It supports multiple partition table formats, including MS-DOS and GPT. It is useful for creating space for new operating systems, reorganising disk usage, and copying data to new hard disks.