Have you ever wondered how a Linux system “finds” files on an external USB drive? Or, when you plug in a new hard disk, how does the system allow you to access its data? This is where the core concept of “mounting” comes into play. In simple terms, mounting connects a physical storage device (such as a hard disk partition, USB drive, or CD-ROM) to the Linux directory structure, enabling the system to read or write data from this device as if it were a local file.
I. Why Mounting?¶
The Linux directory structure is “tree-like,” with the root directory (/) as the starting point for the entire system, where all files reside in subdirectories under the root. However, physical storage devices (like new hard disks or USB drives) are independent “external file repositories.” They need to be “connected” to the root directory via a mount point (a directory) so the system can recognize and access their contents.
For example: If your USB drive is a standalone “file repository,” the mount point acts like a “bookshelf” (a directory) at home. By “plugging” the USB drive into this bookshelf, the system can access the files on the USB drive from the bookshelf.
II. Key Concepts to Understand First¶
Before starting operations, remember these two core concepts:
- Device Name: In Linux, storage devices are typically represented in the format /dev/sdXn. For example, a USB drive might be /dev/sdb1, and the first partition of the first hard disk is /dev/sda1 (X is a letter, n is a number).
- Mount Point: An empty directory (e.g., /mnt/usb) used to “house” the mounted device, allowing the system to access files on the device through this directory.
III. Preparation: Confirm Device and Mount Point¶
Before mounting, confirm two things:
1. Identify the Storage Device: After inserting the USB drive or connecting the new hard disk, use commands to check the device name.
Common commands: lsblk (lists all block devices, simple and intuitive) or fdisk -l (shows detailed partition information).
Example (the USB drive might appear as /dev/sdb1; confirm based on actual output):
lsblk # Run this to find your device; e.g., the USB drive is sdb1
- Prepare the Mount Point: Create an empty directory as the mount point (if it doesn’t exist).
For example, to mount the USB drive at/mnt/usb, create this directory first:
sudo mkdir /mnt/usb # Requires root privileges; use sudo to elevate
IV. Formal Mounting: 3 Steps¶
1. Execute the Mount Command¶
Use the mount command with the format:
sudo mount 设备名 挂载点
Example (assuming the device is /dev/sdb1 and the mount point is /mnt/usb):
sudo mount /dev/sdb1 /mnt/usb
sudo: Required, as mounting needs root privileges.Device Name: Must be a device path starting with/dev/, e.g.,/dev/sda1.Mount Point: Must be an existing empty directory, e.g.,/mnt/usb.
2. Verify Successful Mounting¶
After mounting, use these commands to check:
- Method 1: Use df -h to view mounted file systems (-h for human-readable format):
df -h | grep /mnt/usb # Filter information related to the mount point
- Method 2: Use
mountto view all mounted information and locate your device:
mount | grep /mnt/usb
- Method 3: Directly access the mount point directory to check for files on the device:
ls /mnt/usb # If there are files on the USB drive, they will appear here
3. Unmount the Device (Important!)¶
Always unmount the device when not in use to avoid data corruption or resource waste. Ensure:
- No programs are accessing the device (e.g., if you’re in cd /mnt/usb, exit first).
- Execute the unmount command:
sudo umount /mnt/usb # Unmount the mount point
- If you get “device is busy,” exit all open terminal windows or programs accessing the device directory before retrying.
V. Common Issues and Solutions¶
-
Problem 1: Mount Point Does Not Exist
Error:mount: /mnt/usb: can't read superblock
Solution: Create the mount point directory first (see “Preparation” above). -
Problem 2: Device Name Not Found
Error:mount: /dev/sdb1: can't read superblock
Solution: Confirm the device name withlsblk(e.g., the USB drive is/dev/sdb1, not/dev/sdb). -
Problem 3: Unmount Fails with “Device is Busy”
Error:umount: /mnt/usb: target is busy
Solution: Exit all terminals or programs accessing the/mnt/usbdirectory before unmounting.
VI. Temporary vs. Permanent Mounting¶
- Temporary Mounting: Done with the
mountcommand; the mount will be lost after a reboot or shutdown. - Permanent Mounting: Modify the
/etc/fstabfile to auto-mount the device on system startup (suitable for long-term use, e.g., a second hard disk).
Beginners should first master temporary mounting, then try permanent mounting once comfortable.
VII. Summary¶
Mounting is a critical step for connecting external storage in Linux. The core is “device name + mount point + mount/umount commands.” By confirming the device with lsblk, creating a mount point with mkdir, mounting with mount, and verifying with df -h, you can easily complete file system mounting. Practice with a USB drive to become proficient!