Master Linux Disk Management: Devices, Partitions, RAID & LVM
This guide explains Linux disk management fundamentals, covering device files, disk types, RAID levels, partitioning methods, filesystem choices, mounting techniques, useful command‑line tools, real‑world case studies, and step‑by‑step LVM creation and expansion.
Disk Devices and External Structure
In Linux every hardware component appears as a file under /dev. Example device nodes are /dev/sda (first disk), /dev/sda1 (first partition), and /dev/zero. The major number identifies the driver type; the minor number distinguishes individual devices of that type.
Typical storage categories:
SSD – solid‑state, similar to USB flash.
HDD – rotating platters, motor‑driven.
NVMe – PCI‑Express interface, highest performance.
Form factors: 3.5" for desktops, 2.5" for laptops/servers. Interfaces range from legacy IDE/SCSI (deprecated) to SATA (desktop/laptop) and SAS (enterprise).
RAID Overview
RAID aggregates multiple disks into a single logical unit to improve capacity, performance, or reliability.
RAID 0 – striping, maximum speed, no redundancy.
RAID 1 – mirroring, one‑disk failure tolerance.
RAID 5 – block‑level striping with distributed parity; usable capacity = (N‑1) × disk size.
RAID 10 – striped mirrors, balances performance and safety.
Disk Partitioning
Linux identifies disks as sda, sdb, … and partitions as sda1, sda2, etc. Two partition table formats are used:
MBR – up to 4 primary partitions (or 3 primary + 1 extended with many logical partitions). Suitable for disks ≤ 2 TB.
GPT – up to 128 primary partitions, required for disks > 2 TB.
Partitioning Workflow
Insert the new disk.
Rescan the SCSI bus if the kernel does not detect it: echo '- - -' > /sys/class/scsi_host/host0/scan Choose the appropriate tool:
For MBR (≤ 2 TB) use fdisk /dev/sdX or cfdisk.
For GPT (> 2 TB) use parted /dev/sdX or gdisk /dev/sdX.
Create partitions, specifying type (primary, extended, logical) and size. Example with fdisk:
# fdisk /dev/sdb
n # new partition
p # primary
1 # partition number
2048
+5G # size 5 GiB
w # write tableAfter editing, refresh the kernel table if lsblk does not show the new layout:
partprobe /dev/sdbNon‑Interactive Partition Creation
echo -e 'p
n
+1G
w
' | fdisk /dev/sdbUsing parted
(parted) mklabel gpt
(parted) mkpart primary ext4 0% 500GB
(parted) printFilesystem Basics
A filesystem defines how files are stored on a block device. Linux supports many filesystems; the ones most often used are:
ext2 – simple, no journaling, suitable for small, rarely‑changed partitions (e.g., /boot).
ext3 – ext2 with journaling.
ext4 – modern, supports files up to 16 TB, timestamps with nanosecond precision, and improved performance.
xfs – high‑performance, scales to exabytes.
swap – dedicated swap area.
Supported filesystems can be inspected via:
ls /lib/modules/$(uname -r)/kernel/fs # kernel‑provided modules
cat /proc/filesystems # currently usable filesystemsMounting and Persistent Mounts
Mount a filesystem with the mount command. The source can be a device node, label, UUID, or pseudo‑filesystem name.
# Read‑only mount example
mount --source /dev/sdb1 -o ro /mnt/readonlyMount points must exist and be empty directories. A device may be mounted at multiple points, but a single mount point can host only one filesystem at a time.
To mount filesystems automatically at boot, add entries to /etc/fstab. Each line contains six fields:
# device mountpoint fstype options dump fsck
/dev/sdb1 /mnt/xfs xfs defaults 0 0Common Disk Utilities
df
Shows filesystem usage.
# Human‑readable, show type, total summary
df -hT --totaldu
Displays directory size.
# Summarize a directory in human‑readable form
du -sh /etcdd
Low‑level copy utility. Useful for backing up the MBR or cloning a whole disk.
# Backup only the first 512 bytes (MBR)
dd if=/dev/sdb of=./sdb-mbr.img bs=512 count=1
# Clone an entire disk
dd if=/dev/sdx of=/path/to/image bs=4M status=progressSwap Management
Allocate swap space equal to 1–1.5 × RAM (capped at 8 GB for large systems). Create a swap file, format it, enable it, and add it to /etc/fstab for persistence.
# Create a 2 GB swap file
dd if=/dev/zero of=/swapfile bs=1G count=2
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
# Verify
swapon -s
# Persist
echo '/swapfile none swap sw 0 0' >> /etc/fstabTypical Disk Issues and Remedies
Disk full : Find large files. find / -type f -size +1G -exec ls -lh {} \; Inode exhaustion : Locate directories with many small files.
find / -xdev -type d -printf '%h %i
' | sort -k2n | tailDeleted file still consuming space : Identify the holding process.
lsof | grep '(deleted)'
# Then terminate or restart the processLogical Volume Management (LVM)
Concept
LVM adds an abstraction layer consisting of Physical Volumes (PVs), Volume Groups (VGs), and Logical Volumes (LVs). This allows dynamic resizing and re‑allocation of storage.
Creating Physical Volumes, Volume Groups, and Logical Volumes
# Mark partitions as physical volumes
pvcreate /dev/sdb1 /dev/sdb2 /dev/sdb3
# Create a volume group named vg1 using two PVs
vgcreate vg1 /dev/sdb1 /dev/sdb2
# Create logical volumes
lvcreate -L 5G -n lv1 vg1 # size‑based
lvcreate -l 500 -n lv2 vg1 # extent‑basedFormat and mount the new LVs:
# ext4 example
mkfs.ext4 /dev/vg1/lv1
mount /dev/vg1/lv1 /mnt/lv1
# xfs example
mkfs.xfs /dev/vg1/lv2
mount /dev/vg1/lv2 /mnt/lv2Extending Logical Volumes
First ensure the VG has free space; if not, extend the VG with an additional PV.
# Add a new physical volume to the VG
vgextend vg1 /dev/sdb3
# Grow the logical volume
lvextend -L 7G /dev/vg1/lv1
# Resize the filesystem (ext* family)
resize2fs /dev/vg1/lv1
# For XFS use xfs_growfs
xfs_growfs /dev/vg1/lv2After resizing, verify with df -h.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
