How to Mount a Drive on a Linux Server (and Make It Stay Mounted)

Mount a second drive (and keep it mounted): lsblk, mount, fstab.

Plug a drive into a Windows PC and a letter appears. Plug one into a Linux server and nothing happens until you tell the system where to put it. That's mounting: attaching the drive to a folder so its files appear there. Do it once by hand, then once in fstab so it happens at every boot.

Quick reference

TaskCommand
See all driveslsblk -f
Format as ext4 (erases it!)sudo mkfs.ext4 /dev/sdb1
Make a mount pointsudo mkdir /mnt/data
Mount it nowsudo mount /dev/sdb1 /mnt/data
Unmountsudo umount /mnt/data
Find its UUID for fstabsudo blkid /dev/sdb1

1. Find the drive

lsblk -f

You'll see something like:

NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 vfat 1A2B-3C4D /boot/efi
└─sda2 ext4 5e6f... /
sdb
└─sdb1 ntfs Photos 9A8B...

sda is the system disk. The new one is sdb, and its partition is sdb1. The FSTYPE column tells you how it's formatted: ext4 is Linux's own, ntfs is from Windows, exfat from cameras and Macs. Linux can read all of them. If FSTYPE is blank, the drive needs formatting.

2. Format it (only if it's new or you want to wipe it)

This erases everything on the drive. Check the name twice.

sudo mkfs.ext4 -L data /dev/sdb1

-L data gives it a label. If there's no partition at all (just sdb, no sdb1), create one first with sudo fdisk /dev/sdb: press n, Enter through the defaults, then w to write.

For a drive you'll also plug into Windows, use exFAT instead: sudo apt install exfatprogs && sudo mkfs.exfat /dev/sdb1.

3. Mount it

sudo mkdir -p /mnt/data
sudo mount /dev/sdb1 /mnt/data
ls /mnt/data

The drive's contents now appear in /mnt/data. If it's a freshly formatted ext4 drive, give yourself permission to write to it:

sudo chown john:john /mnt/data

4. Make it permanent with fstab

Device names like sdb can change between boots. Use the UUID instead:

sudo blkid /dev/sdb1

Copy the UUID="..." value, then:

sudo nano /etc/fstab

Add a line at the bottom:

UUID=9a8b7c6d-1234-5678-abcd-ef0123456789 /mnt/data ext4 defaults,nofail 0 2

Change ext4 to ntfs3 or exfat to match. nofail is important: without it, a missing or unplugged drive stops the server booting.

Test before rebooting:

sudo umount /mnt/data
sudo mount -a
ls /mnt/data

If mount -a says nothing and the files are there, the fstab line is right.

Unplugging safely

sudo umount /mnt/data

If it says "target is busy", something has a file open there — sudo lsof +D /mnt/data shows what. cd out of the folder if that's you.

Troubleshooting

"unknown filesystem type 'ntfs'." Use ntfs3 as the type on recent Ubuntu, or sudo apt install ntfs-3g.

Server hangs at boot after editing fstab. A bad line and no nofail. At the recovery prompt, nano /etc/fstab, comment the line out with #, reboot.

Can't write to the drive even with sudo chown. NTFS and exFAT don't have Linux permissions. Add uid=1000,gid=1000 to the fstab options (your user's IDs — id shows them).

Drive shows as sdb one day and sdc the next. That's why fstab uses the UUID. Your mount is fine; just don't script with /dev/sdX names.

Wrapping up

lsblk -f to find it, mkfs.ext4 only if it's blank, mount to try it, blkid plus an fstab line with nofail to keep it. Then mount -a to check before you trust a reboot to it.

Call us