Hands‑On Linux Disk Management: Partitioning, Formatting, and Mounting
This guide walks through Linux disk management fundamentals, covering how to partition disks with fdisk or gdisk, create filesystems using mkfs, mount and unmount devices, configure automatic mounts via /etc/fstab, and handle special cases such as ISO images and Windows shares.
Basic Concepts
Linux stores all devices under /dev, so to use a disk you must partition it, format the partitions with a filesystem, and mount the filesystem to a directory.
(1) Partitioning with fdisk
For disks ≤2 TiB you can use fdisk (MBR). The workflow is:
sudo apt-get -y install fdisk # Ubuntu
sudo yum -y install fdisk # CentOS
fdisk -l # list disks
fdisk /dev/sdc # start partitioning
# Commands inside fdisk:
# d – delete a partition
# n – create a new partition (choose p for primary, size +2G, etc.)
# t – change partition type (e.g., 05 for FAT12)
# w – write changes
# q – quit without savingExample: create a 2 GiB primary partition on /dev/sdc:
fdisk /dev/sdc
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
Select (default p): p
Partition number (1‑4, default 1): 1
First sector (2048‑41943039, default 2048): 2048
Last sector, +sectors or +size{K,M,G,T,P} (2048‑41943039, default 41943039): +2G
Created a new partition 1 of type "Linux" and size 2 GiB.(2) Partitioning with gdisk (GPT)
For disks >2 TiB or when you prefer GPT, use gdisk which also works on MBR disks.
sudo apt-get -y install gdisk # Ubuntu
sudo yum -y install gdisk # CentOS
gdisk /dev/sdf # start GPT partitioning
# Inside gdisk:
# n – add a partition (choose number, start sector, +1G size, type 8300)
# t – change type, l – list types (8200 swap, 8300 Linux, 8e00 LVM)
# w – write tableExample: add a 1 GiB Linux filesystem partition:
gdisk /dev/sdf
Command (? for help): n
Partition number (1‑128, default 1): 1
First sector (34‑8589934558, default = 2048): 2048
Last sector (2048‑8589934558, default = 8589932543): +1G
Current type is 8300 (Linux filesystem)
Changed type of partition to 'Linux filesystem'
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!!
Do you want to proceed? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/sdf.
The operation has completed successfully.(3) Formatting Partitions
Formatting creates a filesystem on a partition. Common Linux filesystems are ext2/3/4 and XFS.
# List supported mkfs commands
mkfs -t ext4 /dev/vdb1 # create ext4
mkfs.ext4 /dev/vdb1 # preferred shortcut
mkfs -t xfs /dev/vdb1 # XFS exampleExample creating an ext3 filesystem with a label and custom block size:
mkfs.ext2 -b 2k -L demoTest -j /dev/vdb1
# Output (truncated)
mke2fs 1.46.5 (30-Dec-2021)
/dev/vdb1 has an ext3 filesystem
Created 1048576 blocks (2 k) and 131072 inodes
Filesystem UUID: a94d46ba-4f33-4ab3-9cd4-cfee31e78367(4) Mounting Filesystems
Mount attaches a filesystem to a directory (mount point). The mount point should be an empty directory.
# Create mount point
mkdir /mnt/game
# Mount read‑only with sync and noatime options
mount -vrt ext2 -o sync,noatime /dev/vdb1 /mnt/game
# Verify
df -h | grep /mnt/game
# Try to write (should fail because of read‑only)
touch /mnt/game/abc.txt
# Output: touch: cannot touch '/mnt/game/abc.txt': Read‑only file systemMount by label or UUID:
# Find label/UUID
blkid /dev/vdb2
# Mount using label
mount -v -L shebeiB /mnt/videos
# Mount using UUID
mount -v -U eaab835f-073a-4b98-ba44-68c8e49228e2 /mnt/videos(5) Unmounting
# Simple unmount
umount /mnt/game
# Force unmount if busy
fuser -cu /mnt/game # list processes
fuser -k /mnt/game # kill them
umount -f /dev/vdb1(6) Automatic Mounting with /etc/fstab
The file /etc/fstab defines devices to mount at boot.
# Example entries
/dev/vdb1 /mnt/game ext2 auto,ro 0 0
LABEL=shebeiB /mnt/videos ext3 auto,rw 0 0
UUID=a14f72f0-d450-473a-aaa2-4f2b811b0500 /mnt/music ext4 noauto,rw 0 0After editing, run mount -a to apply.
(7) Special Device Mounts
ISO Image
mkdir /mnt/guazai1
mount -vo loop /path/to/image.iso /mnt/guazai1
# Verify
df -h | grep /mnt/guazai1
umount -f /dev/loop12Windows Share (CIFS)
mkdir /mnt/guazai2
mount -t cifs -o username=JavaScript,password=54088 //192.168.0.144/images /mnt/guazai2
# Verify
df -h | grep /mnt/guazai2
umount //192.168.0.144/imagesConclusion
By mastering partitioning tools ( fdisk, gdisk), filesystem creation ( mkfs, mke2fs), mounting commands, and /etc/fstab configuration, you can reliably manage storage on Linux systems, including handling large disks, special devices, and network shares.
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.
Linux Tech Enthusiast
Focused on sharing practical Linux technology content, covering Linux fundamentals, applications, tools, as well as databases, operating systems, network security, and other technical knowledge.
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.
