Today I Learned: Why My External Drive Disappears When I SSH In (And How to Fix It)

As my homelab is growing, I noticed that when I ssh’d in to a machine, a mounted hard drive is not visible. But it is visible when I’m at the machine itself.


The Problem

I have an external drive mounted at /media/johndata on my Ubuntu desktop. When I sit down at the machine, it’s right there. Files accessible, everything happy.

But when I SSH in from another machine, my Mac, my Linode VPS, whatever, that mount point is empty.

This is not a bug. It’s actually working as designed, which somehow makes it more annoying.


Why This Happens

When you log into a Linux desktop GUI, the desktop environment automatically mounts removable drives on your behalf.

When you SSH in, there’s no desktop session. There’s just a shell. So the GUI-managed mount never happens, and the drive sits there unmounted and invisible.


The Fix: /etc/fstab

The solution is to tell the system to mount the drive at boot time, at the OS level, before any user session exists. That’s what /etc/fstab is for.

Step 1: Find Your Drive’s UUID

Never refer to drives by device name (/dev/sda4) in fstab. Device names can change if you add or remove hardware. Use the UUID instead, which is permanent.

sudo blkid

Look for your drive in the output. Mine showed up as:

/dev/sda4: LABEL="johndata" UUID="df4d3851-d2ab-4bf7-853f-c73534ee3838" TYPE="ext4"

The LABEL field is a nice hint that this is the right one. Grab that UUID.

Step 2: Make Sure the Mount Point Exists

ls /media/johndata

Step 3: Back Up and Edit fstab

Then open it for editing:

sudo vi /etc/fstab

Add this line at the bottom, substituting your own UUID and mount point:

UUID=df4d3851-d2ab-4bf7-853f-c73534ee3838  /media/johndata  ext4  defaults  0  2

A quick note on those last two numbers: 0 means don’t include this drive in dump backups, and 2 means check the filesystem at boot but after the root partition. That’s the right setting for a data drive.

Save and exit.

Step 4: Test Without Rebooting

sudo mount -a

This tells the system to mount everything in fstab that isn’t already mounted. If you get no errors, you’re good.

Verify:

ls /media/johndata

Your files should be there.


Conclusion

I wrote this all out for myself. My meatbag SSD requires multiple flashes.


Posted

in

,

by

Tags: