In this brief guide, we will see all the possible ways to find and list disk partitions in Linux and Unix-like operating systems. Before getting into the topic, let us take a quick look at what is disk partitioning and how disk partitions are named in Linux.
Table of Contents
Disk partitioning in Linux
Disk partitioning or disk slicing is a method of dividing a physical storage disk device into multiple logical sections. These sections are known as partitions. A hard disk drive can contain one or several partitions.
In Linux and Unix-like systems, the disk is usually divided into three partitions:
- One partition is used for keeping the system files. It is usually mounted on
"/"
(root
directory). - One partition is used for keeping the users configuration files and their personal data. It is mounted on
/home
directory. - And a swap partition.
All partitions should be formatted with a filesystem, for example EXT4, before installing the OS and/or saving any data in it.
The partition table information is stored in Master Boot record (MBR) in BIOS-based systems and GUID Partition Table (GPT) in UEFI-based systems.
At system boot, BIOS or UEFI scans all storage devices, detects the MBR/GPT areas, finds the boot disks, loads the bootloader program (i.e. grub2) in memory from the default boot disk, executes the boot code to read the partition table and identify the /boot
partition, loads the Kernel in memory, and finally passes the control to the Kernel. Kernel takes care of the rest of the boot process and loads the OS.
Disk and partition names in Linux
You need to know the correct names that Linux uses when you are creating, mounting, and deleting partitions.
The name of disks and the partitions in Linux differs from other operating systems. The basic naming scheme in Linux OS is given below:
- The name of the first floppy drive is
/dev/fd0
. - The name of the second floppy drive is
/dev/fd1
, and so on. - The first hard disk (the primary master) detected is named
/dev/sda
. - The second hard disk detected is named
/dev/sdb
, and so on. - The first SCSI CD-ROM is named
/dev/scd0
. It is also known as/dev/sr0
.
You might be wondering what sda
does stands for. sd
is originally for referring scsi disk devices, however it is now used to refer SATA devices and any removable devices in general.
The partitions on each disk are represented by appending a decimal number to the disk name. For example, sda1
is the first partition in the first SCSI hard drive, sda2
represents the second partition of the first disk drive, sdb1 is the first partition in the second hard drive and so on. In layman terms, s
refers to the interface (SATA, SAS, or SCSI), d
is for disk, a
is for the device id, and the number is for partition id. The same applies to the subsequent disks added to the system.
Knowing Linux disks and partitions name is just enough for the purpose of this guide. If you want to know more details, a quick web search may yield many relevant results. Let us get back to the topic. There are many ways to view disk partitions in Linux. First, we will start with lsblk
command line utlity.
1. List disk partitions in Linux using lsblk command
The lsblk utility is used to display information about a specified block device as well as all available block devices, along with their partitioning schemes in Linux. It reads the sysfs
filesystem and udev db
to collect information of disks and partitions and displays the output in tree-like format.
To list disk and partition information with lsblk command, simply run it without any options:
$ lsblk
Or,
$ sudo lsblk
Sample output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT loop0 7:0 0 55M 1 loop /snap/core18/1705 loop1 7:1 0 55M 1 loop /snap/core18/1754 loop2 7:2 0 69.4M 1 loop /snap/lxd/15223 loop3 7:3 0 71.2M 1 loop /snap/lxd/15913 loop4 7:4 0 27.1M 1 loop /snap/snapd/7264 loop5 7:5 0 29.8M 1 loop /snap/snapd/8140 sda 8:0 0 20G 0 disk ├─sda1 8:1 0 1M 0 part └─sda2 8:2 0 20G 0 part / sr0 11:0 1 1024M 0 rom
As you see in the above output, lsblk
command lists one 20GB disk named sda
, with two partitions namely sda1
and sda2
. If you look under the Type column in the above output, it shows the type of the device i.e. disk or part (i.e. partition).
Did you notice there is one more partition name sr0
? It represents the ISO image mounted as an optical medium.
You may have more than one devices in your system. In that case, just specify the disk device name like below:
$ lsblk /dev/sda
The above command will show the partition details in the first disk drive.
You can even display more details including filesystem type, UUID, Mountpoint etc., like below:
$ lsblk -io KNAME,TYPE,SIZE,MODEL,FSTYPE,UUID,MOUNTPOINT
Alternatively, you could use -fm
option to display mountpoint, size, owner, mode:
$ lsblk -fm
2. Display disk partitions using fdisk command in Linux
Fdisk is a command line, dialog-driven program for managing partition tables and partitions on a hard disk in Linux.
To display disk partitions in Linux, run fdisk
command with -l
option as root
or sudo
user:
$ sudo fdisk -l
Sample output:
[...] Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors Disk model: VBOX HARDDISK Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: 46F42576-F542-4AD4-9BE4-31E59BAFE3C1 Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 41940991 41936896 20G Linux filesystem
In the above output, you will see all available disk partitions.
To view the partition table in a specific disk drive, explicitly mention its name like below:
$ sudo fdisk -l /dev/sda
3. Check Hard disk partitions using sfdisk in Linux
Sfdisk is is a script-oriented tool for partitioning any block device. Sfdisk usage is same fdisk's usage.
To check the hard disk partitions in Linux with sfdisk
command, run:
$ sudo sfdisk -l
You can also check the partitions in a specific device as well.
$ sudo sfdisk -l /dev/sda
4. Check Linux disk partitions using cfdisk
Cfdisk is a curses-based, command line program for partitioning any block device in Linux and Unix-like systems.
To check all available disk partitions in Linux using cfdisk
, run:
$ sudo cfdisk
Sample output:
To exit, press q or choose Quit option by using arrow keys and hit ENTER.
By default, Cfdisk lists partition details of /dev/sda
disk.
5. Find disk partitions in Linux using blkid
The blkid is a yet another command line program to list all recognized partitions and their UUID (Universally Unique Identifier).
To list al partitions in your Linux machine, run blkid as root
or sudo
user:
$ sudo blkid
Sample output:
/dev/sda2: UUID="81bb4976-a820-4e0d-92ab-1a754f9837bd" TYPE="ext4" PARTUUID="ea153271-0c12-4b95-9dee-3dab58a1fd03" /dev/loop0: TYPE="squashfs" /dev/loop1: TYPE="squashfs" /dev/loop2: TYPE="squashfs" /dev/loop3: TYPE="squashfs" /dev/loop4: TYPE="squashfs" /dev/loop5: TYPE="squashfs" /dev/sda1: PARTUUID="02fcad04-66ea-41e0-8673-4e3fbbf1883a"
You can also list all partitions in a table, including current mountpoints:
$ sudo blkid -o list
Sample output:
device fs_type label mount point UUID ------------------------------------------------------------------------ /dev/sda2 ext4 / 81bb4976-a820-4e0d-92ab-1a754f9837bd /dev/loop0 squashfs /snap/core18/1705 /dev/loop1 squashfs /snap/core18/1754 /dev/loop2 squashfs /snap/lxd/15223 /dev/loop3 squashfs /snap/lxd/15913 /dev/loop4 squashfs /snap/snapd/7264 /dev/loop5 squashfs /snap/snapd/8140 /dev/sda1 (not mounted)
6. Get disk partition details using hwinfo tool
Hwinfo is a free, open source and command line utility to find Linux system hardware information. It probes for the hardware present in your Linux system and displays the extensive details of each hardware device.
Hwinfo is not installed by default in many Linux distribution. Refer the following link to install Hwinfo in your Linux system.
Once installed, run the following command to get the list of disk partitions in your Linux system with hwinfo
utility:
$ hwinfo --block --short
Sample output:
disk: /dev/sda VBOX HARDDISK partition: /dev/sda1 Partition /dev/sda2 Partition cdrom: /dev/sr0 VBOX CD-ROM
Here the --short
option is used precisely display the disk name, partition names and the CD ROM in user-friendly format, excluding all other details.
If you want to display, full details of the partitions, just remove the --short
option.
7. List Linux partition details with inxi
Inxi is a command line system information tool. This script is specifically built for console and IRC. It is also used as a debugging tool for forum technical support to quickly ascertain users' system configurations and hardware.
Inxi is not available by default. You need to install it in your Linux box as shown in the following guide:
Once installed, list the partition details with inxi
, use -P flag:
$ inxi -P
Sample output:
Partition: ID-1: / size: 19.56 GiB used: 5.72 GiB (29.3%) fs: ext4 dev: /dev/sda2
If you want to show full partition details, use -p
(small letter):
$ inxi -p
Sample output:
Partition: ID-1: / size: 19.56 GiB used: 5.72 GiB (29.3%) fs: ext4 dev: /dev/sda2 ID-2: /snap/core18/1705 raw size: 54.9 MiB size: <superuser/root required> used: <superuser/root required> fs: squashfs dev: /dev/loop0 ID-3: /snap/core18/1754 raw size: 54.9 MiB size: <superuser/root required> used: <superuser/root required> fs: squashfs dev: /dev/loop1 ID-4: /snap/lxd/15223 raw size: 69.3 MiB size: <superuser/root required> used: <superuser/root required> fs: squashfs dev: /dev/loop2 ID-5: /snap/lxd/15913 raw size: 71.2 MiB size: <superuser/root required> used: <superuser/root required> fs: squashfs dev: /dev/loop3 ID-6: /snap/snapd/7264 raw size: 27.1 MiB size: <superuser/root required> used: <superuser/root required> fs: squashfs dev: /dev/loop5 ID-7: /snap/snapd/8140 raw size: 29.8 MiB size: <superuser/root required> used: <superuser/root required> fs: squashfs dev: /dev/loop4
8. Manually List all disk partitions by probing proc filesystem
Proc file system (or shortly procfs) is a virtual file system maintained by the Linux kernel. It is also sometimes referred to as a process information pseudo-file system. It doesn't contain 'real' files but runtime system information such as system memory, devices mounted, hardware configuration etc. All these information are available under a special directory named /proc
in Linux.
The disks and partitions details are available in /proc/partitions
file. So, we can list all disk partitions by looking at the contents of this file using cat
command:
$ cat /proc/partitions
Sample output:
major minor #blocks name 7 0 56264 loop0 7 1 56268 loop1 7 2 71008 loop2 7 3 72952 loop3 7 4 30540 loop4 7 5 27740 loop5 11 0 1048575 sr0 8 0 20971520 sda 8 1 1024 sda1 8 2 20968448 sda2
9. View disk partitions in Linux with parted
Parted is a command line program to manipulate disk partitions in Linux and Unix-like systems. It supports
multiple partition table formats, including MS-DOS and GPT. Parted is specifically used to create and manage partitions in disks larger than 2TB.
To view disk partitions in Linux, run parted
command with -l
option:
$ sudo parted -l
Sample output:
Model: ATA VBOX HARDDISK (scsi) Disk /dev/sda: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 2097kB 1049kB bios_grub 2 2097kB 21.5GB 21.5GB ext4
All of the aforementioned tools are commandline-based. If you are a newbie who is not much comfortable with Terminal, you can use the following two graphical tools to check partition details in Linux.
10. View disk partition details using GParted in Linux
GNOME Partition Editor (or shortly GParted) is a graphical front-end to parted
command line tool. Using GParted, you can create and manage disk partitions via a simple and easy-to-use graphical interface.
GParted is not installed by default, but it is available in the default repositories of several Linux distributions. So you can install GParted using your distribution's default package manager. For example, Gpated can be installed on Debian, Ubuntu and other DEB-based systems like below:
$ sudo apt install gparted
To view your disk partition table, simply open GParted utility from menu or Dash.
Important Note: Just do not change anything unless you know what you are doing.
11. Find disk partitions with GNOME Disks
GNOME Disks or gnome-disk-utility is a graphical utility to view, modify and configure disks and media in Linux. It comes pre-installed in Linux distributions that has GNOME Desktop environment.
Open GNOME Disks utility to find all available partitions in your hard disk.
And, that's all. These are the few ways to list Linux disk partitions. There are many other tools and commands available to find the partitions in a disk. I guess I've covered enough. If you think I missed any important tool in this list, feel free to leave a note in the comment section below.
Featured Image by Christopher Muschitz from Pixabay.
4 comments
What you did was good, BUT, it is 2021, and you show floppy drive [ /dev/fd0 ], yet no mention of SSD???
Disk /dev/nvme1n1: 465.78 GiB, 500107862016 bytes, 976773168 sectors
Disk model: Samsung SSD 960 EVO 500GB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 772C08A9-3659-4F14-9D67-630FF7485A19
Device Start End Sectors Size Type
/dev/nvme1n1p1 2048 976773119 976771072 465.8G Linux filesystem
Disk /dev/nvme0n1: 476.96 GiB, 512110190592 bytes, 1000215216 sectors
Disk model: Samsung SSD 960 PRO 512GB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 906C3AA9-699B-47AC-A6C0-FDA7EF4C6C95
Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 1050623 1048576 512M EFI System
/dev/nvme0n1p2 1050624 1000214527 999163904 476.4G Linux filesystem
Thanks. I didn’t have SSD at the time of writing this guide. I will update this guide after I got a SSD.
Thanks a lot !
Very convenient :).
Thank you for explaining things in such a way it’s a great help.