A USB drive, also known as a USB flash drive or a pen drive, is a widely used external storage device that can be utilized to back up or transfer data from one system to another. As the file system is supported in a GUI Operating System such as Windows and GNOME Desktop in CentOS, which helps you to immediately mount a USB and access its data. However, most CentOS users prefer to mount the USB drive using the command-line method as they are used to working around the terminal. If you are one of them, you have to manually mount the USB drive in your CentOS terminal to access the USB data.

This post will demonstrate to you how to mount a USB drive in CentOS. So, let’s start!

How to mount USB drive in CentOS

First of all, plug in the USB drive into any of the available ports of your system:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/1-9.jpg" data-lazy- height="575" src="data:image/svg xml,” width=”767″>

How to detect USB drive in CentOS

CentOS automatically creates a new block device when an external USB storage device is connected to a system in the “/dev/” directory. Still, you cannot access the data present in the USB before mounting it. To mount the USB drive, you have to know the name of the block device created on your system. For this, we will utilize the “fdisk” command.

For Linux-based systems such as CentOS, “fdisk” is the widely used command-line-based disk manipulation utility. “fdisk” is an acronym for “format disk” or “fixed disk”. You can utilize the fdisk command for creating, copying, resizing, altering, resizing, and transferring partitions on a hard drive. In our case, we will execute the fdisk command to get the details about the device block created for the plugged in USB drive:

In the above-given fdisk command, the “-l” parameter is added to list all system partitions. The device names are used to display the partitions. For instance, /dev/sda, /dev/sdb, and /dev/sdc:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/2-9.jpg" data-lazy- height="527" src="data:image/svg xml,” width=”766″>

From the output, you can see that CentOS created the “/dev/sdc” for our USB drive having 3.8 GB storage:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/3-9.jpg" data-lazy- height="526" src="data:image/svg xml,” width=”765″>

How to create a mount point in CentOS

Now, we know about the name of the device block of our USB drive. Before moving towards the mounting procedure, we will create a mount point for the plugged USB drive. In our root filesystem, we will create a “usb” Directory as a mount point.

For this purpose, we will utilize the “mkdir” command in the CentOS terminal. The “mkdir” command permits a user to create single or multiple directories in their filesystem. To create a “usb” directory, we will execute the below-given command in our terminal:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/4-8.jpg" data-lazy- height="289" src="data:image/svg xml,” width=”735″>

How to mount USB drive in CentOS

After successfully creating the mount point, we can now easily mount the USB drive. According to the “fdisk” command, the name of the device block for our USB drive is “/dev/sdc1”. The “mount” command is utilized in the CentOS terminal for mounting the filesystems and removable devices such as external hard drives or USB drives.

Here is the syntax of the mount command:

$ sudo mount [Device_Block_Name] [Mount_Point_Path]

For our USB drive, the name of the device block is “/dev/sdc1” and its mount point is “/usb”:

$ sudo mount /dev/sdc1 /usb

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/5-8.jpg" data-lazy- height="320" src="data:image/svg xml,” width=”769″>

How to verify mounted USB drive in CentOS

The “grep” command is used to search for a specific string or pattern. The “grep” command will take the output of the “mount” command as input, by utilizing the pipe operator “|”. In between the whole filesystem related to the external plugged-in devices, the grep will look for the “sdc1” device block:

The execution of the above-given command will verify if the USB drive is mounted or not:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/6-8.jpg" data-lazy- height="328" src="data:image/svg xml,” width=”855″>

Another method to verify the mounted USB on your CentOS system is to use the “df” command. The “df” is an acronym for “disk filesystem”. It is utilized for getting the summary of used and available disk space of the filesystem.

You can add the combination of the “-HT” options in the “df” command to display the size and type of the filesystem:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/7-4.jpg" data-lazy- height="427" src="data:image/svg xml,” width=”766″>

How to access data of USB drive in CentOS

After successfully mounting the USB drive in the mount point, you can now access the USB drive. In this section, we will demonstrate to you the procedure of accessing data from the mounted drive. Firstly, execute the “cd” command to navigate into the “mount point” or “mount directory,” which is “/usb” in our case:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/8-2.jpg" data-lazy- height="325" src="data:image/svg xml,” width=”767″>

For viewing the content of the mounted USB drive, execute the “ls” command in your CentOS terminal:

The output will list the names of all files and directories present inside the USB drive:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/9-2.jpg" data-lazy- height="316" src="data:image/svg xml,” width=”765″>

How to delete a directory from the mounted USB drive in CentOS

As the mounted directory “/usb” is our current working directory. So now, we will utilize the “rmdir” command for deleting a directory from our USB drive:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/10-2.jpg" data-lazy- height="325" src="data:image/svg xml,” width=”855″>

Again, execute the “ls” command to check if the directory is deleted or not:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/11-1.jpg" data-lazy- height="304" src="data:image/svg xml,” width=”858″>

How to unmount USB drive in CentOS

The “umount” command is used for unmounting any filesystem. For instance, to unmount a USB drive, we will add the device block name of the mounted drive in the “umount” command:

<img alt="" data-lazy- data-lazy-src="https://kirelos.com/wp-content/uploads/2021/10/echo/12.jpg" data-lazy- height="309" src="data:image/svg xml,” width=”737″>

Conclusion

When you plug in a USB drive in your CentOS system, it normally mounts automatically. After that, you can utilize the file manager on your system to access its data. Unfortunately, in some cases, you may need to mount the USB through the CentOS terminal manually. This post demonstrated how to mount a USB drive, access USB data, and delete any directory from the mounted USB drive. Moreover, the procedure for unmounting the USB drive is also provided to you.

About the author

<img alt="" data-lazy-src="https://secure.gravatar.com/avatar/c73b74cd8044d2e9b300610f5af77d0b?s=112&r=g" data-lazy- height="112" src="data:image/svg xml,” width=”112″>

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.