Operations 40 min read

Master Linux Disk Management: Partition, Format, and Mount Like a Pro

This comprehensive guide explains Linux disk management fundamentals, covering how to partition disks with fdisk and gdisk, format them using mkfs, mount and unmount filesystems, configure automatic mounts via /etc/fstab, and handle special cases such as ISO images and Windows shares.

Open Source Linux
Open Source Linux
Open Source Linux
Master Linux Disk Management: Partition, Format, and Mount Like a Pro

In Linux, disk management is essential for partitioning, formatting, and mounting storage devices to fully utilize space and access data efficiently.

All devices appear under /dev; you must partition, format, and mount them to known directories before use.

1. Basic Introduction

Disk partitioning divides a physical disk into logical parts. Tools like fdisk and gdisk can create MBR or GPT partitions. Use MBR for disks under 2 TB, GPT for larger disks.

2. fdisk Partition Tool

Install fdisk:

sudo apt-get -y install fdisk   # Ubuntu
sudo yum -y install fdisk       # CentOS

Basic commands:

fdisk -l                     # List disks and partitions
fdisk /dev/sdb               # Open disk for editing
# Inside fdisk menu:
  d   # Delete partition
  n   # Add new partition
  p   # Print partition table
  w   # Write changes and exit

Example: create a 2 GB primary partition on /dev/sdc:

fdisk /dev/sdc
Command (? for help): n
Partition type: p
Partition number: 1
First sector: 2048
Last sector (+size): +2G
Command (? for help): w

3. gdisk Partition Tool

Install gdisk:

sudo apt-get -y install gdisk   # Ubuntu
sudo yum -y install gdisk       # CentOS

gdisk works with GPT (and MBR) disks. Common commands:

gdisk /dev/sdf
b   # Backup GPT data
n   # Add new partition
p   # Print partition table
w   # Write changes

Example: create a 1 GB partition on /dev/sdf:

gdisk /dev/sdf
Command (? for help): n
Partition number (1-128, default 1):
First sector (34-8589934558, default = 2048): 2048
Last sector (2048-8589934558, default = 8589932543) or +size{K,M,G,T,P}: +1G
Hex code or GUID (Enter = 8300 for Linux filesystem):
Command (? for help): w

4. Observing Partition State

lsblk

Lists block devices and partitions:

lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   20G  0 disk
├─sda1   8:1    0    1M  0 part
└─sda2   8:2    0   20G  0 part /

blkid

Shows UUID and filesystem type; useful for mounting by UUID.

blkid output example
blkid output example

parted

Displays partition table type and layout:

parted /dev/sdb1 print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number  Start   End     Size    Type     File system  Flags
 1      1049kB  5370MB  5369MB  primary  ext3
 2      5370MB  7517MB  2147MB  primary  ext3

5. Formatting Filesystems

Use mkfs (or specific variants) to create a filesystem on a partition. Example for ext4: mkfs.ext4 /dev/vdb1 Common options include -b (block size), -L (label), -j (add journal), -m (reserved block percentage), -U (set UUID).

6. Creating Filesystems with mkfs and mke2fs

mkfs

is generic; mkfs.ext2, mkfs.ext3, mkfs.ext4 are specific. mke2fs is the underlying implementation for ext2/3/4.

mkfs.ext2 -b 2k -L demoTest -j /dev/vdb1
# Result shows filesystem type, UUID, etc.

7. Adjusting Filesystem Parameters

tune2fs

modifies ext2/3/4 parameters (e.g., max mount count, check interval, add journal). Example:

tune2fs -c 15 /dev/sdb   # Set max mount count to 15
tune2fs -i 10d /dev/sdb  # Force check after 10 days
dumpe2fs

displays detailed filesystem information, such as block count, inode count, block size, etc.

8. Mounting Devices

Mount a filesystem with mount:

mount -vrt ext2 -o sync,noatime /dev/vdb1 /mnt/game

Check with df -h and verify read‑only with touch (should fail if ro).

Mount by LABEL or UUID

Using label: mount -v -L shebeiB /mnt/videos Using UUID:

mount -v -U eaab835f-073a-4b98-ba44-68c8e49228e2 /mnt/videos

9. Unmounting Devices

Unmount with umount (or umount -f if needed). Ensure the mount point is not busy:

umount /dev/vdb1
umount /mnt/game

10. Automatic Mounting with /etc/fstab

Configure /etc/fstab with six fields: device, mount point, filesystem 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  0

Apply with mount -a and verify with df -h.

11. Special Mounts

ISO Image

Mount an ISO file using the loop device: mount -vo loop /path/to/image.iso /mnt/guazai1 Unmount with umount -f /dev/loop12.

Windows Share (CIFS)

Mount a Windows SMB share:

mount -t cifs -o username=JavaScript,password=54088 //192.168.0.144/images /mnt/guazai2

Unmount with umount //192.168.0.144/images.

After mastering partitioning, formatting, and mounting, you can manage Linux storage effectively and automate it for reliable system operation.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxPartitioningdisk-managementMounting
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.