HowTo: Linux List Disk Partitions Command

0
827

How do I list all hard disk partitions under Linux operating systems?

Usually, your hard disk drive divided into one or more logical disks called partitions. This division is described in the partition table found in sector 0 of the hard disk. The device is usually /dev/sda, /dev/sdb or so. A device name refers to the entire disk and the device name will be as follows:

  1. /dev/hd* – IDE disks. /dev/hda will be first IDE hard disk, /dev/hdb will be second IDE hard disk, and so on.
  2. /dev/sd* – SCSI or SATA disks. /dev/sda will be first SATA/SCSI hard disk, /dev/sdb will be second SATA/SCSI hard disk, and so on.
WARNING! These examples may crash your computer if NOT executed with proper care. BE EXTREMELY CAREFUL WITH THE FOLLOWING COMMANDS. ONE TYPING MISTAKE AND ALL YOUR DATA IS LOST.

List Partitions Under Linux

Open a terminal window (select Applications > Accessories > Terminal). Switch to the root user by typing su – and entering the root password, when prompted. Or use sudo command:
$ su -
# fdisk -l

OR
$ sudo fdisk -l
Sample outputs:

Disk /dev/sda: 251.1 GB, 251059544064 bytes
255 heads, 63 sectors/track, 30522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0008fcd3
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          14      104448   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              14       13068   104857600   83  Linux
/dev/sda3           13068       13198     1048576   82  Linux swap / Solaris
/dev/sda4           13198       30523   139163648    5  Extended
/dev/sda5           13198       30523   139162624   83  Linux

The -l options 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. You can specify device name as follows (in this example list partitions for /dev/sda):
# fdisk -l

sfdisk Command

The sfdisk command act as a partition table manipulator for Linux. You can use this tool to list partitions too:
# sfdisk -l /dev/sda
# sfdisk -lu /dev/sda
# sfdisk -ls /dev/sda

Sample outputs:

71669760
Disk /dev/sda: 8922 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sda1   *      0+    104-    105-    838656   83  Linux
/dev/sda2        104+    235-    131-   1048576   82  Linux swap / Solaris
/dev/sda3        235+   8922-   8688-  69781504   83  Linux
/dev/sda4          0       -       0          0    0  Empty

Where,

  1. -l : List the partitions of a device.
  2. -s : List the size of a partition.
  3. -u or -uS or -uB or -uC or -uM : Accept or report in units of sectors (blocks, cylinders, megabytes, respecpively). The default is cylinders, at least when the geometry is known.

Listing Linux a Partition Size Larger Than 2TB

The fdisk or sfdisk command will not list any partition size larger than 2TB. To solve this problem you need to use GNU parted command with GPT partitions. It supports Intel EFI/GPT partition tables. Partition Table (GPT) is a standard for the layout of the partition table on a physical hard disk. It is a part of the Extensible Firmware Interface (EFI) standard proposed by Intel as a replacement for the outdated PC BIOS, one of the few remaining relics of the original IBM PC. EFI uses GPT where BIOS uses a Master Boot Record (MBR). In this example list partitions on /dev/sdb using the parted command:
# parted /dev/sdb
Sample outputs:

GNU Parted 2.3
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted)

Set unit type to TB or GB by typing ‘unit TB‘ or ‘unit GB‘ at the (parted) prompt:
(parted) unit TB
OR
(parted) unit GB
To list partitions type print command at the (parted) prompt:
(parted) print
Sample outputs:

Model: ATA ST33000651AS (scsi)
Disk /dev/sdb: 3001GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start   End     Size    File system  Name     Flags
 1      0.00GB  3001GB  3001GB  ext4         primary
(parted)

To exit from parted session type ‘quit’ at the (parted) prompt:
(parted) quit

How Do I List All Partitions Layout On All Block Devices?

Pass the -l OR –list option to the parted command to lists partition layout on all block devices:
# parted -l
Sample outputs:

Fig.01: Show Linux Disk Partitions With GNU parted Command

Originally posted 2016-01-11 05:53:20.

LEAVE A REPLY

Please enter your comment!
Please enter your name here