Linux Disk Usage and Mounting a USB Drive

how to mount a usb drive in linux

A data-logging Pi needs somewhere to write, so you plug in a USB drive. This guide explains how to mount a usb drive in linux: find it with lsblk, mount it, then add a UUID entry to fstab with nofail.

The routine below climbs from the simplest check to the most cautious fix: identify the partition, mount it by hand, make the mount survive reboots, and release it cleanly when it reports busy. It is written for general Linux, with the data-logging Raspberry Pi in mind. Working on a headless Pi over the network? Start with how to find ip address of raspberry pi, and read how to set up ssh keys on linux for key-based logins. More shell basics are collected in our linux command line tutorials.

Finding the device name with lsblk

lsblk lists storage devices as a tree, which makes the new drive easy to spot next to the disks you already have. Run it before and after plugging the drive in, and the entry that appears is yours. A Linux storage guide on LinkedIn describes the same tree view of all block devices.

The drive in hand before it goes into the port. The partition name you read from lsblk, not the physical drive, goes into the mount command.

Reading the tree

The whole drive appears as a parent device, and its partitions sit beneath it. The partition is what you mount, for example /dev/sdb1, not the parent disk. Match the entry by the size you recognise, and leave your system disk alone.

Plug the drive in first, then run lsblk and look for the new entry. This is an illustrative photo, not a Linux screen.

Reading the UUID column

Add the -f option, as in lsblk -f, and each device gets a UUID column. That identifier is what the fstab step later relies on. If the field is blank for your flash drive, an Arch Linux forum thread shows the same situation, so check the partition’s filesystem before going further.

The screen also shows a small bar chart and a line reading ‘DATA PACKETS’.

Mounting the partition by hand

A manual mount attaches the partition to an empty directory, and the basic syntax is sudo mount [options] <device> <mount-point>. A LinuxConfig forum thread gives a concrete case, mount /dev/sdb1 /mnt/sdb1. For a logger, a short fixed directory such as /mnt/usb is easier to point your scripts at.

  1. Create the mount point. Run sudo mkdir -p /mnt/usb to make the directory.
  2. Mount the partition. Run sudo mount /dev/sdb1 /mnt/usb, using the partition name lsblk showed you.
  3. Check the result. Run lsblk to see the mount point beside the partition, then df -h to read the drive’s size and how much is used before you start logging to it.

When mount reports a bad superblock

An error such as “wrong fs type, bad option, bad superblock on /dev/sdb1” can appear when the mount fails. It names three possible causes, so confirm the partition name and its filesystem with lsblk -f before retrying. Do not reach for a format yet if the drive holds data you want.

Formatting a blank drive as ext4

If the drive is new or disposable and will only be read by Linux machines, ext4 is a sensible choice for a logging volume. Run sudo mkfs.ext4 /dev/sdb1 and answer the confirmation prompt. Formatting replaces the existing filesystem, so check the device name against lsblk twice, then mount the partition as above.

Mounting at boot with fstab

A manual mount disappears at reboot, so a data logger needs an fstab entry. Reference the drive by UUID rather than by a name like /dev/sdb1. The same LinkedIn guide notes that UUIDs do not change even when you plug devices into different ports, while device names can.

A hub with several ports shows why UUIDs matter: the same drive can end up in a different port and still be recognised.

Building the entry

Get the UUID with sudo blkid /dev/sdb1. Then open /etc/fstab with sudo nano /etc/fstab and add one line. Entries have six fields in a fixed order: <device> <mount-point> <type> <options> <dump> <pass>.

A filled-in line looks like this:

UUID=<uuid-from-blkid> /mnt/usb ext4 defaults,nofail <dump> <pass>

Copy the dump and pass values from an existing line in your own fstab. Set the type to match the filesystem on the partition.

Why nofail matters for a logger

The nofail option lets boot carry on if the drive is absent. Without it, a pulled or failed drive can stop a headless Pi at boot, when you most need to reach it. One forum user on the LinuxConfig thread reported being unable to log in to a Raspberry Pi because it would not boot. Keep nofail on any removable data volume, and make your logging script cope with the directory being empty when the drive is missing.

Testing before you reboot

Run sudo mount -a. It mounts everything listed in fstab, and the LinkedIn guide advises fixing any errors it prints before you reboot. Only reboot once it returns cleanly and df -h shows the drive at its mount point.

Unmounting and the busy-device error

The command is umount, run against the mount point, as in sudo umount /mnt/usb. If it says the device is busy, something still has files open there. Work up this ladder and stop at the first step that succeeds.

  1. Find the culprit. Run sudo lsof /mnt/usb or sudo fuser -muv /mnt/usb to list the processes using the mount.
  2. Stop or close it. For a data logger, stop the logging service first, then try sudo umount /mnt/usb again.
  3. Use a lazy unmount. sudo umount -l /mnt/usb is the safer fallback because it waits until the device is free.
  4. Force only as a last resort. umount -f can lead to data corruption, so reserve it for a drive whose contents you can afford to lose.

These steps come from the same LinkedIn storage guide. Never unplug a drive that is still busy; release it first.

Checkpoints at a glance

Stage Command What to confirm
Identify lsblk -f The new partition, such as /dev/sdb1, and its UUID column
Mount by hand sudo mount /dev/sdb1 /mnt/usb The mount point appears beside the partition and in df -h
Persist sudo blkid /dev/sdb1 The UUID you paste into a six-field fstab line with nofail
Test sudo mount -a No errors before you reboot
Release sudo fuser -muv /mnt/usb No processes listed before umount

The commands and fields come from the LinkedIn storage guide and the LinuxConfig forum thread.

Frequently asked questions

Is the command umount or unmount?

It is spelled umount, without the n. The LinkedIn guide stresses this, and the command is normally given the mount point.

Will a desktop mount the drive for me?

On Ubuntu desktop, a USB drive is mounted automatically under /media, in a folder named after your username and the device. A manual mount or fstab entry is for when you want a fixed, scriptable location such as /mnt/usb.

How do I mount an NTFS drive?

One LinuxConfig forum reply suggests ntfs-3g /dev/sdb1 /mnt/usb. Use it if a plain mount fails on a Windows-formatted drive.

What if the UUID column is blank?

A forum report on Arch Linux shows a flash drive with a blank UUID while other devices had one. Run sudo blkid on the partition and check its filesystem before writing an fstab line that depends on it.