In this tutorial, we explain how to mount USB drives in a Linux system using terminal and shell command line. This allows you to mount a USB drive of any file system, to some mount point on your system. 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 understanding, read the subsequent paragraphs. In Linux, you can mount all file systems including ext4, FAT, and NTFS.
In this tutorial you will learn how to:
- Detect your USB drive
- Create a custom mount point
- Mount USB in Linux
- Access USB drive’s data
Software Requirements and Conventions Used
|Category||Requirements, Conventions or Software Version Used|
|System||Any GNU/Linux Distribution|
|Other||Privileged access to your Linux system as root or via the
|Conventions||# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Video Example on how to mount USB in Linux
Detecting USB hard drive
After you plug in your USB device to the 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 mounted before you can retrieve or store any data. To find out what name your block device file have you can run
fdiskcommand requires administrative privileges to access the required information, thus, from this reason, the commands needs to be executed as a root user or with
# 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/sdc1with 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
mkdircommand 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
# 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
grepto 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
# cd /media/usb-drive
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 linux command to unmount your USB drive:
# umount /media/usb-drive
Permanent USB Mount in Linux
In order to mount your USB in Linux permanently after reboot add the following line into your
/etc/fstab config file:
/dev/sdc1 /media/usb-drive vfat defaults 0 0
For any other file system type simply set correct type. For example the bellow command will mount USB driver with NTFS file system:
/dev/sdc1 /media/usb-drive ntfs defaults 0 0
Referring to the USB drive using block device name from the
/etc/fstabmay not provide you with a best long term solution. Depending on the number of USB drives available on your Linux system the block device name may change. Although it might serve you well as a temporary solution but you might be better off using UUID raw block device name as explained below.
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
8765-4321 thus our
/etc/fstab mount line will be:
/dev/disk/by-uuid/8765-4321 /media/usb-drive vfat defaults 0 0
mount -a command to mount all not yet mounted devices.
# mount -a
In this tutorial, we saw how to mount a USB drive on a Linux system in order to access its data and store new data onto it. Linux makes it possible to either temporarily mount a USB drive that we insert, or make a persistent mount of storage devices that we don’t plan on removing. Whether you have a small thumb drive or a huge external drive, the commands here should be able to mount your USB storage device.
Wrong fstype error
You may receive the following error when you attempt to mount USB stick:
mount: /mnt/sda: wrong fs type, bad option, bad superblock on /dev/sda1, missing codepage or helper program, or other error.
Make sure that you have a correctly defined format in the
/etc/fstab as follows:
<file system> <mount point> <type> <options> <dump> <pass>
Make sure that you have defined all above columns in correct order.