How to mount USB in Linux

Share on :

1. Why Mounting is done in Linux?

Mounting is done for the operating system to know how to access the files on that device. Linux systems can do automatically mounting for most of the devices if we arrange it to do so, just like Windows and Macs do.

2. To check your USB drive

To check if USB is connected to your system and detected by your system run fdisk –l command.

This command will list all the USB drivers connected and disk in your system. Once you connect your USB to USB port a new entry comes in the /dev/ directory.

fdisk command require administrative privileges so this command needs to be executed by root user or sudo user.

# fdisk -l
Here /dev/sdb is the USB drive directory showing based on the USB size and the file system.

3.Before mounting your USB manually you must check if your USB is already mounted by your Linux system.

  1. Run df –h (df stands for disk free and –h shows the details in human readable form) command, this command will show information related to file system, size and available free space in the storage, along with where the disk is mounted.
# df -h
here you can see my /dev/sdb1 (USB drive) is automatically mounted by Linux system

2. Run mount | grep <USB disk directory> command. This command will show your USB mount point with its mounted file system if the disk is already mounted, else it will show nothing if it is not mounted.

# mount | grep /dev/sdb1

NOTE:  Most of the Linux distributions automatically recognize the USB drive and mount them while, some older versions and some Linux system with minimal install can’t mount it automatically hence you have to do it manually.

4. How to create mount point

You can mount your USB in any existing directory or can create a new directory using mkdir command.

# mkdir   /media/ "dir-name"

5. Mounting USB drive

  • Temporary Mount

Temporary mounting will mount your USB for the run time that is your USB will remain mounted till your system is on or running and you have to mount it again the next time you switch on your system.

   Mounting  /dev/sdb1  into /media/usb using mount command. 
          # mount {source}  {destination}
  • Permanent Mount

You can permanently mount your USB by making an entry in etc/fstab. But you should be aware that whenever next time you boot your system your USB is connected else, you won’t be able to start your system because /etc/fstab is a system configuration file that contains all disk, so during booting process it is going to search for the USB for which you made the entry in /etc/fstab.

  1. Run blkid command to see what is your USB UUID (unique id) and your USB file system which would be required to enter in fstab file.
# blkid
blkid of my USB, So my USB has UUID=6404-13DC and file system vfat.
  1. You can open your /etc/fstab using any editor you have, make sure you are opening the file being a root user or using sudo before the command, else the file would open in read only mode and you won’t be able to edit it.
# vim /etc/fstab

NOTE: you can do entry in /fstab file by specifying the name of the drive (/dev/sdb1) in place of UUID  but it is recommended to use the UUID (unique ID) since the drive name (like /dev/sdb1)may change based on if you add a new disk or insert any other USB. Each hard disk and USB drives have their Unique ID (UUID) assigned to them which do not change.

6. To check if your USB is mounted or not.

Run mount command (mount command would give all the mounted file system). Run mount | grep ‘USB disk directory’

This command will show the mount point as well as the mounted file system of the USB disk if it is mounted else it would show nothing.

# mount | grep /dev/sdb1

7. To access the contents of USB drive

You need to go into that drive where your USB is mounted to access the data.

# cd /media/usb

8. To unmount USB drive

To unmount USB drive run the command umount with specifying the mount point.

#unmount   {mount-point}

Share on :

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *