Master Linux Disk Management: From Devices to RAID, Partitions, and LVM
Learn the fundamentals of Linux disk management, including device files, hardware types, partitioning schemes, RAID levels, filesystem creation, mounting techniques, persistent fstab configuration, and logical volume management, with practical command examples and real‑world case studies for effective storage administration.
Disk Management
Linux follows the philosophy that everything is a file, including hardware devices which appear as device files.
# ll /dev/sda*
brw-rw---- 1 root disk 8, 0 Nov 20 04:11 /dev/sda
brw-rw---- 1 root disk 8, 1 Nov 20 04:11 /dev/sda1
brw-rw---- 1 root disk 8, 2 Nov 20 04:11 /dev/sda2
# ll /dev/zero
crw-rw-rw- 1 root root 1, 5 Nov 20 04:11 /dev/zeroMajor number: identifies the device type. Minor number: identifies the specific device within that type.
1. External Disk Structure
Disk classifications:
Solid‑state drives (SSD): internally similar to a motherboard and USB flash drive.
Mechanical drives (HDD): contain platters, a spindle, and a moving arm, similar to a DVD.
NVMe drives.
PCI‑E interface.
Size categories:
3.5" – desktop PCs.
2.5" – servers and laptops.
Interface types:
IDE – obsolete.
SCSI – obsolete.
SATA – common for desktops and laptops.
SAS – standard for enterprise servers.
SSD advantages: higher speed, higher price, lower capacity, limited lifespan.
HDD advantages: lower price, larger capacity, long‑lasting.
Speed is not solely determined by interface; NVMe protocol provides the fastest performance.
2. RAID Arrays
Purpose:
- Larger capacity # combine multiple disks into one logical disk
- Higher performance # writing to two disks is faster than one
- Better reliability # data can be mirrored for backupTypical interview/quiz question – RAID levels:
RAID 0: at least one disk, total capacity = sum of disks, no redundancy, fastest read/write, used when speed is critical (e.g., database replica).
RAID 1: exactly two disks, usable capacity = half, can survive one disk failure, slower writes, used for system disks where safety matters.
RAID 5: minimum three disks, usable capacity = n‑1 disks, tolerates one failure, balances speed and safety, suitable for stable workloads.
RAID 10: at least four disks (even number), usable capacity = half, tolerates one‑half disk failures, high read/write speed, ideal for high‑concurrency scenarios.
3. Disk Partitioning
Windows defaults to MBR (max 4 primary partitions). Linux disk naming example:
sda # first disk
sda1 # first partition on sda
sda2 # second partition on sda
sdb # second disk
sdb1 # first partition on sdb
sdb5 # first logical partition on sdb3.1 Linux Partition Schemes
1. System partition (standard):
/boot 200M # kernel and bootloader
/ remaining space # root filesystem
2. Swap partition:
/boot 200M
swap 2G # temporary disk‑backed memory
/ remaining space
3. Mixed example:
/boot 200M
swap 2G
/ 50G # system
/data 1.8T # data3.2 Partition Types
MBR supports up to 4 primary partitions or 3 primary + 1 extended with many logical partitions.
GPT supports up to 128 primary partitions.
3.3 Partitioning Steps
1. For disks < 2 TiB use fdisk (MBR); for larger disks use gdisk/parted (GPT).
2. Insert the new disk (e.g., 20 GiB SCSI).
3. Rescan SCSI bus:
for i in $(ls /sys/class/scsi_host/); do echo '- - -' > /sys/class/scsi_host/${i}/scan; done
4. Create partitions with fdisk:
fdisk /dev/sdb
(use commands n, p/e, w, etc.)
5. Format partitions (e.g., mkfs.xfs /dev/sdb1).
6. Create mount point and mount:
mkdir /mnt/xfs
mount /dev/sdb1 /mnt/xfs
7. Add entry to /etc/fstab for persistent mounting.Non‑interactive fdisk example: echo -e 'p\nn\n\n+1G\np\n' | fdisk /dev/sdb Parted commands (interactive):
mklabel gpt # set GPT partition table
mkpart primary xfs 0% 500G # create 500 GiB XFS partition
print # view layout
quit # exit4. Filesystems
4.1 What Is a Filesystem?
A filesystem defines how data is organized and accessed on a storage device, providing structures for creating, reading, writing, modifying, and protecting files.
4.2 Common Linux Filesystems
ext2 – simple, suitable for small, rarely‑changed partitions (e.g., /boot).
ext3 – ext2 with journaling.
ext4 – modern, supports large files (up to 1 EiB) and improved performance.
xfs – high‑performance, supports up to 8 EiB.
swap – dedicated swap area.
iso9660 – CD/DVD image.
4.3 Creating Filesystems
# mkfs.ext4 /dev/sdb1
# mkfs.xfs /dev/sdb2
# blkid /dev/sdb1 # shows UUID and type5. Mounting Disks
Mount command syntax:
mount [options] [--source] <source> <target>
mount -a # mount all entries in /etc/fstabKey options:
Device file (e.g., /dev/sda5).
Label (‑L).
UUID (‑U).
Pseudo‑filesystems (proc, sysfs, devtmpfs, configfs).
Mount rules:
One mount point can host only one device at a time.
A device can be mounted at multiple mount points.
Mount points should exist and preferably be empty directories.
6. Persistent Mounts (fstab)
/dev/sdb1 /mnt/xfs xfs defaults 0 07. Common Disk Tools
7.1 df
Shows filesystem usage.
df -hT # human‑readable with type
df -t ext4 # filter by ext4
df -lTh --total # local filesystems with total line7.2 du
Shows directory size.
du -sh /etc # summary of /etc
du -sh /etc /var/log --total7.3 dd
Low‑level copy/backup utility.
# Backup MBR (first 512 bytes)
dd if=/dev/sdb of=./sdb.img bs=512 count=1
# Backup entire disk
dd if=/dev/sdx of=/path/to/image8. Real‑World Cases
Case 1 – Swap Exhaustion
When Java runs out of memory, increase swap (size ≈ 1‑1.5 × RAM, max 8 GiB). Create swap file:
dd if=/dev/zero of=/1g bs=1G count=1
mkswap /1g
swapon /1gCase 2 – Disk Full
Find large files (>1 GiB): find / -type f -size +1G Or create a test file to fill space:
dd if=/dev/zero of=/opt/2g bs=1M count=2000Case 3 – Log File Growth
Move a large log file to a new larger disk and create a symlink:
# mount /dev/sdc3 /data
# mv /var/log/10g /data/
# ln -s /data/10g /var/log/10gCase 4 – Deleted File Still Occupying Space
Identify the holding process:
lsof | grep 10g # shows process using deleted file
kill -9 <pid>9. Logical Volume Management (LVM)
9.1 What Is LVM?
LVM provides an abstraction layer over physical volumes, allowing flexible resizing, aggregation, and management of storage.
9.2 Creating Logical Volumes
# Create physical volumes
pvcreate /dev/sdb1 /dev/sdb2 /dev/sdb3
# Create volume group
vgcreate vg1 /dev/sdb1 /dev/sdb2
# Create logical volumes
lvcreate -L 5G -n lv1 vg1
lvcreate -l 500 -n lv2 vg1
# Format and mount
mkfs.ext4 /dev/vg1/lv1
mount /dev/vg1/lv1 /lv19.3 Extending LVM
Extend the volume group with an additional physical volume:
vgextend vg1 /dev/sdb3
lvextend -L 7G /dev/vg1/lv1
resize2fs /dev/vg1/lv1 # for ext* filesystemsFor XFS filesystems use xfs_growfs after extending the LV.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
