Storage Management Concepts
Files on a Linux server are accessed through the ﬁle-system hierarchy, a single inverted tree of directories. This ﬁle system hierarchy is assembled from ﬁle systems provided by the storage devices available to your system. Each ﬁle system is a storage device that has been formatted to store ﬁles. In a sense, the Linux ﬁle-system hierarchy presents a collection of ﬁle systems on separate storage devices as if it were one set of ﬁles on one giant storage device that you can navigate. Much of the time, you do not need to know which storage device a particular ﬁle is on, you just need to know the directory that ﬁle is in.
Sometimes, however, it can be important. You might need to determine how full a storage device is and what directories in the ﬁle-system hierarchy are affected. There might be errors in the logs from a storage device, and you need to know what ﬁle systems are at risk. You could just want to create a hard link between two ﬁles, and you need to know if they are on the same ﬁle system to determine if it is possible.
File Systems and Mount Points
To make the contents of a ﬁle system available in the ﬁle-system hierarchy, it must be mounted on an empty directory. This directory is called a mount point. Once mounted, if you use ls to list that directory, you will see the contents of the mounted ﬁle system, and you can access and use those ﬁles normally. Many ﬁle systems are automatically mounted as part of the boot process.
If you have only worked with Microsoft Windows drive letters, this is a fundamentally different concept. It is somewhat similar to the NTFS mounted folders feature.
File Systems, Storage, and Block Devices
Low-level access to storage devices in Linux is provided by a special type of ﬁle called a block device These block devices must be formatted with a ﬁle system before they can be mounted.
Block device ﬁles are stored in the /dev directory, along with other device ﬁles. Device ﬁles are created automatically by the operating system. In Red Hat Enterprise Linux, the ﬁrst SATA/PATA, SAS, SCSI, or USB hard drive detected is called /dev/sda, the second is /dev/sdb, and so on. These names represent the entire hard drive. Other types of storage will have other forms of naming.
Block Device Naming
|TYPE OF DEVICE||DEVICE NAMING PATTERN|
|SATA/SAS/USB-attached storage||/dev/sda, /dev/sdb …|
|virtio-blk paravirtualized storage (some virtual machines)||/dev/vda, /dev/vdb …|
|NVMe-attached storage (many SSDs)||/dev/nvme0, /dev/nvme1 …|
|SD/MMC/eMMC storage (SD cards)||/dev/mmcblk0, /dev/mmcblk1 …|
Normally, you do not make the entire storage device into one ﬁle system. Storage devices are typically divided up into smaller chunks called partitions. Partitions allow you to compartmentalize a disk: the various partitions can be formatted with different ﬁle systems or used for different purposes. For example, one partition can contain user home directories while another can contain system data and logs. If a user ﬁlls up the home directory partition with data, the system partition may still have space available.
Partitions are block devices in their own right. On SATA-attached storage, the ﬁrst partition on the ﬁrst disk is /dev/sda1. The third partition on the second disk is /dev/sdb3, and so on. Paravirtualized storage devices have a similar naming system.
An NVMe-attached SSD device names its partitions differently. In that case, the ﬁrst partition on the ﬁrst disk is /dev/nvme0p1. The third partition on the second disk is /dev/nvme1p3, and so on. SD or MMC cards have a similar naming system. A long listing of the /dev/sda1 device ﬁle on host reveals its special ﬁle type as b, which stands for block device:
[user@host ~]$ ls -l /dev/sda1 brw-rw----. 1 root disk 8, 1 Feb 22 08:00 /dev/sda1
Another way of organizing disks and partitions is with logical volume management (LVM). With LVM, one or more block devices can be aggregated into a storage pool called a volume group. Disk space in the volume group is then parceled out to one or more logical volumes, which are the functional equivalent of a partition residing on a physical disk.
The LVM system assigns names to volume groups and logical volumes upon creation. LVM creates a directory in /dev that matches the group name and then creates a symbolic link within that new directory with the same name as the logical volume. That logical volume ﬁle is then available to be mounted. For example, if a volume group is called myvg and the logical volume within it is called mylv, then the full path name to the logical volume device ﬁle is /dev/myvg/mylv.
Examining File Systems
To get an overview of local and remote ﬁle system devices and the amount of free space available, run the df command. When the df command is run without arguments, it reports total disk space, used disk space, free disk space, and the percentage of the total disk space used on all mounted regular ﬁle systems. It reports on both local and remote ﬁle systems.
The following example displays the ﬁle systems and mount points on host.
[user@host ~]$ df Filesystem 1K-blocks Used Available Use% Mounted on devtmpfs 912584 0 912584 0% /dev tmpfs 936516 0 936516 0% /dev/shm tmpfs 936516 16812 919704 2% /run tmpfs 936516 0 936516 0% /sys/fs/cgroup /dev/vda3 8377344 1411332 6966012 17% / /dev/vda1 1038336 169896 868440 17% /boot tmpfs 187300 0 187300 0% /run/user/1000
The partitioning on the host system shows two physical ﬁle systems, which are mounted on / and /boot. This is common for virtual machines. The tmpfs and devtmpfs devices are ﬁle systems in system memory. All ﬁles written into tmpfs or devtmpfs disappear after system reboot.
To improve readability of the output sizes, there are two different human-readable options: -h or -H. The difference between these two options is that -h reports in KiB (2 raise to 10), MiB (2 raise to 20 ), or GiB (2 raise to 30 ), while the -H option reports in SI units: KB (10 raise to 3 ), MB (10 rasie to 6 ), or GB (10 raise to 9 ). Hard drive manufacturers usually use SI units when advertising their products.
Show a report on the ﬁle systems on the host system with all units converted to human-readable format:
[user@host ~]$ df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 892M 0 892M 0% /dev tmpfs 915M 0 915M 0% /dev/shm tmpfs 915M 17M 899M 2% /run tmpfs 915M 0 915M 0% /sys/fs/cgroup /dev/vda3 8.0G 1.4G 6.7G 17% / /dev/vda1 1014M 166M 849M 17% /boot tmpfs 183M 0 183M 0% /run/user/1000
For more detailed information about space used by a certain directory tree, use the du command. The du command has -h and -H options to convert the output to human-readable format. The du command shows the size of all ﬁles in the current directory tree recursively. Show a disk usage report for the /usr/share directory on host:
[root@host ~]# du /usr/share ...output omitted... 176 /usr/share/smartmontools 184 /usr/share/nano 8 /usr/share/cmake/bash-completion 8 /usr/share/cmake 356676 /usr/share
Show a disk usage report in human-readable format for the /usr/share directory on host:
[root@host ~]# du -h /var/log ...output omitted... 176K /usr/share/smartmontools 184K /usr/share/nano 8.0K /usr/share/cmake/bash-completion 8.0K /usr/share/cmake 369M /usr/share