1. Overview

In many instances, command output in your Linux terminal may contain a reference to the directory /dev/sda. What does this directory represent?

In this tutorial, we’ll learn what /dev/sda represents. First, we’ll look at the /dev directory, followed by /dev/sda. Lastly, we will look at the commands we can use to get more information about /dev/sda.

2. The /dev Directory and Its Content

Linux traditionally treats everything as a file or directory to read from or to write to. So when we look at /dev/sda, we can assume it is an absolute path. Why is this path important and where does it lead us?

/dev is a directory in the root folder that contains all the device files. The system creates these files during installation, and they must be available during the boot process. When we list the content of /dev (i.e., with the ls command), we realize that most of the files listed are either block or character devices. However, apart from these two, other types of device files also exist in the /dev directory.

A more detailed and direct way we can identify device files in the /dev directory is by using the device’s major and minor numbers. For example, disk devices have a major number of 8, which assigns them as SCSI block devices. Note that the SCSI subsystem manages all PATA and SATA hard drives. This is because the old ATA subsystem is not maintainable due to the poor quality of its code. *As a result, hard drives that would previously be designated as hd[a-z] are now referred to as sd[a-z].* Currently, sd[a-z] is the most used way to refer to hard disks. Though, some distros still use hd[a-z].

SCSI is a microprocessor-controlled smart bus. It allows us to add up to 15 peripheral devices to the computer. These devices include hard drives, scanners, USB, printers, and many other devices. It stands for small computer system interface.

2.1. /dev/sda

Now that we have looked at the /dev directory and mentioned some of its content, let’s discuss /dev/sda, which is a block device in the /dev directory. First of all, let us find out how many /dev/sda device files we have in the /dev directory by running :

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

3. Listing More Information About /dev/sda

Now that we have identified that /dev/sda refers to the hard disk, let us now look at the commands we can use to get more information about our hard disk and the partitions within it. The first command we use is fdisk:

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

4. Conclusion

In this article, we have learned that /dev/sda is the hard disk of the computer we are using. Also, we now know that sd[a-z] is the currently used naming format for our disks in Linux. And lastly**,** /dev/sda[1-15] shows the partitions within our hard disk. So if we have three disks in our system, the disks will display as /dev/sda, /dev/sdb, and finally*/dev/sdc*.