This tutorial will show you how to mount and access a USB stick or external USB hard drive on Linux.
Most desktop Linux distributions will automatically mount USB drives show them in their file explorer, but lightweight and server distributions may not include this functionality – either because it’s considered unnecessary or because the typical user of said distribution wants to be able to do manage those tasks themselves.
Modern Linux distributions should all include drivers for USB sticks and external drives, so it’s just a matter of mounting them at a location in the file system so that they can be accessed. Here’s how to do it.
Plug In the Drive
The first step – plug in your USB stick or external hard drive and give it a few moments to be detected.
Find the Drive
Next, find the drive you just plugged in using the fdisk command to list (-l) the attached storage devices:
sudo fdisk -l
We’ll be using the sudo command frequently – many of these tasks require administrative privileges.
The fdisk command will output a list of storage devices attached to your system. Among them (hopefully last in the list to make it easy to find) will be the device you just plugged in:
Disk /dev/sdb: 29.26 GiB, 31406948352 bytes, 61341696 sectors Disk model: Cruzer Blade Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xfdb38d34 Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 61341695 61339648 29.3G c W95 FAT32 (LBA)
Above, you can see the device /dev/sdb (the physical USB drive) and /dev/sdb1 – a FAT partition on that drive.
The device names sdb/sdb1 may differ on your system!
Create Mount Point
Before you can mount the drive for use, you’ll need a location for the drive to be accessed from – an empty folder:
sudo mkdir /media/usb1
The /media/ directory is commonly used for removable media – so I’ve created a folder in it for this USB drive to be mounted under.
Mount the Drive
The mount command will mount a given storage device to a given directory:
sudo mount /dev/sdb1 /media/usb1
The above command mounts the FAT partition on the USB stick (/dev/sdb1) to the /media/usb1 directory created above
Check Mounted Volumes
You can check whether the drive has mounted successfully by piping the output of the mount command to the grep command and searching for the name of your USB device:
mount | grep sdb1
Use the Drive
With the drive mounted, you can simply use the files on the drive as you would any other path on your file system:
touch /media/usb1/myFile.txt
The above command would create a new file on the USB drive called myFile.txt.
Unmount the Drive
The umount command will unmount a drive so it can be safely disconnected:
sudo umount /dev/sdb1
Simply supply the device path to the umount command, and any mount points for it will be unmounted.
Mount Automatically on Boot
If your drive is going to be staying attached to your system permanently, you may wish to have it mount automatically:
First, find the UUID of your disk – this unique identifier will persist reboots. List the UUID for the disks by running:
ls -l /dev/disk/by-uuid/*
Make a note of the entry for your USB device, in my case:
/dev/disk/by-uuid/87CD-13C2 -> ../../sdb1
And then edit your fstab file to add a record for automatic mounting:
nano /etc/fstab
Add a line like the following:
/dev/disk/by-uuid/87CD-13C2 /media/usb1 vfat 0 0
… with the UUID for your own USB device. You may also have to replace the vfat bit if you are not using a FAT-formatted drive.
To mount all unmounted devices from fstab without rebooting run:
mount -a