How to Mount and Unmount a USB Drive in the Linux Terminal

When you plug a USB flash drive into a desktop computer running Ubuntu, the graphical interface usually handles everything for you. The drive icon magically appears on your desktop, and you simply double-click it to view your files. But what happens when you are managing an Ubuntu server without a graphical interface (GUI), or connecting via SSH?

In the terminal, inserting a USB drive does nothing automatically. You must manually instruct the Linux kernel to attach the drive’s file system to a specific folder on your hard drive before you can read or write data to it. This process is known as “mounting.”

In this guide, we will walk you through the professional workflow for identifying, mounting, and safely unmounting a USB drive entirely within the Linux terminal.

Step 1: Identify Your USB Drive

Before you can mount the drive, you need to know what “name” the Linux kernel has assigned to it. Linux treats all hardware as files, usually located in the /dev directory.

  1. Plug your USB drive into the computer.
  2. Open your terminal and type the following command to list all block devices (storage drives): lsblk

The output will show a tree of your drives. Your main hard drive is usually labelled sda or nvme0n1. Your USB drive will likely be at the bottom, labelled something like sdb or sdc. Look at the size column to confirm you have the right drive.

Underneath the drive name (e.g., sdb), you will see the actual partition on the drive that contains your data, which will be labelled sdb1. Write this partition name down.

Step 2: Create a Mount Point

Linux needs a specific, empty folder (directory) to act as the gateway to your USB drive. You only need to create this folder once.

Type the following command to create a folder called “usb” inside the standard /media directory:

sudo mkdir /media/usb

Step 3: Mount the USB Drive

Now you simply connect the device partition (from Step 1) to the folder you just created (from Step 2).

Type the following command (replacing sdb1 with your actual partition name):

sudo mount /dev/sdb1 /media/usb

If the command executes without displaying any errors, it was successful! You can now navigate to that folder to view your files:

cd /media/usb
ls

Step 4: Safely Unmount the USB Drive

This is the most critical step. If you simply yank the USB drive out of the port while it is mounted, you risk severely corrupting the data on the drive. You must tell the Linux kernel to flush its cache and safely detach the file system.

  1. First, ensure you are not currently inside the USB folder. The terminal cannot unmount a drive if you are using it. Type cd ~ to return to your home directory.
  2. Type the unmount command, pointing it to your mount folder:

sudo umount /media/usb

Note: The command is umount, not “unmount” (there is no ‘n’).

Once the terminal returns to a new prompt line without errors, it is completely safe to physically unplug the USB drive from the computer.

Leave a Reply

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

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.

Receive our best articles and tips delivered straight to your inbox.