Connecting USB storage devices to the Ubuntu system for data migration or backup is a common operation in daily server maintenance. However, many operators encounter USB device mount failures, recognition failures, or permission errors when using the Ubuntu system. This article explains the underlying logic of USB mounting in Ubuntu and provides system troubleshooting and repair methods based on common failure scenarios to help you quickly resolve practical issues.
Understanding USB Mounting in Ubuntu
In Ubuntu, all devices (including USB storage) are treated as part of the file system. When a USB device is inserted, the kernel automatically recognizes the device and assigns a mount point through udev. This process is usually automated by udisks or systemd. However, in server environments, the automatic mounting service may be disabled, causing USB devices to malfunction. Typical paths for USB devices in the system are:
/dev/sdX
For example, if the USB device is the first SCSI device, the path might be /dev/sdb1, /dev/sdc1, and so on.
Analysis of Common Mount Failure Scenarios
The system does not recognize the USB device. After inserting the USB device, use the following command to check whether it is recognized:
dmesg | tail
If no new device information is displayed in the output, the following reasons may be the following: The USB port is damaged or has poor contact, the voltage is insufficient (especially for external hard drives without an external power supply), or the kernel has not loaded the USB storage module. Solution:
lsusb
If the device is not displayed, it is recommended to check the hardware or try restarting udev:
sudo service udev restart
The device is recognized but the mount point is not created. If lsblk shows the device but it is not mounted:
lsblk
Example output:
sdb 8:16 1 29.8G 0 disk
└─sdb1 8:17 1 29.8G 0 part
This indicates that /dev/sdb1 exists but is not mounted. You can manually mount the drive:
sudo mkdir /mnt/usb
sudo mount /dev/sdb1 /mnt/usb
If you receive an "unknown filesystem type" error, first check the file system format:
sudo file -s /dev/sdb1
Ensure that the system has the appropriate file system installed, such as FAT32 or NTFS.
The mount failure may be caused by a permissions issue. Server security policies typically prevent non-root users from mounting USB drives. You can implement a fixed mount by modifying the /etc/fstab configuration and adding the following:
/dev/sdb1 /mnt/usb auto defaults,nofail 0 0
Then execute:
sudo mount -a
If the storage device has file system errors, use the fsck tool to check and repair the file system errors:
sudo fsck /dev/sdb1
Be sure to unmount the device before performing the repair:
sudo umount /dev/sdb1
How to Automatically Mount USB Devices (Suitable for Test Servers)
For temporary test servers, you can install usbmount (supported in Ubuntu 18 and below):
sudo apt install usbmount
However, in Ubuntu 20.04 and later, usbmount has been deprecated. It is recommended to manually configure the automount service using udev and systemd mount rules. Write a custom udev rule:
sudo nano /etc/udev/rules.d/99-usb.rules
The content is as follows:
ACTION=="add", SUBSYSTEMS=="usb", KERNEL=="sd?1", RUN+="/usr/bin/systemd-mount /dev/%k /mnt/usb"
Save and reload the rules:
sudo udevadm control --reload-rules && sudo udevadm trigger
Using USB mount points on a server has security implications. If connecting a server to a public USB device, be wary of malicious programs. Mounting with noexec, nosuid, and nodev settings can enhance security. To ensure data backup integrity, perform a sync after writing to the device.
Standardize the mount path to avoid arbitrary mounting in system paths such as /media. Using a unified /mnt/usb or a custom directory facilitates automated script recognition. To prevent automatic mount errors, production servers should disable the automatic mount mechanism and only allow root users to mount the device to prevent accidental operations from impacting business operations.
USB device mounting issues on Ubuntu servers are not isolated cases; rather, they are a complex task involving the collaboration of multiple system components. Whether it's system failure to recognize the device, insufficient permissions, or file system errors, these issues can be identified and corrected through systematic troubleshooting. For servers deployed over a long period of time, it's recommended to establish standardized USB mount procedures and permission control policies to ensure secure and stable data transmission.