Solved: How to Mount USB Drive in Linux [100% Working]

If you have a usb disk and you are thinking "how to mount USB drive in Linux", you should read this article.

 

Required RPM to mount USB Drive in Linux

First of all, if you are using a Linux with a graphical interface (KDE, Gnome, XFCE etc.), most Linux distributions do the usb disk connection work for you. Sometimes, extra package installation may be required for this.

Advertisement

You can find the answer to the question "Which packages should I install for the disk format" in the picture below.

Solved: How to Mount USB Drive in Linux [100% Working]

In addition, the installed package also has operations on the usb disk. For example, you can see if you can perform operations such as create, share and copy after package installation.

 

Install Required Packages

USB with NTFS File System

For a usb disk with ntfs file type, ntfs-3g or ntfsprogs packages must be installed on the system.

If you are using a Debian based distribution (Ubuntu, Debian, Pardus etc.) and to confirm that this package is installed;

sudo dpkg -l | grep ntfsprogs

The above command will show package and its version if installed.

If you want to install this package, use following command:

Advertisement
sudo apt install ntfsprogs

 

If you are using a RedHat based distribution (CentOS, Rocky Linux, Alma Linux or Fedora);

sudo yum list installed | grep ntfsprogs
ntfsprogs.x86_64 2:2021.8.22-2.fc35 @anaconda

you can check the existence of the package in the system with this command. For installation, run the following command on the terminal.

sudo yum install ntfsprogs

 

USB with FAT32 File System

If you have a USB disk with FAT32 file type, the dosfstools package must be installed in the system.

To install on Debian-based distributions;

sudo apt install dosfstools

and to install on Redhat-based distributions

sudo yum install dosfstools
NOTE:

If you installed the packages, then you may need to physically remove the usb disk and insert it again.

 

How to identify the USB drive in Linux?

You have connected your USB to the Linux box but you are not sure how to identify the partition name of the USB? There are many commands which you can use to easily identify the connected USB drive.

Here I have consolidated Linux mount command to access filesystems, iso image, usb, network drives, refer this article for more details

The lsblk command will list the disks inserted into the Linux server:

foc@fedora:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 931.5G 0 disk /home
sdb 8:16 1 57.8G 0 disk
└─sdb1 8:17 1 57.8G 0 part

Your disk should show on this screen with its size. If not, plug the disk into a different usb port. If still no results, try connecting the USB disk to another computer. If there is no physical problem with the disk, it will definitely show on this screen.

For all information about the disk;

sudo fdisk -l /dev/sdb

you can run the command. Command output;

Advertisement
Disk /dev/sdb: 57.76 GiB, 62021173248 bytes, 121135104 sectors
Disk model: DataTraveler 3.0
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: 0x87c5c7b6
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 121135103 121133056 57.8G 7 HPFS/NTFS/exFAT

will display some information about the device.

 

How to get the File System type of USB Drive?

We can use blkid command which will show the file system type of the USB Drive.

For example for USB Drive with NTF File System type:

# blkid /dev/sdc1
/dev/sdc1: LABEL="Deepak-16G" UUID="B48646258645E886" TYPE="ntfs" PARTUUID="2633de4d-01"

Similarly for a USB drive with FAT32 File System type:

# blkid /dev/sdc1
/dev/sdc1: LABEL="DEEPAK-16G" UUID="5E92CAC292CA9E41" TYPE="vfat" PARTUUID="2633de4d-01"

 

Steps to mount USB Drive in Linux

After confirming that the disk does not have a physical problem, if you know the format of your disk, you can follow the mount steps.

 

Advertisement

Step-1: Create Mount Point

Create the directory where you will mount the disk with the following command. This is optional step and if you intend to temporarily mount the USB drive then you can just mount it on /mnt

sudo mkdir /media/my_disk

With this command you can confirm that the directory has been created.

ls /media/

 

Step-2: Mount the USB drive to mount point

It is important to mount the USB Drive to some partition to be able to access the content of the drive. So we will mount our USB drive i.e. /dev/sdb1 to /media/my_disk

sudo mount /dev/sdb1 /media/my_disk

 

Step-3: Verify

After the command is executed, the USB disk is connected to the system. You can verify the same using:

sudo mount -l | grep my_disk
/dev/sdb1 on /media/my_disk type ntfs (rw,relatime,user_id=0,group_id=0,allow_other,blksize=4096)

If you have inserted a FAT32 disk, the output will be as follows;

/dev/sdb1 on /media/my_disk type vfat (rw,relatime,user_id=0,group_id=0,allow_other,blksize=4096)

You can also verify the same using lsblk command output after mounting steps;

Advertisement
foc@fedora:/media/my_disk$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 931.5G 0 disk /home
sdb 8:16 1 57.8G 0 disk
└─sdb1 8:17 1 57.8G 0 part /media/my_disk

Changing File System type of USB Drive using mkfs

Operations such as file copy speed may cause problems due to the format of your current disk. For example, USB drive cannot save a single file larger than four GB by default due to the limitation in the FAT32 file system. Therefore, it is necessary to convert your FAT disk to exFAT or NTFS format.

First unmount the USB drive using umount command:

sudo umount /dev/sdb1

 The mkfs command is used in Linux for formatting. For example, in the terminal to make the file system of your usb disk exfat;

sudo mkfs.exfat /dev/sdb1

Or if you want to format it as NTFS due to its unique features (journaling, fake copy etc.);

sudo mkfs.ntfs /dev/sdb1

 

How to unmount USB Drive in Linux

First of all, verify that the USB disk is connected to the system;

sudo mount -l | grep my_disk
/dev/sdb1 on /media/my_disk type ntfs (rw,relatime,user_id=0,group_id=0,allow_other,blksize=4096)

Next execute the umount command followed by the USB partition OR mount point as we identified in previous commands;

Advertisement
sudo umount /dev/sdb1

or

sudo umount /media/my_disk

 Now we can safely delete the temporary mount point which we created:

sudo rm -rf /media/my_disk

If you attempt to delete the my_disk directory without unmounting, then you will get below error. So, first perform the umount operation and then the directory deletion.

foc@fedora:~$ sudo rm -rf /media/my_disk/
rm: cannot remove '/media/my_disk/': Device or resource busy

 

If you get "target is busy" during the umount process as shown below, it means that the USB disk is still in use. In such event you can either try to forcefully unmount the device or you must exit this directory in terminal or graphical interface which is using USB drive. Then repeat the umount process.

foc@fedora:/media/my_disk$ sudo umount /dev/sdb1
[sudo] password for foc:
umount: /media/my_disk: target is busy.

 

Permanently mount USB Drive using FSTAB

The operations in the above steps are one-time binding steps. When the computer restarts, your disk will not be mounted, you will have to repeat the mount steps you did before.

As a workaround, the USB drive must be permanently mounted using /etc/fstab.

Get the UUID of the USB Drive, it is always recommended to use UUID instead of partition name as the partition name is prone to change if some other disk/storage gets mounted before the USB. In such case the mount operation will fail leading to boot up issues.

Execute blkid command to get the UUID of your USB drive:

# blkid /dev/sdb1
/dev/sdb1: UUID="2c566ef5-fe73-4e1c-aa71-9a8cd77c0b31" TYPE="ntfs" PARTUUID="09181a39-01"

Now update the /etc/fstab file with a new entry and provide disk, path to be mounted, disk format, connection priority and permissions.

foc@fedora:~$ cat /etc/fstab
UUID=d1d3b1db-10b3-4655-b4fa-9d7238d5ed4a / btrfs subvol=root,compress=zstd:1 0 0
UUID=04c22680-e7e3-4703-91fc-cd5e942c356f /boot ntfs defaults 1 2
/dev/sda /home ntfs defaults 0 0

WARNING: Operations on the /etc/fstab directory may cause the operating system not to boot after reboot. Therefore, it is important to have a backup before starting. At the terminal;

sudo cp -rf /etc/fstab /etc/fstab-old

Take the backup without any operation with the command. In a negative situation, you can restore the system by returning from this backup.

For permanent mount operation;

sudo nano /etc/fstab

The script opens the file. Add the following to the last line of the file;

2c566ef5-fe73-4e1c-aa71-9a8cd77c0b31 /media/my_disk ntfs defaults 0 1

For FAT32 format;

2c566ef5-fe73-4e1c-aa71-9a8cd77c0b31 /media/my_disk vfat defaults 0 1

For exFAT format;

2c566ef5-fe73-4e1c-aa71-9a8cd77c0b31 /media/my_disk exfat defaults 0 1

Then save and exit with the CTRL + X command.

Once /etc/fstab is updated, execute mount -a command which will attempt to mount all the paths from /etc/fstab.

Next you can verify using mount -l command to make sure your USB drive is mounted successfully.

 

Finally

We recommend that you look at the man pages for the mount and mkfs commands. For this, in the terminal;

man mkfs

and

man mount

just run the commands. The information and parameters on these pages are the most accurate sources.

Before formatting the disk, make sure that you do not have any important data in the disk. Most importantly, make sure to format the USB disk during disk formatting. Otherwise, you may be formatting the system disk.

 

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Leave a Comment

X