How to mount USB in Linux
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.
3.Before mounting your USB manually you must check if your USB is already mounted by your Linux system.
- 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.
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.
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.
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.
- 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.
- 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.
- 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.
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.
7. To access the contents of USB drive
You need to go into that drive where your USB is mounted to access the data.
8. To unmount USB drive
To unmount USB drive run the command umount with specifying the mount point.