Master Linux Storage: Mount, Unmount, Auto‑Mount, Partition & Format Commands
This guide explains essential Linux storage commands—including fdisk, df, du, mount, umount—covers automatic mounting via /etc/fstab, details disk partitioning with fdisk, and demonstrates how to format partitions using mkfs, providing practical examples for each operation.
1. Mounting and Unmounting Storage Devices
Common commands for storage device management are fdisk -l, df, du, mount and umount.
fdisk -l
Purpose: List partition information for all disks, including unmounted partitions and USB devices. Useful for identifying device names before mounting.
Note: Since hardware appears as files in Linux, you can also use ls -l /dev/sda* to view the first disk's partitions.
df
Purpose: Show disk space usage and file‑system statistics, defaulting to kilobytes.
Syntax: df [option] Key options:
-a or --all: display all file systems
-h or --human‑readable: show sizes in a readable format
-T or --print‑type: display the file‑system type
Example:
#df -adu
Purpose: Report disk usage of files or directories. Without arguments it shows the size of the current directory and its subdirectories; multiple paths can be listed separated by spaces.
Syntax: du [option] <em>path</em> Key options:
-a or --all: display size of each file
-h or --human‑readable: use K, M, G units
-S or --separate‑dirs: show only the total for each specified directory (uppercase S)
Examples:
#du -h -S ahao
#du -h haha1 haha2
mount
Purpose: Without arguments, list all mounted file systems; with arguments, attach a storage device to a directory, making the directory act as the device's access point.
Note: Files that existed in a mount point become hidden after mounting.
Syntax: mount [option] <em>device</em> <em>mount_point</em> Key option: -t<fs_type> (e.g., vfat for FAT32, iso9660 for CD images, auto for automatic detection).
Examples:
#mount -t auto /dev/sda5 /ahao
#mount -t auto /dev/sdb1 /ahao
#mount -t iso9660 xxx.iso /peter -o loop
umount
Purpose: Unmount a mounted file system. It is recommended to use the mount point for clarity, especially when a device has multiple mount points.
Syntax: umount <em>mount_point</em> (recommended) umount <em>device</em> Example:
#umount /ahao2. Automatic Mounting
Automatic mounting at boot is configured via the /etc/fstab file, which can be edited with vi or a graphical editor such as gedit.
/etc/fstab fields
1st column: device name (e.g., /dev/sda1), label, or UUID
2nd column: mount point
3rd column: file‑system type
4th column: mount options (usually defaults)
5th column: dump flag (1 = dump, 0 = no dump)
6th column: fsck order (1 = check, 0 = skip)
Example entry for auto‑mounting a USB drive to /usb without backup or fsck:
/dev/sdb1 /usb auto defaults 0 0
After editing, run mount -a to verify the configuration.
3. Disk Partitioning
When using fdisk in Linux, common options include d, l, m, n, p, q, t, w, etc.
Notes:
Primary and extended partitions are numbered 1‑4; logical partitions start at 5.
If an extended partition exists, only logical partitions can be added.
fdisk command
Purpose: Interactively create, delete, and modify disk partitions.
Usage: fdisk <em>device</em> then enter options such as: m: list help p: display current partition table n: create a new partition l: list known partition types d: delete a partition t: change partition type w: write changes and exit q: quit without saving
Typical workflow:
Use p to view the current table.
Use d to delete unwanted partitions.
Use n to add new partitions, choosing type (p for primary, e for extended, l for logical), number, start and end sectors.
Verify with p again.
Save with w or discard with q.
4. Disk Formatting
After partitioning, a file system must be created on each partition using mkfs (or a specific variant such as mkfs.vfat).
mkfs command
Purpose: Format a partition and create a file system.
Syntax:
mkfs [options] <em>device</em> mkfs.<em>fs_type</em> [-v] <em>device</em>Key options:
-t<fs_type>: specify the file system type (e.g., ext4, vfat)
-V: display detailed information (must appear before -t)
Example:
#mkfs -V -t vfat /dev/sdb1
#mkfs.vfat -v /dev/sdb1
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.
