To ensure that storage is optimized and data is organized effectively, disk management is an essential component of Linux system administration. Linux disk management commands are easy to learn and may greatly improve system efficiency and productivity, regardless of expertise level. This article covers some of the most important Linux disk and partition management commands and utilities.
1. Fdisk: Listing and Interpreting Disks
Disk partition tables may be easily modified with the help of the robust “fdisk
“ tool. Your hard drives may have partitions added, removed, and modified by you. Use: to see a list of all accessible drives together with their partitions.
sudo fdisk -l
This command gives you a detailed overview of every disk together with the partition layouts. It’s very helpful for figuring out the existing division layout and organizing changes.
2. Devices for Viewing Blocks: lsblk
A command-line tool called lsblk
provides a list of all accessible or designated block devices’ specifications. It does not need root access to execute simple commands, in contrast to fdisk
:
lsblk
Use these words to get more information, such as file system types:
lsblk -f
This command makes it simple to grasp the connections and mount points between all storage devices by displaying them in a tree-like layout.
3. Detailed Hardware Information: hwinfo
Hwinfo
is a great tool for delving more into your hardware—including disk information. It offers thorough information on many hardware parts. Use below command to install hwinfo
:
sudo apt install hwinfo # On Debian, Ubuntu, and Mint
sudo yum install hwinfo # On RHEL/CentOS/Fedora and Rocky Linux/AlmaLinux
Once installed, you can retrieve disk information with:
sudo hwinfo --disk
This command provides comprehensive information on every disk, therefore enabling you to properly manage hardware and troubleshoot.
4. Partition Management with parted
Partition management also benefits from another flexible tool: partitioned Its more user-friendly interface than fdisk
helps both MBR and GPT partitioning systems. To begin divided, employ:
sudo parted /dev/sdX
Replace /dev/sdX
with the actual disk identifier. From now on, you may create and resize partitions among other things:
mkpart primary ext4 1MiB 100%
This command creates a new primary partition with the ext4 file system spanning the entire disk.
5. LVM, or Logical Volume Management
It’s possible to handle hard storage in a lot of different ways with LVM, which goes beyond what standard splitting can do. This is a step-by-step guide on how to use LVM:
Create Physical Volumes (PVs):
sudo pvcreate /dev/sdX1
eplace /dev/sdX1
with the appropriate partition.
Create a Volume Group (VG):
sudo vgcreate my_vg /dev/sdX1
my_vg
is the name of the volume group.
Create Logical Volumes (LVs):
sudo lvcreate -n my_lv -L 10G my_vg
This creates a logical volume named my_lv
with a size of 10GB.
Format the Logical Volume:
sudo mkfs.ext4 /dev/my_vg/my_lv
Mount the Logical Volume:
sudo mount /dev/my_vg/my_lv /mnt
Ensure the mount point /mnt
exists before mounting.
6. Monitoring Disk Usage: df and du
For monitoring disk usage, df
and du
are essential tools:
df: Displays the amount of disk space used and available on filesystems.
df -h
The -h
option makes the output human-readable.
du: Estimates file space usage.
du -sh /path/to/directory
The -s
option summarizes the total usage, and -h
makes it human-readable.
In summary
Gaining proficiency with these Linux disk management commands will enable you to effectively control the storage on your system. These programs provide the functionality required to keep a system tidy and healthy, whether you’re using parted to manage partitions, fdisk to list disks, or LVM for its versatility. By using programs like df and du on a regular basis, you can keep aware of how much disk space you’re using and maybe avoid storage-related problems before they happen. Start using these commands now to improve your knowledge of Linux disk administration.
FAQs
Q: How do I check free disk space on Linux?
A: Use the df -h
command to see a summary of available and used disk space.
Q: How can I resize a partition without losing data?
A: Tools like gparted
(GUI) or parted
(command-line) can resize partitions safely, but always back up your data first.
Q: What’s the difference between fdisk
and parted
?
A: fdisk
is simpler and works well with MBR, while parted
supports GPT and is better for more complex partitioning tasks.