How to Mount and Unmount Drives on Linux
In this article, I will show how to mount and unmount a drive on Linux. There will be a video showing how to do this up on my channel soon.
In The GUI
In the GUI, you’ll need an application like Gnome Disks.
- Select the disk you want to mount in the sidebar.
- Hit the play button. This will mount the drive in /mnt
Note, that the drive does need to be formatted and have a file system on it in order to be mounted.
You’ll also need to have polkit installed, so if you’re not in a desktop environment, you’ll need that set up. If you are in Gnome or KDE or something like that, you’re all set.
KDE does have it’s own tool, it’s a bit more complicated, but works mostly the same.
In the Terminal
In order to mount a drive, you first have to know the actual name of the drive. This is done with:
lsblk
This will list all of the drives currently attached to your system. Note that if you use snaps, your list will be a little longer than if you don’t.
The most challenging part of mounting a drive is to figure out which is which. The more drives you have, the harder this is going to be. Most people, however, should be able to figure it out as they won’t have dozens of drives.
The best way, is to know the size of your drives. Find the one that you want to mount. Note the letter designation. This will be sda or sdb, or perhaps, nvme. Do note, that a drive has to be partitioned and have a file system on it in order to be mounted.
Once you know the letter designation of the drive, then we need a place to mount the drive.
The most common place to do this is in /mnt
. But you can mount a drive anywhere you want. Keep in mind that if you want your drive available to apps that aren’t user specific, you may not want to mount it in your HOME directory.
Let’s say for this example that we do want to mount it in /mnt. To do that, all you have to do is:
Make a directory inside /mnt:
`sudo mkdir /mnt/mydrive`
Then simply:
`sudo mount /dev/sda1` /mnt/mydrive`
If this succeeded, there will be no output.
Let’s talk about that last command. The /dev/ is the directory where Linux stores its device information. All drives are in /dev by default. This is literally mapping that location to a user accessible location. Do note, that we’re mounting our partition, not the drive itself. That’s why it’s sda1, not just sda. Mounting just sda will spit out an error.
Unmounting
To unmount a drive, you can do this:
sudo umount /dev/sda1
This will remove the link between the drive and your directory. You can also do
sudo umount /mnt/mydrive
If you get a notice that the drive is busy, you should probably be patient. Often this means that data is still being written to the drive. But if you’re impatient, and need to get that drive disconnected right now, you can:
sudo umount -L /mnt/mydrive
This will just do it, without checking the device status. Note that this could lead to data loss. So be careful.
FSTAB
If you don’t want to mount your drives manually, Linux does let you set up a device to be auto mounted on boot. This uses a file called fstab. First, we’ll need to find your device’s UUID. This is a unique identifier that will not change. To get this:
sudo blkid
This will spit out a bunch of information. But what you need to do is find your drive, and copy the UUID portion of this. To copy in the terminal, you do ctrl + shift + c
. You will also need to note the file system type. Most Linux drives are ext4, but this could be ntfs or btrfs.
Next, we’ll need to tell the system to mount your drive on boot. To do this, we’ll need to edit the file /ect/fstab.
sudo nvim /etc/fstab
You’ll have entries inside this file already. Leave those alone. Go to the bottom and put this line:
UUID=THEUUIDOFYOURDRIVE /mnt/mydrive ext4 defaults.nofail 0 0
I’m not going to go into what all this means, as it gets complicated, but we’ll talk about the first four parts of this.
The first is the UUID of the drive you want to connect. Then we have the mount point. Then we have the file system type, in our case, it is ext4. Then we have the mount options. Almost always, you’ll be using defaults
here. I like to add nofail
as well, that way your system will boot even if the drive isn’t connected. Those last two numbers are for more complicated boot options, 0 0 is default, use that unless you know what you’re doing.
Save the file, and then reboot. The drive should be mounted.