10 Monitoring Linux Disk Partitions and Usage in Linux

In Linux, disk partitions refer to logically separated sections or slices of a physical hard disk drive or storage device. These partitions allow users to divide the available disk space into distinct units, each treated as an individual storage entity.

Here are some essential aspects of Linux disk partitions:

  1. Organization of Disk Space: Partitions enable the organization and management of disk space by creating distinct areas for specific purposes. For instance, separate partitions can be designated for the operating system files, user data, system logs, or swap space.
  2. Partition Types:
    • Primary Partition: The primary partition is the main division on the disk that can contain a file system and bootable operating system.
    • Extended Partition: An extended partition is a special type used to create additional logical partitions within it.
    • Logical Partition: Logical partitions exist within an extended partition and provide further segmentation of disk space.
  3. File Systems:
    • Each partition typically holds its own file system, such as ext4, ext3, XFS, NTFS, FAT32, or others. The file system determines how data is organized, stored, and accessed on that partition.
  4. Partitioning Tools:
    • Various command-line utilities like fdisk, parted, gdisk, and graphical tools like gparted are used to create, delete, resize, or modify partitions on a disk.
  5. Mounting:
    • After creating partitions, they need to be mounted onto the Linux file system to be accessible. This process involves attaching a partition to a specific directory (mount point) in the file system hierarchy.
  6. Device Naming:
    • In Linux, partitions are represented using device names such as /dev/sda1, /dev/sdb2, etc. The initial part (/dev/sd) refers to the device itself, while the letter and number signify the partition number.
  7. Usage and Benefits:
    • Disk partitions allow better organization of data, facilitating backup, system maintenance, and data isolation.
    • They also aid in securing critical system areas from accidental data corruption or user errors by isolating different types of data onto separate partitions.

Understanding disk partitions is crucial for managing disk space effectively, optimizing system performance, and ensuring data security and accessibility in Linux systems. Proper planning and caution are recommended when creating, modifying, or managing disk partitions to avoid data loss or system instability.

A System Administrator (SysAdmin) in the context of hosting plays a crucial role in managing and maintaining the infrastructure and services that provide hosting solutions.

Monitoring the space usage of storage devices is one of the most important tasks for a SysAdmin, which ensures that there is adequate free space available on the storage devices to maintain the efficient operation of your Linux system.

List of Command Line Tools to Check Linux Disk Partitions

Following is a list of command line utilities for printing storage device partition tables and space usage.

1. fdisk (fixed disk) Command

fdisk is a powerful and popular command line tool used for creating and manipulating disk partition tables. It supports various partition table formats, including GPT, MBR, Sun, SGI, and BSD.

You can use fdisk‘s user-friendly, text-based, menu-driven interface to perform tasks such as displaying, creating, resizing, deleting, modifying, copying, and moving partitions on storage disks

The fdisk command below will print the partition table of all mounted block devices:

fdisk -l

2. sfdisk (scriptable fdisk) Command

sfdisk works similarly to fdisk as it can print or manipulate a storage disk partition table. However, sfdisk offers additional features that are not available in fdisk. You can use it just like fdisk, and it also supports GPT, MBR, Sun, and SGI partition tables.

One difference between the two is that sfdisk does not create the standard system partitions for SGI and SUN disk labels like fdisk does.

sfdisk -l

3. cfdisk (curses fdisk) Command

cfdisk is a simple program used for printing and managing disk partitions by providing basic partitioning functionality through a user-friendly interface that operates similarly to more powerful commands like fdisk and sfdisk, enabling users to view, add, delete, and modify hard disk partitions.

Use the right and left arrow keys to move the highlighter over the menu tabs.

cfdisk

4. Parted Command

The parted command is a versatile and powerful utility for managing disk partitions on Unix-like operating systems. With a wide array of features, it allows users to create, resize, delete, and manipulate partitions on hard drives, making it essential for system administrators and advanced users.

The parted tool supports both MBR (Master Boot Record) and GPT (GUID Partition Table) partitioning schemes and provides options for various file systems.

Additionally, parted provides a range of advanced features, such as alignment control and the ability to create, resize and copy disk partitions (add a progress bar while copying), making it an indispensable tool for disk management tasks.

parted -l

5. lsblk (list block) Command

The lsblk command provides a detailed overview of storage devices, including hard drives, solid-state drives, and removable media, along with their associated information like size, partitions, and mount points.

lsblk aids in system administration tasks, making it easier to identify available storage resources, understand disk configurations, and manage storage devices efficiently.

Its straightforward output and customization options make it a valuable tool for system administrators, helping ensure effective storage management and troubleshooting.

lsblk

6. blkid (block id) Command

The blkid command is used to identify block devices such as hard drives and partitions by their Universally Unique Identifier (UUID) or other attributes. It provides crucial information about storage devices, making it easier to mount and manage them.

blkid

7. hwinfo (hardware info) Command

The hwinfo command is used to provide comprehensive data about the system’s components, including CPU, RAM, storage devices, graphics cards, network interfaces, and more.

The system administrators and users employ ‘hwinfo‘ to diagnose hardware issues, identify compatible drivers, and enhance system performance.

hwinfo

List of Command Line Tools to Monitor Linux Disk Space Usage

The following list includes command-line utilities for monitoring Linux disk space usage.

8. df (disk filesystem) Command

The df command is used to retrieve essential information about disk usage and available storage space on Linux file system usage.

The “df” command assists users in monitoring disk space allocation, identifying potential storage issues, and making informed decisions regarding data management and cleanup.

The '-hT' switch in the command below enables human-readable reporting of disk size, used space, available space, and used space percentages.

df -hT

9. du (disk usage) Command

The du command is used to allow users to assess the space occupied by files and directories on their storage device in a human-readable format.

The du command helps users identify which files or directories consume the most space, aiding in disk management, cleanup, and optimization tasks. This command is invaluable for system administrators and users seeking to maintain efficient disk usage.

du -sh /home/

10. pydf (python df) Command

The pydf command is an exceptional Python command line utility and a great replacement for the df command in Linux. It uses distinct colors to highlight disk partitions with specific attributes.

pydf

What to Do When Your Linux Disk/Partition Is Running Out of Space?

Once you realize that any of your storage disk(s) is running out of space or is full, you should:

First, make a backup of all your important files on the system using any of the Linux system backup tools.Next, check which files or directories are occupying the biggest amount of space on the disk(s) using the du command.Then delete from the storage disk(s), any files that are no longer important or that you will not use in the future with the help of the rm command or you can CCleaner tools to find and delete unwanted files in Linux.If your root partition is getting full, you can resize root partition using LVM, it should be pretty straight.

We hope you’ve found this useful