Master Linux Disk Partitioning: From lsblk to LVM (Part 10)
This step‑by‑step guide walks through Linux disk management—from inspecting devices with lsblk, creating MBR or GPT partitions with fdisk and parted, formatting with ext4 or xfs, mounting, monitoring usage with df and du, using dd for cloning, to flexible LVM volumes and persistent fstab entries—plus practical tips and common pitfalls.
1. lsblk – Inspect Disks
Before any operation, run lsblk to list all block devices, their sizes, types and mount points. Example output shows a 500 GB sda with a boot partition and an LVM group, and an empty 1 TB sdb. Useful flags: lsblk -f (filesystems), lsblk -l (list view), and lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINT for custom columns.
2. fdisk – Classic MBR Partitioning
fdiskworks on virtually every Linux system and supports MBR tables (max 2 TB, up to four primary partitions). After fdisk /dev/sdb you enter an interactive prompt where m shows help, p prints the table, n creates a partition, d deletes, t changes type, w writes changes (only w actually writes to disk), and q quits without saving.
Example: create a 500 GB primary partition on a new /dev/sdb, then run partprobe /dev/sdb so the kernel rereads the table.
3. parted – GPT for Large Disks
For disks larger than 2 TB, use GPT with parted. Basic interactive usage:
parted /dev/sdc
(parted) mklabel gpt # create GPT label
(parted) mkpart primary ext4 0% 100% # one partition filling the disk
(parted) print
(parted) quitNon‑interactive (script‑friendly) form:
parted /dev/sdc mklabel gpt --script
parted /dev/sdc mkpart primary ext4 0% 100% --scriptTip: even for <2 TB disks you can use parted + GPT to avoid later migration.
4. Formatting – ext4 vs xfs
After partitioning, format the partition with a filesystem. Common commands: mkfs.ext4 /dev/sdb1 (stable, good for small files) mkfs.xfs /dev/sdb1 (high performance for large files, recommended by Oracle and Red Hat).
Guideline: use ext4 for general purpose, xfs for big‑data or database workloads. Verify the filesystem UUID with blkid /dev/sdb1.
5. mount/umount – Attach Filesystems
Mount a formatted partition:
mkdir /data
mount /dev/sdb1 /dataCommon mount options (passed with -o): noatime, nodiratime, ro, rw, defaults. Unmount with umount /data (note the spelling). If the device is busy, identify processes with lsof /data or force release with fuser -km /data.
6. df – Check Free Space
Use df -h to display human‑readable disk usage. To find partitions over 90 % used, pipe through:
df -h | grep -E "(9[0-9]%|100%)"7. du – Directory Usage
du -sh .shows the total size of the current directory (e.g., 2.3G .). To locate the largest sub‑directories: du -h --max-depth=1 /var | sort -hr | head -10 Note the difference: du reports actual disk blocks used, while ls -lh shows logical file size.
8. dd – Low‑level Copying
Syntax: dd if=INPUT of=OUTPUT bs=BLOCK_SIZE count=COUNT. Common uses:
Backup a partition:
dd if=/dev/sdb1 of=/backup/sdb1_backup.img bs=4M status=progressCreate a bootable USB:
dd if=ubuntu-22.04.iso of=/dev/sdc bs=4M status=progress && syncWipe a disk: dd if=/dev/zero of=/dev/sdb bs=4M status=progress Warning: dd does not ask for confirmation; mixing up if and of can permanently erase a system disk.
9. LVM – Flexible Volume Management
LVM abstracts physical volumes (PV) into volume groups (VG) and logical volumes (LV), allowing online resizing. Core concepts:
PV – actual disk partitions
VG – pool of PVs
LV – allocatable space, similar to a traditional partition
Example creation:
# 1. pvcreate /dev/sdb1 /dev/sdc1
# 2. vgcreate vg_data /dev/sdb1 /dev/sdc1
# 3. lvcreate -L 500G -n lv_data vg_data
# 4. mkfs.ext4 /dev/vg_data/lv_data
mkdir /data
mount /dev/vg_data/lv_data /dataTo extend when /data fills up:
# lvextend -L +100G /dev/vg_data/lv_data
# resize2fs /dev/vg_data/lv_data # for ext4
# xfs_growfs /data # for xfsAdditional PVs can be added with pvcreate /dev/sdd1 and vgextend vg_data /dev/sdd1. LVM adds flexibility but introduces an extra abstraction layer and cannot be used for /boot (GRUB cannot read LVM).
10. /etc/fstab – Persistent Mounts
Temporary mounts disappear after reboot; to make them permanent, add entries to /etc/fstab:
<device> <mountpoint> <fstype> <options> <dump> <fsck>Typical line using UUID: UUID=a1b2c3d4-... /data ext4 defaults,noatime 0 2 After editing, verify with mount -a. A malformed fstab can prevent the system from booting, as illustrated by a real‑world case where an extra space broke the boot process.
Summary
Key workflow for a new server: run lsblk to discover disks, use fdisk for ≤2 TB or parted for >2 TB, format with ext4 (general) or xfs (large files), mount and record the mount in /etc/fstab, verify with mount -a, and employ LVM when frequent resizing is needed. Handle dd with extreme care to avoid catastrophic data loss.
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.
AI Agent Super App
AI agent applications, installation, large-model testing, computer fundamentals, IT operations and maintenance exchange, network technology exchange, Linux learning
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.
