How 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:
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:
Now open the /etc/fstab file with the help of nano as:
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”.
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.
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.
Now we will also upgrade it so all the packages are upgraded as well.
Now we will create the directory by using the command “mkdir” so that the usb drive can be mounted there:
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:
Now if we have the format of usb drive FAT32 or FAT16 system we will use the following command:
And for the format of NTFS we will use the following:
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:
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.