| by Arround The Web | No comments

How to Mount a USB Drive in Debian 11

Removable USB drives allow you to easily transfer the files from one system to another. When you plug in a USB drive to your system’s USB port, it automatically mounts it. In Linux, it is mounted usually under the “/media” directory and can be accessed using the File Manager. However, in some scenarios, your system may not mount the USB drive automatically after you plug it in and you will be required to mount it manually in order to transfer the files between systems.

In this post, we will describe how you can mount a USB drive in a Debian OS in case it is not detected by the system automatically.

We use the Debian 11 OS to describe the procedure mentioned in this article. This procedure is also applicable to the previous Debian releases.

Mounting a USB drive

Step 1: Plug in the USB drive to any of the available USB ports in your computer.

Step 2: Once you plugged in the USB drive, check the USB drive name and the file system type drive used. To do this, launch the terminal application in your Debian 11 OS and issue the following command:

$ sudo fdisk -l

You will receive an output that is similar to that in the following screenshot. Scroll down the output and you will see your USB drive possibly at the end of the output labeled as sda, sdb, sdc, sdd, etc. Note down the name of your USB drive and the file system as you may need it later. In our scenario, the USB drive name is “/dev/sdb1” and the file system is “FAT32”.

https://linuxhint.com/wp-content/uploads/2019/11/1-40.png

Step 3: The next step is to create a directory that serves as the mount point for the USB drive. To create the mount point directory, issue the following command in the terminal:

$ sudo mkdir /media/<mountpoint_name>

Let’s create a mount point directory named USB under the /media directory:

$ sudo mkdir /media/USB

https://linuxhint.com/wp-content/uploads/2019/11/2-36.png

Step 4: Then, to mount the USB drive to the mount point that you created, issue the following command in the terminal:

$ sudo mount <device_name> <mountpoint_directory>

In our scenario, we will mount the USB drive /dev/sdb1 to the mount point that we created as /media/USB/. The command is as follows:

$ sudo mount /dev/sdb1 /media/USB/

https://linuxhint.com/wp-content/uploads/2019/11/3-39.png

Step 5: To verify if the USB drive is mounted on the mount point successfully, issue the following command:

$ mount | grep <USB_drive_name>

In our scenario, the command would be:

$ mount | grep sdb1

The output in the following screenshot shows that our USB drive /dev/sdb1 has been mounted on the mount point /media/USB. In case the command does not show any output, it means that the device is not mounted.

https://linuxhint.com/wp-content/uploads/2019/11/4-36.png

Step 6: To explore the mounted USB drive, move inside the mounted directory using the cd command:

$ cd /media/USB/

Now, you can navigate the directories in the USB drive in the same way as you do with the other directories in your file system. To list the files in the USB, use the ls command.

https://linuxhint.com/wp-content/uploads/2019/11/5-35.png

You can also access and explore the USB drive through the File manager of your system.

https://linuxhint.com/wp-content/uploads/2019/11/6-35.png

Auto-Mount the USB Drive in Debian 11

You can also auto-mount the USB drive when it is plugged into the system. To do this, edit the /etc/fstab file in a text editor using the following command:

$ sudo nano /etc/fstab

Add the following entry at the end of the file, replacing the /dev/sdb1 and vfat with your USB device name and filesystem:

/dev/sdb1 /media/USB vfat defaults 0 0

Then, save and exit the text editor.

Now, run the following command to mount all the devices:

$ mount -a

This command mounts all the USB drives that are added to the /etc/fstab file but have not yet been mounted. Also, the next time you restart your system with a USB drive plugged in, your USB drive will be automatically mounted.

Unmounting a USB Drive

If you no longer want to use the mounted USB drive, you can unmount or detach it. However, before attempting to unmount it, make sure that there are no other operations in progress on the mounted USB drive. Otherwise, the drive won’t detach and you’ll get an error message.

To unmount the USB drive, type umount followed by the mount point directory or the device name as follows:

$ sudo umount <mountpoint_directory>

Or

$ sudo umount <USB_drive_name>

In our scenario, it would be:

$ sudo umount /media/USB

https://linuxhint.com/wp-content/uploads/2019/11/7-33.png

If you see no output, it means that all went well and your USB drive is unmounted from the system. You can also confirm it from your File Manager’s left sidebar.

https://linuxhint.com/wp-content/uploads/2019/11/8-28.png

To delete the mount point directory, issue the following command:

$ sudo rmdir <mountpoint_directory>

https://linuxhint.com/wp-content/uploads/2019/11/9-26.png

Conclusion

In this article, you learned how to mount a USB drive in a Debian OS and how to unmount it when you need to remove the drive. I hope it will be helpful whenever you need to mount/unmount a USB drive in your system.

Share Button

Source: linuxhint.com

Leave a Reply