automount a partition on linux

By | March 7, 2018

Partitions are not auto-mounted at boot time unless they are specified in /etc/fstab, this guide walks you through the process

1.Identify the block devices and their uuid (Universally unique identifier)  from blkid , lsblk commands.

sda 8:0 0 596.2G 0 disk
├─sda1 8:1 0 2G 0 part /boot
├─sda2 8:2 0 2G 0 part [SWAP]
├─sda3 8:3 0 1K 0 part
├─sda4 8:4 0 443.4G 0 part /run/media/cipher/e9480814-7c11-4ed1-956a-ab46610c5079
└─sda5 8:5 0 140G 0 part /

/dev/sda1: UUID="9e6adcf5-4a97-4c17-b0ec-ab89e1aa9af8" TYPE="ext4" PARTUUID="fc396355-01"
/dev/sda2: UUID="6b659d6e-f7ee-4a59-a552-05164ad36a06" TYPE="swap" PARTUUID="fc396355-02"
/dev/sda4: UUID="e9480814-7c11-4ed1-956a-ab46610c5079" TYPE="ext4" PARTUUID="fc396355-04"
/dev/sda5: UUID="9ffb470e-71af-4c1d-b76e-55f5e09a8890" TYPE="ext4" PARTUUID="fc396355-05"

add sda4 partition uuid in /etc/fstab
UUID=e9480814-7c11-4ed1-956a-ab46610c5079 /media/data ext4 defaults 0 0

#before rebooting the server make sure you have entered correct entries in fstab to check this issue command

#mount -a
mount: /media/data: mount point does not exist.
lets fix the mount point
#sudo mkdir -p /media/data
#sudo mount -a
#echo $?

we have setup automounting of drive it can be tested with df command.

df -Th 
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  2.0G     0  2.0G   0% /dev
tmpfs          tmpfs     2.0G     0  2.0G   0% /dev/shm
tmpfs          tmpfs     2.0G  1.5M  2.0G   1% /run
tmpfs          tmpfs     2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sdb3      ext4       79G   27G   48G  36% /
tmpfs          tmpfs     2.0G   52K  2.0G   1% /tmp
/dev/sdb5      ext4       65G   52G   10G  84% /media/data
/dev/sdb1      ext4      976M  154M  756M  17% /boot
tmpfs          tmpfs     394M     0  394M   0% /run/user/0
tmpfs          tmpfs     394M  4.0K  394M   1% /run/user/988
tmpfs          tmpfs     394M     0  394M   0% /run/user/1000