Skip to content

Instantly share code, notes, and snippets.

@darkmavis1980
Last active August 29, 2015 14:07
Show Gist options
  • Save darkmavis1980/0eb3ca13bc534ec8f8cd to your computer and use it in GitHub Desktop.
Save darkmavis1980/0eb3ca13bc534ec8f8cd to your computer and use it in GitHub Desktop.
How to automount partitions on linux

The first thing to do is to get the UUID of the hard drive, just type:

sudo blkid

This will return you a list of your hard drives with the UUID for each ones

/dev/sda1: UUID="206f61f1-a465-4240-935b-eea3c7c10cd9" TYPE="ext4" /dev/sda2: LABEL="Mimas" UUID="1569a3fe-65f0-4641-8eab-7c1f1affb5c2" TYPE="ext4" /dev/sda3: LABEL="Iapetus" UUID="d74de2c8-bc98-4032-8854-901d41f4b1b1" TYPE="ext4" /dev/sda5: UUID="7a375655-f71b-4686-8ac2-c0a260302165" TYPE="swap" /dev/sdb1: LABEL="Photos2" UUID="65d12ccf-eb67-4418-b198-45b141fa9ae9" TYPE="ext4" /dev/sdb2: LABEL="Enceladus" UUID="0ae8f29f-1c12-4193-85e2-36f33d9d8ebc" TYPE="ext4" /dev/sdc1: LABEL="Phoebe" UUID="3286ea22-bf21-46fc-bbb8-77ddb0dd1ae8" TYPE="ext4" /dev/sdd1: LABEL="Photos1" UUID="45a707d0-0f76-4e08-8467-d3afe5ce3e38" TYPE="ext4" /dev/sdd2: LABEL="Photos3" UUID="92cc4e5b-a942-481b-bfe0-280ac608a609" TYPE="ext4"

Now copy on gedit the UUID without the quotes (in our case we picked the hard drive called "Mimas" at /dev/sda2)

UUID=1569a3fe-65f0-4641-8eab-7c1f1affb5c2

Now we need to know the rest of the parameters to add to the fstab, so just write on the shell (bear in mind that at this stage you need to mount your hard drive)

cat /proc/mounts

This will show you a list of mounted devices, and at the end of this list you will find the mount point of your hard drives, so what we need to do now is to get the mount point of the hard drive we want to automount and we copy everything after /dev/sda2 (where /dev/sda2 is the hard drive we want to mount)

/dev/sda2 /media/darkmavis/Mimas ext4 rw,nosuid,nodev,relatime,data=ordered 0 0

Now you just need paste the string we just copied after the UUID (separated by a space obviusly)

UUID=1569a3fe-65f0-4641-8eab-7c1f1affb5c2 /media/darkmavis/Mimas ext4 rw,nosuid,nodev,relatime,data=ordered 0 0

Now that we have our nice string, we just need to edit the fstab

sudo nano fstab

And at the end of our fstab file we just need to copy the UUID with the parameters, save, and reboot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment