Understanding Linux Storage Basics

Linux handles both hard disk drives (HDD) and solid state drives (SSD) the same way. It mostly depends on the connection method used to connect those drives to the kernel. There are three main methods to connect kernel and physical drive:

  1. Parallel Advanced Technology Attachment (PATA): connects drive using parallel interface which requires wide cable. PATA supports two devices per adapter.
  2. Serial Advanced Technology Attachment (SATA): connects drive using serial interface. Works with faster speeds than PATA and can support up to four devices per adapter.
  3. Small Computer System Interface (SCSI): connects drive using parallel interface but with speeds of SATA. SCSI supports up to eight devices per adapter.

When we connect any drive type, Linux assigns a file for that device inside /dev directory called raw device. Raw device provides full path to the device on the system. Any data written to that file is written on the device, and any data read from that file is read from that device.

Speaking of naming drives in Linux, PATA devices are named /dev/hdX where X represents individual drive. The SCSI and SATA devices are named /dev/sdX where X represents individual drive.

A partition is one section of physical drive and is treated as separate storage space. Partitioning a drive is done to better organize data where we can separate user data from system data. So that if bad user fills up storage space with unimportant files, system can breath on other partition.

Systems that use BIOS boot loader method use Master Boot Record (MBR) to manage disk partitions. This method supports up to four primary partitions on a drive. Each primary partition can be split into multiple extended partitions. The MBR extended partitions are numbered starting at 5 and above. On the other hand, systems that use UEFI boot loader use GUID Partition Table (GPT) for managing disk partitions. This method supports up to 128 partitions on a drive.

Automatic Drive Detection

At boot time, Linux detects drives and partitions, and assigns each one a unique device filename. However, with the invention of USB removable devices that method needed to be modified. Linux now uses udev application to manage hotplug devices. The udev program runs in the background, and automatically detects new plugged devices. Once detected, they are given unique device filename in /dev directory.

Great feature udev is offering is that it can make device files persistent. This means permanent filename is assigned for given file. By doing that, important devices have permanent name that cannot be in conflict with other devices. So, all files inside /dev/disk directory are links to /dev physical device files. Files are created based on the following attributes of the drive:

  1. /dev/disk/by-id/: Link storage device by their manufacturer make, model, serial number
  2. /dev/disk/by-label/: Link storage device by their label assigned to them (sometimes called by-partuuid)
  3. /dev/disk/by-path/: Link storage device by their physical hardware port they are connected to
  4. /dev/disk/by-uuid/: Link storage device by their 128-bit universally unique identifier (UUID) assigned to the device.

Let’s take a look inside this directory:

[aldin@arch ~]$ ls -la /dev/disk/
total 0
drwxr-xr-x  6 root root  120 Oct 18 12:27 .
drwxr-xr-x 21 root root 3580 Oct 18 12:27 ..
drwxr-xr-x  2 root root  200 Oct 18 12:27 by-id
drwxr-xr-x  2 root root  100 Oct 18 12:27 by-partuuid
drwxr-xr-x  2 root root  200 Oct 18 12:27 by-path
drwxr-xr-x  2 root root  100 Oct 18 12:27 by-uuid
[aldin@arch ~]$ 

Each directory contains a symbolic link that points to the physical disk and partition inside /dev directory. Let’s take a look inside /dev/disk/by-partuuid/:

[aldin@arch by-uuid]$ ls -la /dev/disk/by-partuuid/
total 0
drwxr-xr-x 2 root root 100 Oct 18 12:27 .
drwxr-xr-x 6 root root 120 Oct 18 12:27 ..
lrwxrwxrwx 1 root root  10 Oct 18 12:27 5d79c40f-3625-f44e-88cb-1160088081a1 -> ../../sda1
lrwxrwxrwx 1 root root  10 Oct 18 12:27 92abd148-b0e0-bf40-8785-de55ae84702b -> ../../sda3
lrwxrwxrwx 1 root root  10 Oct 18 12:27 c7ce4846-41b1-ad49-84d7-9e58fe2b6889 -> ../../sda2
[aldin@arch by-uuid]$ ls -la /dev/disk/by-uuid/
total 0
drwxr-xr-x 2 root root 100 Oct 18 12:27 .
drwxr-xr-x 6 root root 120 Oct 18 12:27 ..
lrwxrwxrwx 1 root root  10 Oct 18 12:27 3898728b-a9f9-4964-8a23-6d3bbec99030 -> ../../sda2
lrwxrwxrwx 1 root root  10 Oct 18 12:27 66d3a8df-476b-4c5d-85c5-2f02bac66026 -> ../../sda3
lrwxrwxrwx 1 root root  10 Oct 18 12:27 CAAB-5AD3 -> ../../sda1

This Post Has One Comment

  1. Christine Dewey

    Great blog here! Also your web site loads up very fast!

    What web host are you using? Can I get your affiliate link to your host?

    I wish my site loaded up as fast as
    yours lol

Leave a Reply