When connecting a USB device to a PC, Windows offers a choice to mount it as a mass storage device. However, Linux does not automatically mount all USB mass storage devices. In this article, we will discuss how to ensure that USB devices are mounted as mass storage devices in Linux.
Prerequisites
Before proceeding, ensure that your Linux distribution is updated with the latest packages. You can update your system using the following command:
sudo apt update
Identifying USB Devices
Before mounting a USB device, you need to identify it. You can use the lsusb command to list all USB devices connected to your system:
lsusb
Automatically Mounting USB Devices
By default, some Linux distributions, such as Ubuntu, automatically mount USB mass storage devices when they are connected. If your distribution does not automatically mount the device, you can create a udev rule to do so.
Create a udev Rule
To create a udev rule, open the terminal and create a new file using your favorite text editor:
sudo nano /etc/udev/rules.d/51-usb-storage.rules
Add the following line to the file:
ACTION=="add", SUBSYSTEM=="block", ATTR{device}=="[0-90-9]{4}", RUN+="/usr/local/bin/mount_usb.sh %k"
Replace [0-90-9]{4} with the vendor ID of your USB device. Save and close the file.
Create a Script to Mount the Device
Create a new file using your favorite text editor:
sudo nano /usr/local/bin/mount_usb.sh
Add the following lines to the file:
#!/bin/bash
# Set the device path
/sbin/mount -t vfat /dev/$1 /mnt
Replace vfat with the file system type of your USB device. Save and close the file. Make the script executable:
sudo chmod +x /usr/local/bin/mount_usb.sh
Manually Mounting USB Devices
If you prefer to mount USB devices manually, you can use the mount command:
sudo mount /dev/sdb1 /mnt
Unmounting USB Devices
To unmount a USB device, use the following command:
sudo umount /mnt
- Windows automatically mounts USB mass storage devices, but Linux does not.
- To automatically mount USB devices in Linux, create a udev rule and a script to mount the device.
- Manually mounting USB devices is also an option.