Mount drives In Debian and Ubuntu

What does it means?

When we connect to our machine a drive we are used to see it immediately and to be able to access to it as it is plugged in.

Well this concept doesn’t work on every machines. If we have a server running and more often without graphical interface, for example, this is not going to happen on it’s own.

We have to run some commands before we can read this drive.
Lets see together how to do it.

NOTE: The content of this article doesn’t apply on drives whit NTFS file system.

Discover the connected drives

Firs we got to know the drives connected to our system and the name the system assigned them.

we can do this typing the command:

$ sudo blkid

We will have a answer like this:

/dev/mmcblk0p1: LABEL="system-boot" UUID="92C5-CC2B" TYPE="vfat" PARTUUID="da84ba12-01"

/dev/mmcblk0p2: LABEL="writable" UUID="b96ff47f-349e-4582-87d0-2d8c7afc91f4" TYPE="ext4" PARTUUID="da84ba12-02"

/dev/sda1: LABEL="UsBackUp" UUID="2fbcf53c-8b01-4867-a11e-9c31b5c99a31" TYPE="ext4" PARTUUID="13c03966-9159-4a37-971c-48fafb49904"

Here you will find the information of your device.
The fist value is the device name given from the pc. This can change if you’re working with different devices plugged in and if they are going to be connected in different order every time.

The LABEL is the name we have given to the device
The UUID is a unique number your device have
The TYPE indicate the filesystem in use on the device
The PARTUUID is the id of the partition

Mount the drive into a given folder

Mounting the drive will give us access to it like if it is a folder present in our system. Usually the drives are built in the folders: /mnt or /media.

To proceed with this process we will have to run a command with this syntax:

$ sudo mount <device name> <mount folder>

it will be like:

$ sudo mount /dev/sda1 /mnt/usbpen

We can check if the drive have mounted succesfully executing the command mount without any specification following:

$ sudo mount

now if we are going to check in our /mnt folder we will see our “usbpen” whit inside all the files we have in our pendrive.

Unmount our drive

Before removing the drive we have to unmount it or we are going to run into a file corruption.
To do this we just have to run:

$ umount /mnt/usbpen

or even:

$ umount /dev/sda1

Mount a drive at system startup

If we have a drive always connected like an hard drive or a backup usb-pen and we want it to be mounted at system startup we will have to edit the file /etc/fstab.

read this before going on

This method have a high risk of corrupting your system booting so don’t do it if you’re not sure about what are you doing.
I will not be responsible for any problem you are going to have if you choose to do what is following!

In order to achieve this we need to do something before:

create a mounting folder

In the previous explanation the folder was appearing just with the use of the command “mount” but in this scenario we have to create previously the folder in which the drive will be mounted.

So lets execute in out terminal:

$ sudo mkdir /mnt/drive1

Fetch some drive information

We will need some information about our drive before we proceed. In order to know what we need we can use the command lsblk specifying what we need to know for the next step.

$ lsblk -o NAME,FSTYPE,UUID

we will have a response like:

NAME        FSTYPE UUID
sda                
└─sda1      ext4   2fbf8742-8b01-4667-a11e-9c3859439a31
mmcblk0            
├─mmcblk0p1 vfat   F2C3-CC2B
└─mmcblk0p2 ext4   bf67a647f-679e-4582-87d0-2d8ca7d39f4

We need to know for our purpose:

  • UUID to be sure we are going to mount that specific drive even in case the connection port is going to change
  • FSTYPE is the file system used in the drive.

modify /etc/fstab

We have to open the file with our favorite text editor and root privileges:

$ sudo nano /etc/fstab

here we will have all the partition mounted at the system startup and it’s important not to mess with them.
We are going to add a line to the ones already there with this order:

UUID=<uuid> <pathtomount> <filesystem> defaults 0 0

NOTE: every parameter must be separated wit a <TAB> and not with a space

in our case the line will look like:

UUID=2fbf8742-8b01-4667-a11e-9c3859439a31 /mnt/drive1/ ext4 defaults 0 0

when you’re done save and reboot the system to check if the drive has been mounted.

The system encounter a problem and doesn’t boot up!

Well in case a problem occur you need a physical or virtual access to the machine main drive to solve the problem because you will need to find the way to get to the “fstab” file and make it as it was before. Even to make a backup will be a great idea.

As example you have to extract the drive and connect it to another system or boot up a live OS from a CD or a pen-drive.

Till the next time!
Bye!!!

Leave a Reply