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 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

How to automount USB Drive in Ubuntu 1

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

How to automount USB Drive in Ubuntu 2

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

# nano /etc/fstab

How to automount USB Drive in Ubuntu 3

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

How to automount USB Drive in Ubuntu 4

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

How to automount USB Drive in Ubuntu 5

How to automount USB Drive in Ubuntu 6

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

How to automount USB Drive in Ubuntu 7

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

$ sudo apt upgrade

How to automount USB Drive in Ubuntu 8

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

$ sudo mkdir /media/usb

How to automount USB Drive in Ubuntu 9

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

How to automount USB Drive in Ubuntu 10

How to automount USB Drive in Ubuntu 11

How to automount USB Drive in Ubuntu 12

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:

How to automount USB Drive in Ubuntu 13

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 automount USB Drive in Ubuntu 14

How to unmount the USB drive

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

 

$ sudo umount /media/usb

How to automount USB Drive in Ubuntu 15

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.

Leave a Comment

Your email address will not be published. Required fields are marked *