boucle ∞

Sparking curiosity, facilitating knowledge-sharing, and fostering community interaction.

Efficient Disk Space Management in Red Hat CentOS
Published 12 july 2023

Managing disk space effectively is crucial for system administrators, as it ensures optimal performance and the smooth operation of systems. We have various utilities at our disposal in Linux, such as df, du, dd, fdisk, parted, lvm (Logical Volume Manager), and more.

df: The df command stands for “disk filesystem”. It reports the amount of disk space used and available on the file system.

1
df -h

The -h flag makes the output human-readable.

du: The du command, short for “disk usage”, summarizes the disk usage of the set of FILEs, recursively for directories.

1
du -sh /path/to/directory

The -s option stands for “summary” and -h for “human-readable”.

dd: The dd command is used to copy and convert raw data. It is widely used for generating large file for I/O testing.

1
dd if=/dev/zero of=filename bs=1G count=1

This creates a 1GB file named filename.

fdisk: The fdisk is a command-line utility that provides disk partitioning functions.

1
sudo fdisk -l

This lists all the disk partitions on the system.

parted: parted is another command-line utility to manage disk partitions.

1
sudo parted -l

This lists the partition layout on all block devices.

When it comes to managing filesystems more dynamically, we make use of logical volume management (LVM). It provides a higher-level view of the disk storage on a computer system than the traditional view of disks and partitions.

pvcreate: This creates a physical volume for later use by the logical volume manager (LVM).

1
sudo pvcreate /dev/sdb1

This initializes /dev/sdb1 as a physical volume.

vgcreate: This creates a new volume group (vg).

1
sudo vgcreate my_vg /dev/sdb1

This creates a volume group my_vg using the physical volume /dev/sdb1.

lvcreate: This creates a logical volume in an existing volume group.

1
sudo lvcreate -n my_lv -L 500M my_vg

This creates a logical volume my_lv of size 500MB in the volume group my_vg.

Remember, while commands like rm and rmdir are helpful for freeing up space, it’s crucial to use them judiciously since they delete files and directories. Always ensure you have a good backup policy before removing any files.

I hope this article gives you a more in-depth understanding of disk management on Linux systems. Remember, the best way to master these commands is through practice, so don’t hesitate to explore these commands in your lab environment.

Lucian

Open source enthousiast.

×