Linux - Disk (storage devices)

> Operating System - Kernel (Windows, Unix, Linux) > Linux / Unix > Linux - Disk (storage devices)

1 - About

Drive - Hard (disk|drive) (HDD) in Linux.

It contains partitions that contains file system that are mounted to be made available to the OS.

Advertising

3 - Name

A disk name is the following syntax without the Partition number but to understand the whole story, we have added it.

# Disk Name
/dev/[sd|hd]Unit
# Partition Name
/dev/[sd|hd]UnitPartition

where:

  • unit starts with “a” for the first unit, “b” for the second, and so on. Therefore, the first hard drive on your system may appear as hda or sda.
  • partition is a number representing a specific partition on the device, starting with “1.” The number may be one or two digits in length, depending on the number of partitions written to the specific device.

Therefore:

  • /dev/[sd|hd]Unit refers to a disk name (usually /dev/sda, /dev/sdb or so)
  • and /dev/[sd|hd]UnitPartition refers to a partition name (usually /dev/sda1, /dev/sdb1 or so)

The disk name is:

  • usually /dev/sda, /dev/sdb or so.
  • or /dev/hd* (IDE) or /dev/sd* (SCSI). The old systems without libata (a library used inside the Linux kernel to support ATA host controllers and devices) make a difference between IDE and SCSI disks.

Examples:

  • /dev/hda1 — The first partition on the first ATA drive
  • /dev/sdb12 — The twelfth partition on the second SCSI drive
  • /dev/sdad4 — The fourth partition on the thirtieth SCSI drive
Advertising

4 - Management

4.1 - See the disk

4.1.1 - Directory

Under Red Hat Linux, the device files for disk drives appear in the /dev/ directory.

ls /dev/
agpgart    floppy-fd0  null      ram4      tty1   tty30  tty51    vcs1
cdrom      full        nvram     ram5      tty10  tty31  tty52    vcs2
cdrom-hdc  gpmctl      oldmem    ram6      tty11  tty32  tty53    vcs3
console    hdc         par0      ram7      tty12  tty33  tty54    vcs4
core       hpet        parport0  ram8      tty13  tty34  tty55    vcs5
disk       initctl     parport1  ram9      tty14  tty35  tty56    vcs6
fd         input       parport2  ramdisk   tty15  tty36  tty57    vcs7
...........................

The format for each file name depends on several aspects of the actual hardware and how it has been configured. The important points are as follows:

4.1.2 - dmesg

dmesg | grep -i "device sd"
# Axure: dmesg | grep SCSI
# or  grep -i "\[sd.\]"
SCSI device sda: 167772160 512-byte hdwr sectors (85899 MB)
SCSI device sda: 167772160 512-byte hdwr sectors (85899 MB)
SCSI device sdb: 1048576000 512-byte hdwr sectors (536871 MB)
SCSI device sdb: 1048576000 512-byte hdwr sectors (536871 MB)

Here we can see that we have two disk:

  • sda (85899 MB)
  • and sdb (536871 MB)
Advertising

4.2 - Get the UUID

sudo -i blkid
/dev/sdc1: UUID="aa6c9d84-94d3-48dd-a037-d98064b9f96c" TYPE="ext4"
/dev/sda1: UUID="ca02dd2d-a91b-4fb1-b24b-0fb19c18b89d" TYPE="xfs"
/dev/sda2: UUID="3c11fba3-32c7-4d0c-b614-aad5630504eb" TYPE="xfs"
/dev/sdb1: UUID="d824e95a-04db-479e-8acf-a3179ee64d16" TYPE="ext4"

4.3 - Mount

  • Mount a partition to a directory
mount /dev/sdc1 /datadrive

See Linux - Mounting File Systems (CDROM, NFS, SMB, ...)

4.4 - Partition

4.5 - Format

Write a the ext4 file system to the partition 1 of the disk sdc

mkfs -t ext4 /dev/sdc1
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2621440 inodes, 10485504 blocks
524275 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2157969408
320 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

5 - Type

More information about ATA and SCSI can be found in Present-Day Industry-Standard Interfaces.

6 - Documentation / Reference

os/linux/disk/disk.txt · Last modified: 2018/12/27 19:50 by gerardnico