Master Linux Disk Management: Partition, Format, and Mount Like a Pro
This comprehensive guide explains Linux disk management fundamentals, covering partitioning with fdisk and gdisk, formatting with mkfs, mounting and unmounting filesystems, using tools like lsblk, blkid, and part‑ed, and configuring automatic mounts via /etc/fstab.
Basic Introduction
Disk management is essential in Linux; devices appear under /dev, so you must partition, format, and mount them to use storage efficiently.
Understanding disks and filesystems before practical work speeds up the process.
fdisk Partition Tool
Use fdisk for MBR partitions (disks ≤2 TB). Install with sudo apt-get -y install fdisk (Ubuntu) or sudo yum -y install fdisk (CentOS).
# Install fdisk
sudo apt-get -y install fdisk # Ubuntu
sudo yum -y install fdisk # CentOSBasic commands:
fdisk -h # help
fdisk -l # list disks and partitions
fdisk /dev/sdb # start interactive sessionExample: create a 2 GB primary partition on /dev/sdc:
fdisk /dev/sdc
n # new partition
p # primary
1 # partition number
2048 # first sector (default)
+2G # last sector (+size)
w # write changesgdisk Partition Tool
Use gdisk for GPT partitions (required for disks >2 TB) and also supports MBR.
# Install gdisk
sudo apt-get -y install gdisk # Ubuntu
sudo yum -y install gdisk # CentOSBasic commands:
gdisk /dev/sdf # start session
b # backup GPT to file
n # new partition
w # write GPTObserving Disk Partition State
1: lsblk Command
Lists block devices and their hierarchy.
lsblk -f # show filesystems and UUIDs
lsblk -d # show only disks2: blkid Command
Displays UUID, LABEL, and type of a device.
blkid /dev/sdb13: parted Command
Shows partition table type and details.
parted /dev/sdb1 printFormatting Filesystems
After partitioning, create a filesystem with mkfs (or specific variants like mkfs.ext4).
# List supported filesystems
mkfs -t ext4 /dev/vdb1
mkfs.ext4 /dev/vdb1 # recommendedCommon options: -L set volume label -b block size -m reserve percentage
Mounting Filesystems
Mount a device to an empty directory:
mkdir /mnt/game
mount -v /dev/vdb1 /mnt/gameMount with options (read‑only, sync, noatime):
mount -vrt ext2 -o sync,noatime /dev/vdb1 /mnt/gameMount by LABEL or UUID:
mount -v -L shebeiB /mnt/videos
mount -v -U eaab835f-073a-4b98-ba44-68c8e49228e2 /mnt/videosUnmounting Devices
umount /dev/vdb1
umount /mnt/gameIf the target is busy, find processes with fuser -cu /mnt/game and kill them.
Automatic Mounting with /etc/fstab
Add entries to /etc/fstab to mount at boot. Format:
<device|LABEL|UUID> <mount_point> <fs_type> <options> <dump> <pass>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 0Apply changes with mount -a.
Special Mounts
ISO Image Mount
mount -vo loop /path/to/image.iso /mnt/isoWindows Share (CIFS) Mount
mount -t cifs -o username=JavaScript,password=54088 //192.168.0.144/images /mnt/guazai2Signed-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 Cloud Computing Practice
Welcome to Linux Cloud Computing Practice. We offer high-quality articles on Linux, cloud computing, DevOps, networking and related topics. Dive in and start your Linux cloud computing journey!
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.
