How to view linux disk partitions (partition table)

Partitioning divides a disk drive into one or more logical disks. Each partition is treated as a separate disk with its own file system. Partition information is stored in a partition table.

Primary vs Extended partitions

The original partitioning scheme for PC hard disks allowed only four partitions, called primary partitions. To create more than four partitions, one of these four partitions can be divided into many smaller partitions, called logical partitions. When a primary partition is subdivided in this way, it is known as an extended partition. The partitioning tools presented in this lesson allow you to create primary or extended partitions.

How to list disk partitions

Partition devices are listed in the /proc/partitions file:

# cat /proc/partitions
major minor  #blocks  name

   8       16   20971520 sdb
   8        0   20971520 sda
   ...

The columns are described as follows:
major: The major number of the device. This corresponds with the block device in the
/proc/devices file.
minor: The minor number of the device. This relates to the number at the end of the partition name.
#blocks: The number of physical disk blocks contained in the partition.
name: The name of the partition.

Various utilities are available to display and manipulate the partition table.
1. fdisk
2. cfdisk
3. parted

fdisk utility

The fdisk utility is a common partition table manipulator for Linux. Use fdisk –l to list the partition table. To display the partition for a specific device, include the device name as an argument. For example:

# fdisk -l /dev/sda

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000dddc2

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

cfdisk utility

The screenshot in the picture below shows the user interface of the cfdisk utility, which is used to create, delete, and modify partitions on a disk device. Enter the cfdisk command and include the device that you want to partition as an argument.

# cfdisk /dev/sda

parted utility

The GNU parted utility is also used to view the existing partition table, change the size of existing partitions, or add partitions from free space or additional hard drives. This utility is more advanced than the fdisk utility. It supports more disk label types and offers additional commands. To view partitions in the disk, use the print subcommand in parted utility:

# parted /dev/sda
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print                                                            
Model: VMware, VMware Virtual S (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  1075MB  1074MB  primary  xfs          boot
 2      1075MB  21.5GB  20.4GB  primary               lvm

 (parted) quit
Related Post