Categories: Ubuntu

How to automount USB Drive in Ubuntu

USB (Universal Serial Bus) is a device which is used as a medium of communication between two peripherals, laptops and personal computers. We can save data on USB from one computer and can copy it to another computer by just using a plugin. When USB is plugged into a computer it is mounted by the operating system installed on that machine. By default the USB is automatically mounted by the operating system installed in a machine but sometimes because of some issue like USB storage device configurations are missing the USB devices are not automatically mounted when they are plugged in. In this case, we have to configure the USB storage devices so that they can be automatically mounted when the system is plugged in. Two methods to auto mount the USB drive on Ubuntu are going to be discussed in this post.

How
Sponsored
we can auto mount USB drive on Ubuntu

As we discussed above, we can configure the USB drive so that it can be auto-mounted when plugged in if by default it is not automounted by two different methods. We will discuss both methods in detail in this post.

How UUID is used to auto mount the USB Drive

UUID (universal unique identifier) is used in Linux for the detection of the USB which is plugged in or for the identification of the partition used by the USB drive. Because of this we have to become a root user. We can be a root user by the following command, it will ask for a password so enter the password:

$ sudo -s

The command sign has changed from “$” to “#” which means now we are in the root user mode.

In order to find out the details of the USB devices attached to our system we will use the following command:

# blkid

Now open the /etc/fstab file with the help of nano as:

# nano /etc/fstab

Now add the following text to the editor. You can save this by using your own address, we are using here /mnt/usb, also enter your unique UUID which you can copy from the above command that is of “blkid”.

UUID=9033-F09B /mnt/usb ext4 defaults 0 0

Now exit the editor by saving the file pressing CTRL+X then type “y” and press ENTER. Now finally run the following command by using the following command.

# mount -a

We can see it is showing that the device is already mounted because by default it is being mounted. If it isn’t mounted by default then it will be mounted by this command.

What is an alternate method to auto mount the USB Drive

We can mount USB in another way too. Open the terminal and use the “update” command to update the repository.

$ sudo apt update

Now we will also upgrade it so all the packages are upgraded as well.

$ sudo apt upgrade

Sponsored

Now we will create the directory by using the command “mkdir” so that the usb drive can be mounted there:

$ sudo mkdir /media/usb

To find out the base name of the mounted USB drive we use the following command as we find out the name of our usb is /dev/sdb1:

$ sudo fdisk -l

Now if we have the format of usb drive FAT32 or FAT16 system we will use the following command:

$ sudo mount -t vfat /dev/sdb1 /media/usb -o uid=1000,gid=100,utf8,dmask=027,fmask=137

And for the format of NTFS we will use the following:

$ sudo mount -t ntfs-3g /dev/sdb1 /media/usb

As our USB drive is of the FAT32 system, we will use the mentioned command for it:

The usb drive is mounted successfully and we can access it and open its files. We go to the file and can check on the left side of the window the USB drive is present.

How to unmount the USB drive

We can unmount the USB drive by using the umount command as:

 

$ sudo umount /media/usb

The USB drive will be unmounted successfully.

Conclusion

A lot of alternate methods are there to complete any task, so if we are getting issues in mounting the USB drive on the laptop, there is no need to panic, we can still manually mount the USB drive. In this post the two methods are discussed through which we can mount the USB drive; one is using the UUID command whereas the other one is more convenient by just making the directory where the USB Drive is being mounted and by running the command according to the format of your USB drive. Using the umount command we also showed how to unmount the USB drive. This post will make you understand how to mount the USB drive on Ubuntu.

Ubuntu Server Admin

Recent Posts

Building RAG with enterprise open source AI infrastructure

One of the most critical gaps in traditional Large Language Models (LLMs) is that they…

1 hour ago

Life at Canonical: Victoria Antipova’s perspective as a new joiner in Product Marketing

Canonical is continuously hiring new talent. Being a remote- first company, Canonical’s new joiners receive…

1 day ago

What is patching automation?

What is patching automation? With increasing numbers of vulnerabilities, there is a growing risk of…

2 days ago

A beginner’s tutorial for your first Machine Learning project using Charmed Kubeflow

Wouldn’t it be wonderful to wake up one day with a desire to explore AI…

3 days ago

Ubuntu brings comprehensive support to Azure Cobalt 100 VMs

Ubuntu and Ubuntu Pro supports Microsoft’s Azure Cobalt 100 Virtual Machines (VMs), powered by their…

3 days ago

Ubuntu Weekly Newsletter Issue 870

Welcome to the Ubuntu Weekly Newsletter, Issue 870 for the week of December 8 –…

4 days ago