Mounting a USB Drive in Debian
- Last Updated: 08/10/2018
Mounting a USB Drive in Debian¶
When you plug in a USB drive into your computer, most of the time behind the scene, the computer automatically "mounts" the drive to a folder on your computer. This allows you to go to that folder and access the data on the drive as an additional part of the file system. Linux, however, typically doesn't automatically mount a USB drive when it is plugged in. To use a USB drive, you need to manually mount the device to a folder on the computer.
The first step is to simply plug in the USB drive into the server or whatever computer you wish to access it on. After you plug the device in, you need to locate where the device was added to the "/dev" directory. In order to list all of the devices, use this command:
You should get an output that lists multiple devices in a similar format as this:
Each of these devices is a drive on the computer, and this shows you the individual partitions and sizes of each device. You should be able to now locate which of these devices is your USB Drive by comparing the size listed by "fdisk -l" and the size of your device. At the end of each section, the partitions are listed for each disk. Partitions are essentially separated segments of a drive. Choose which partition to use, which will usually be 1 for USB drives. Make a note of the partition you are choosing. It will be in a format similar to /dev/sdb1, as circled above.
The last step before actually mounting the device is to create a mount point. A mount point is essentially just a directory on the computer that points at the USB device's storage. In order to create a mount point, you simply create a directory, typically in the /media folder. Do this by running the following command:
Finally, you need to run the mount command to tell the mount point to use the contents of your USB drive as its file system. Use this command, replacing in the name of your drive that you made note of earlier.
mount /dev/sdb1 /media/usb-dev-1
If you have done everything correctly, you should be able to go into the /media/usb-dev-1 folder and view the files on your USB drive. You can access the device similar to any other folder by using the "cd /media/usb-dev-1" command and use other commands as normal.
Unmounting a device¶
Before you can remove your USB device, you must "unmount" it from the file system. In order to unmount the device, you first need to make sure that nothing is accessing the drive, meaning no programs are running from it and you don't have any open shells on the device.
After you have all processes closed using the mount point, use this command to unmount the device:
If this command gives you no errors, you can then remove the device from the server.