Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: July 31, 2024
$ ls -l /dev | grep "sda"
brw-rw---- 1 root disk 8, 0 Apr 29 22:33 sda
brw-rw---- 1 root disk 8, 1 Apr 29 22:33 sda1
brw-rw---- 1 root disk 8, 2 Apr 29 22:33 sda2
brw-rw---- 1 root disk 8, 3 Apr 29 22:33 sda3
brw-rw---- 1 root disk 8, 4 Apr 29 22:33 sda4
brw-rw---- 1 root disk 8, 5 Apr 29 22:33 sda5
brw-rw---- 1 root disk 8, 6 Apr 29 22:33 sda6
From the output shown, we use grep to filter the results and get those that only contain sda. Let us discuss the first line in our example above:
brw-rw---- 1 root disk 8, 0 Apr 29 22:33 sda
Earlier, we have seen that /dev/sd[a-z] stands for the hard drive. During installation, Linux takes the first hard disk found and assigns it the value sda. It does the naming in an alphabetical order depending on the number of disks found. In the following lines, we see a number appended to sda[1-15]. For example, in lines 2 and 3, we have:
brw-rw---- 1 root disk 8, 1 Apr 29 22:33 sda1
brw-rw---- 1 root disk 8, 2 Apr 29 22:33 sda2
If we have multiple partitions in the hard disk, the system consecutively appended a number starting from sda1 to sda15. In a single hard disk, we can only have a maximum of 15 partitions.
$ sudo fdisk -l
Disk /dev/sda: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 104447 102400 50M 7 HPFS/NTFS/exFAT
/dev/sda2 104448 484152681 484048234 230.8G 7 HPFS/NTFS/exFAT
/dev/sda3 484155392 485249023 1093632 534M 27 Hidden NTFS WinRE
/dev/sda4 485251070 976771071 491520002 234.4G 5 Extended
/dev/sda5 485251072 974772223 489521152 233.4G 83 Linux
/dev/sda6 974774272 976771071 1996800 975M 82 Linux swap / Solaris
This command shows us the capacity of our hard disk, the partitions within it, and their respective sizes. Next, let us look at lsblk:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 465.8G 0 disk
├─sda1 8:1 0 50M 0 part
├─sda2 8:2 0 230.8G 0 part
├─sda3 8:3 0 534M 0 part
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 233.4G 0 part /
└─sda6 8:6 0 975M 0 part [SWAP]
sr0 11:0 1 1024M 0 rom
This command shows us all the available block devices connected to the system, except RAM. It displays the output in a tree-like structure. In the examples below, we have added an external storage device. Let us look at the output when we run both fdisk and lsblk, respectively:
$ sudo fdisk -l
Disk /dev/sdb: 115.32 GiB, 123828436992 bytes, 241852416 sectors
Device Start End Sectors Size Type
/dev/sdb1 2048 241852382 241850335 115.3G Microsoft basic data
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sdb 8:16 1 115.3G 0 disk
└─sdb1 8:17 1 115.3G 0 part /media/gt3/BK
sr0 11:0 1 1024M 0 rom
In the first example, we had the primary hard disk /dev/sda, which had the following partitions: sda1, sda2,sda3, sda4, sda5, and sda6. In the second example, we have added an external storage device, which is a flash drive displaying as /dev/sdb, which only has a single partition /dev/sdb1.