Page Content

Tutorials

Basic Disk Management Commands In Linux With Examples

Disk and Storage Management in Linux

Disk and storage management in Linux refers to how the operating system detects, organizes, uses, and maintains storage devices such as hard disks, SSDs, USB drives, and virtual disks. It is one of the most important system administration skills because everything in Linux files, programs, users, logs depends on proper storage handling.

Linux Disk and Storage Management, Disk and Partition, Disk Management Commands in Linux, Partitioning Tools, File System Creation, Swap Space, Logical Volume Manager (LVM), Real-World Example, Linux Disk Management Commands – Cheat Sheet, and Interview Questions were all covered in this blog.

Disk and Partition

What is a Disk?

A disk is a type of storage device, either virtual or actual.

For instance:

  • Hard Disk Drive (HDD)
  • Solid State Drive (SSD)
  • USB drive
  • Virtual disk (in VMware/VirtualBox)

In Linux, disks appear as:

  • /dev/sda, /dev/sdb, /dev/nvme0n1

What is a Partition?

A partition is a logical division of a disk.

For instance, a 1TB drive can be divided into:

  • 300GB for OS
  • 500GB for data
  • 200GB for backup

Linux names partitions like:

  • /dev/sda2
  • /dev/sda1

Also read about Linux File System Structure Explained: Root And Directories

Disk management commands in linux

Disk management commands in linux
Disk management commands in linux

df (Disk Free)

Shows how much space is used and available.

bash

df -h

Output shows:

  • Total size
  • Used space
  • Available space
  • Mount points

du (Disk Usage)

Shows size of files and folders.

bash

du -sh /home

Tells how much space /home uses.

lsblk (List Block Devices)

Shows all disks and partitions in tree format.

bash

lsblk

Very useful to visualize storage layout.

mount

Attaches a disk to a directory.

bash

mount /dev/sdb1 /mnt

Now /mnt shows the content of /dev/sdb1.

umount

Detaches a disk.

bash

umount /mnt

Also read about Process Management In Linux Commands With Examples

Partitioning Tools

fdisk (Classic Tool)

Used for creating and deleting partitions.

bash

fdisk /dev/sda

Inside fdisk:

  • n → new partition
  • d → delete
  • w → write changes

parted (Modern Tool)

Supports large disks and GPT.

bash

parted /dev/sda

More powerful than fdisk.

File System Creation

After partitioning, you must format the partition.

mkfs (Make File System)

bash

mkfs.ext4 /dev/sda1

Creates EXT4 filesystem.

Common file systems:

  • ext4 → default Linux
  • xfs → servers
  • btrfs → snapshots
  • vfat → USB drives

Swap Space

Swap is virtual memory on disk used when RAM is full.

Why swap exists?

  • Prevent system crash
  • Helps low-memory systems
  • Used for hibernation

Create swap file:

bash

fallocate -l 2G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

Check swap:

bash

free -h

Logical Volume Manager (LVM)

Flexible disk management is made possible with LVM.

You could:

  • Resize partitions live
  • Combine multiple disks
  • Create snapshots
  • Add storage without reinstalling OS

LVM Structure

mathematica

Disk → PV → VG → LV → File System

Physical Volume (PV)

Actual disk or partition.

Create:

bash

pvcreate /dev/sdb

Volume Group (VG)

Group of PVs.

Create:

bash

vgcreate myvg /dev/sdb

Logical Volume (LV)

Virtual partition inside VG.

Create:

bash

lvcreate -L 10G -n mylv myvg

Format and Mount LVM

bash

mkfs.ext4 /dev/myvg/mylv
mount /dev/myvg/mylv /data

Also read about Kill Process Linux: Commands, Signals And Real Examples

Real-World Example

You add a new 500GB disk.

Steps:

  1. Detect disk
bash

lsblk
  1. Create PV
bash

pvcreate /dev/sdb
  1. Add to VG
bash

vgextend myvg /dev/sdb
  1. Extend LV
bash

lvextend -L +500G /dev/myvg/mylv
  1. Resize filesystem
bash

resize2fs /dev/myvg/mylv

No reboot needed.

Linux Disk Management Commands – Cheat Sheet

These commands help you inspect disks, manage partitions, format storage, mount devices, and monitor disk usage.

Disk Information Commands

These commands show available disks and their details.

CommandPurpose
lsblkList all disks and partitions
lsblk -fShow file systems and UUIDs
blkidDisplay disk UUID and type
fdisk -lShow partition tables
mountShow mounted devices
findmntShow mount points

Example:

bash

lsblk

Disk Usage Commands

These commands show how much space is used.

CommandPurpose
df -hDisk free space (human readable)
du -sh folderSize of a directory
du -ahAll files and folders
ncduInteractive disk usage viewer

Example:

bash

df -h

Partition Management Commands

Used to create, delete, or modify partitions.

CommandPurpose
fdisk /dev/sdaPartition disk (MBR)
cfdisk /dev/sdaGUI partition tool
parted /dev/sdaGPT partitions
sfdiskScript-based partitioning

Example:

bash

fdisk /dev/sdb

File System Commands

Used to format and repair disks.

CommandPurpose
mkfs.ext4 /dev/sda1Create ext4 file system
mkfs.xfs /dev/sda1Create XFS
fsck /dev/sda1Check file system
tune2fsModify ext file systems

Example:

bash

mkfs.ext4 /dev/sdb1

Also read about How To Install Garuda Linux On Virtualbox Easy Setup Guide

Mounting & Unmounting

Attach or detach disks.

CommandPurpose
mount /dev/sdb1 /mntMount disk
umount /mntUnmount
mount -o roRead-only mount
mount -aMount all from fstab

Example:

bash

mount /dev/sdb1 /mnt

Swap Space Management

Used for virtual memory.

CommandPurpose
swapon -sShow swap
mkswap /dev/sda2Create swap
swapon /dev/sda2Enable swap
swapoff /dev/sda2Disable swap

Example:

bash

swapon -s

LVM (Logical Volume Manager)

Advanced dynamic storage.

CommandPurpose
pvcreateCreate physical volume
vgcreateCreate volume group
lvcreateCreate logical volume
lvextendExpand volume
lvdisplayShow volumes

Example:

bash

lvcreate -L 10G -n mylv myvg

Disk Performance & Health

Check disk health and speed.

CommandPurpose
iostatDisk I/O stats
iotopDisk usage by process
smartctlDisk health
badblocksScan bad sectors
hdparmDisk speed

Example:

bash

smartctl -a /dev/sda

Also read about Explain File Permissions In Linux & Ownership With Examples

Backup & Cloning

Copy disks and data.

CommandPurpose
rsyncBackup files
ddClone disk
tarArchive
gzipCompress
borgBackup tool

Example:

bash

dd if=/dev/sda of=/dev/sdb

Emergency Recovery

Used when system fails.

CommandPurpose
mount -o remount,rw /Fix read-only root
fsck -yAuto repair
initramfsBoot recovery
chrootRepair broken system

Interview Questions

“How do you check disk usage in Linux?”

Answer:

bash

df -h

“How to find disk size?”

bash

lsblk

“How to mount a USB drive?”

bash

mount /dev/sdb1 /mnt

Interview Key Points

ConceptMeaning
dfShows free disk
duShows folder size
lsblkShows disk layout
mountAttach disk
umountDetach disk
fdiskPartition tool
mkfsFormat disk
swapVirtual RAM
PVPhysical disk
VGPool of disks
LVVirtual partition

Summary

Linux disk management commands allow you to view, create, format, mount, monitor, repair, and optimize storage devices, making Linux one of the most powerful operating systems for storage control.

Also read about Basic Linux Commands For Beginners With Easy Examples

Hemavathi
Hemavathihttps://govindhtech.com/
Myself Hemavathi graduated in 2018, working as Content writer at Govindtech Solutions. Passionate at Tech News & latest technologies. Desire to improve skills in Tech writing.
Index