How to Mount and Unmount Devices on the Linux Command Line

USB Universal PlugWhen a new file system (ie. removable media device) is introduced in Windows, it is automatically mounted and assigned a drive letter, from which it is accessible until it is removed. Microsoft has us spoiled.

On Linux, file systems (devices) need to be mounted before they can be accessed. It is an extra step, any way you look at it, so just consider the fact that, this way, you have a great deal of control over the entire process.

It is true that most devices can be mounted from the GUI, so let’s briefly cover that option before jumping into the command line.

Mounting File Systems From the KDE GUI

KDE-Available-Device-IconsMounting and unmounting devices from the KDE GUI (Graphic User Interface) is a simple matter of clicking on the little USB device icon in the system tray. It may even pop up on it’s own when a device is plugged in. From this “Available Devices” notifier, each device can be mounted or unmounted as needed.

Mounted devices will show up in the “Places” panel of the Dolphin file manager — but they’re just shortcuts to the actual default mount points in the /run/media/YourUserName/ directory.

If ever there is trouble unmounting a device, check to make sure that all of the contents of the drive are closed, then try again.

Mounting File Systems From the Command Line

The mount command mounts a file system for use within the current file system.

Simply typing the mount command into the command line will show the mounted file systems, but in a very messy (dare I say unreadable?) format.

To split up the output into human-readable columns, try mount | column -t.

The syntax to mount a device is mount what where, so you will need to know the name of the device to be mounted, and where to mount it.

You can use fdisk -l to determine the name of the device that you want to mount.

When I say “name of the device”, what you are looking for may be similar to /dev/sdb1 or /dev/sdc1. It is usually identifiable by the size, or by the fact that it just showed up when you plugged the device in.

While, in theory, a device could be mounted just about anywhere, I recommend creating directories that exist for the sole purpose of being used as mount points.

You can, for example, create directories in the /mnt directory (as long as you are root or have root privileges), to which each device can be temporarily mounted.

Example: mkdir /mnt/usb and mkdir /mnt/hd

Then, simply mount the device.

Example: mount /dev/sdc1 /mnt/hd

Unmounting File Systems From the Command Line

If you pull the plug prematurely on a mounted device, you’re liable to destroy the device’s entire file system.

The good news is that it probably won’t blow up. But no promises.

So how do you know if the action is premature? You ask it nicely; and don’t forget to say please.

Or you can use the umount command. Yeah, that might work, too.

Instead of unmounting the device, you need to unmount the file system at the mount point.

Example: umount /mnt/hd

Now, if you physically pull the plug, all should be in order, and no explosions should occur.

Leave a Reply

You have to agree to the comment policy.