How to mount an USB drive on a Linux server

Background

This article give a broad overview of how to add a USB drive to your Linux server. A command sequence is displayed with an explanation afterwards.

Commands to Add a New USB Drive to a Linux Server

In this command sequence we’ll be added a new mount called /mnt/backupdrive

cd
ls -lha
df -h
blkid
fdisk -l
parted /dev/sdc
blkid
lsblk
mkfs.ext4 /dev/sdc1
fdisk -l
lsblk
cd /mnt/backupdrive
mkdir /mnt/backupdrive
mount /dev/sdc1 /mnt/backupdrive
df -h
blkid | grep sdc
cp /etc/fstab /etc/bak_fstab
blkid | grep sdc >> /etc/fstab
nano /etc/fstab
lsblk
cat /etc/fstab
blkid

If the commands seems overwhelming, do not fret. The command sequence is part interrogation of the existing system, part issuing of a command, and part validation that the last command issued worked as expected. When working with critical resources always remember this sequence:

  1. Interrogation of existing system, and understanding exactly what result you are looking at
  2. Issuing of a command
  3. Validation the whatever command you used performed as intended

If at any stage above something unexpected happens, immediately halt the current operation until you understand what it is that is not expected.

To illustrate how one could abbreviate the above sequence, see here:

parted /dev/sdc
mkfs.ext4 /dev/sdc1
mkdir /mnt/backupdrive
mount /dev/sdc1 /mnt/backupdrive
blkid | grep sdc >> /etc/fstab

So in reality we might be able to do the job in just 5 commands. But if we did so, we wouldn’t have known:

  1. Does a drive called /dev/sdc already exist? (Use fdisk -l to determine that)
  2. Does a mount called /mnt/backdrive already exist? (Use cd /mnt/backdrive to determine that)

Also no backup of fstab would have been created which would have mean a disaster if something went wrong.

Other questions the large sequence of commands answers are:

  • If we cd, are we root?
  • Show us the existing device attributes using blkid . Based on this output assign the correct drive name /dev/sdc
  • Use fdisk -l to view the existing partition table
  • List to block device hierarchy using lsblk
  • Double check fstab is updated as expected

Working with disks can be tricky but not if you remember the intorregate, issue, and validate sequence.

Contact Us if you require assistance with your Linux hard drives.

 

Share this article

Leave a Reply

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

Scroll to Top