How To Linux List Disk Partitions Command

Configurare noua (How To)

Situatie

How do I list all hard disk partitions under a Linux operating systems using the CLI?

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 on. A device name refers to the entire disk, and the device name will be as follows:

  • /dev/hd* – IDE disks. /dev/hda will be first IDE hard disk, /dev/hdb will be second IDE hard disk, and so on.
  • /dev/sd* – SCSI or SATA disks including SSDs. /dev/sda will be first SATA/SCSI hard disk, /dev/sdb will be second SATA/SCSI hard disk, and so on.
  • /dev/nvme* – NVM Express (NVMe) pci SSD. /dev/nvme0n1 will be first NVMe SSD, /dev/nvme1n1 will be second NVMe SSD, 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.

lsblk Command to list block device on Linux

To list all block devices, run:
# lsblk
# lsblk /dev/DEVICE
# lsblk /dev/sda
# lsblk -l
# lsblk -d | grep disk

Linux list block devices

We can also fine-tune information displayed by lsblk as follows to list only Linux partitions and other data:
# lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT

Pass the following -f and -m to see detailed info:
# lsblk -f -m
# lsblk -f -m | grep ext4

Understanding lsblk option that displays block devices and partitions
  • -m : Show info about Linux permissions
  • -f : List info about Linux filesystems
  • -l : Force list format output option
  • -d : Avoid printing holders. In other words just see block device/disk names
  • -o NAME,FSTYPE,SIZE,MOUNTPOINT : Only display selected columns as per Table 1.
Table 1
Column Descripton
NAME device name
KNAME internal kernel device name
PATH path to the device node
MAJ:MIN major:minor device number
FSAVAIL filesystem size available
FSSIZE filesystem size
FSTYPE filesystem type
FSUSED filesystem size used
FSUSE% filesystem use percentage
MOUNTPOINT where the device is mounted
LABEL filesystem LABEL
UUID filesystem UUID
PTUUID partition table identifier (usually UUID)
PTTYPE partition table type
PARTTYPE partition type UUID
PARTLABEL partition LABEL
PARTUUID partition UUID
PARTFLAGS partition flags
RA read-ahead of the device
RO read-only device
RM removable device
HOTPLUG removable or hotplug device (usb, pcmcia, …)
MODEL device identifier
SERIAL disk serial number
SIZE size of the device
STATE state of the device
OWNER user name
GROUP group name
MODE device node permissions
ALIGNMENT alignment offset
MIN-IO minimum I/O size
OPT-IO optimal I/O size
PHY-SEC physical sector size
LOG-SEC logical sector size
ROTA rotational device
SCHED I/O scheduler name
RQ-SIZE request queue size
TYPE device type
DISC-ALN discard alignment offset
DISC-GRAN discard granularity
DISC-MAX discard max bytes
DISC-ZERO discard zeroes data
WSAME write same max bytes
WWN unique storage identifier
RAND adds randomness
PKNAME internal parent kernel device name
HCTL Host:Channel:Target:Lun for SCSI
TRAN device transport type
SUBSYSTEMS de-duplicated chain of subsystems
REV device revision
VENDOR device vendor
ZONED zone model
How to locate/print block device attributes using blkid

Apart from physical block storage and logical partitions, your Linux box may have software RAID and encrypted hard disks too. We can determine the type of filesystem that a block device holds and also the attributes:
# blkid

List partitions ynder Linux using the fdisk command

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

OR
$ sudo fdisk -l

You can specify device name as follows (in this example list partitions for /dev/sda):
# fdisk -l

Display disk partitions using sfdisk command in Linux

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

Linux partitions info:

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.
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

Using hardware detction tools to print disk paritions on Linux

You can install and use the following tools. We can use the hwinfo command to probe for hardware as follows:
hwinfo | more
hwinfo --block | more
hwinfo --block --short
inxi -P
inxi -p | more

Solutie

Tip solutie

Permanent

Voteaza

(14 din 27 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?