Objective

The following tutorial explains how to mount USB drive in Linux system using terminal and shell command line. If you are using desktop manager, you will most likely be able to use it to mount USB drive for you.

Mounting USB drive is no different than mounting USB stick or even a regular SATA drive. The video example below will illustrate the entire process of mounting USB drive on Linux system. To gain more understating read the subsequent paragraphs.

Conventions

  • # - requires given command to be executed with root privileges either directly as a root user or by use of sudo command
  • $ - given command to be executed as a regular non-privileged user

Video Example

Detecting USB hard drive

After you plug in your USB device to your USB port, Linux system adds a new block device into /dev/ directory. At this stage, you are not able to use this device as the USB filesystem needs to be mouted before you can retrieve or store any data. To find out what name your block device file have you can run fdisk -l command.

NOTE:fdisk command required administrative privileges to access the required information, thus from this reason the commands needs to be executed as a root user or with sudo prefix:
# fdisk -l 
OR
$ sudo fdisk -l

Upon executing the above command you will get an output similar to the one below:

Disk /dev/sdc: 7.4 GiB, 7948206080 bytes, 15523840 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x00000000

Device     Boot Start      End  Sectors  Size Id Type
/dev/sdc1  *     8192 15523839 15515648  7.4G  b W95 FAT32
The above output will most likely list multiple disks attached to your system. Look for your USB drive based on its size and filesystem. Once ready, take a note of the block device name of the partition you intent to mount. For example in our case that will be /dev/sdc1 with FAT32 filesystem.

Create mount point

Before we are able to use mount command to mount the USB partition, we need to create a mount point. Mount point can be any new or existing directory within your host filesystem. Use mkdir command to create a new mount point directory where you want to mount your USB device:

# mkdir /media/usb-drive 

Mount USB Drive

At this stage we are ready to mount our USB's partition /dev/sdc1 into /media/usb-drive mount point:
# mount /dev/sdc1 /media/usb-drive/
To check whether your USB drive has been mounted correctly execute mount command again without any arguments and use grep to search for USB block device name:
# mount | grep sdc1
/dev/sdc1 on /media/usb-drive type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=utf8,shortname=mixed,errors=remount-ro
If no output has been produced by the above mount command your USB partition is not mounted. Alternatively, double-check whether you have used a correct block device name in the above command.

Accessing USB Data

If all went well, we can access our USB data simply by navigating to our previously created mount point /media/usb-drive:
# cd /media/usb-drive

USB Unmount

Before we are able to unmount our USB partition we need to make sure that no process is using or accessing our mount point directory, otherwise we will receive an error message similar to the one below:
umount: /media/usb-drive: target is busy
(In some cases useful info about processes that
use the device is found by lsof(8) or fuser(1).)
Close your shell or navigate away from USB mount point and execute the following command to unmount your USB drive:
# umount /media/usb-drive

Permanent Mount

In order to mount your USB drive permanently after reboot add the following line into your /etc/fstab config file:
/dev/sdc1       /media/usb-drive           vfat    defaults        0       0 
However, the above mount line may fail if you add or remove additional drives from your Linux system. From this reason it is recommend to use partition UUID instead of a raw block device name. To do so, first locate a UUID of your USB drive:
# ls -l /dev/disk/by-uuid/*
lrwxrwxrwx 1 root root 10 Mar 27 23:38 /dev/disk/by-uuid/2016-08-30-11-31-31-00 -> ../../sdb1
lrwxrwxrwx 1 root root 10 Mar 27 23:38 /dev/disk/by-uuid/3eccfd4e-bd8b-4b5f-9fd8-4414a32ac289 -> ../../sda1
lrwxrwxrwx 1 root root 10 Mar 27 23:38 /dev/disk/by-uuid/4082248b-809d-4e63-93d2-56b5f13c875f -> ../../sda5
lrwxrwxrwx 1 root root 10 Mar 28 01:09 /dev/disk/by-uuid/8765-4321 -> ../../sdc1
lrwxrwxrwx 1 root root 10 Mar 27 23:38 /dev/disk/by-uuid/E6E3-F2A2 -> ../../sdb2
Based on the above ls command output we can see that the UUID belonging to block device sdc1 is 8765-4321 thus our /etc/fstab mount line will be:
/dev/disk/by-uuid/8765-4321    /media/usb-drive         vfat   0   0
Run mount -a command to mount all not yet mounted devices.
# mount -a