Aravind Prabhakar

Systems Engineer | Networking | Security | PreSales | Cloud | Devops | AIOps

View on GitHub Linkedin Blogs Tags
12 June 2022

Keeping mount points persistent using fstab

By Aravind

Process to format drive and mount persistently

Format the file system

Format using mkfs command

sudo mkfs.ext4 /dev/sda2

Find the partition

pi@raspberrypi-ard:~ $ lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda           8:0    0  1.8T  0 disk
├─sda1        8:1    0    1T  0 part /home/pi/DRIVE_A
└─sda2        8:2    0  839G  0 part /home/pi/DRIVE_B
mmcblk0     179:0    0 29.8G  0 disk
├─mmcblk0p1 179:1    0  256M  0 part /boot
└─mmcblk0p2 179:2    0 29.6G  0 part /

View details of the partition

in my case /dev/sda2

pi@raspberrypi-ard:~ $ lsblk --fs /dev/sda2
NAME FSTYPE LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINT
sda2 ext4         4a6be123-dfa6-471c-aa3a-72d69e9f2dfa  228.8G    67% /home/pi/DRIVE_B

The above gives FSType also which is also a field in the fstab so populating would be easy.

FSTAB fields

In fstab, there are multiple fields. Each line contains the below fields separated by a tab space.

Example

open fstab file using vim /etc/fstab and add the below line

UUID=4a6be123-dfa6-471c-aa3a-72d69e9f2dfa    /home/pi/DRIVE_B     ext4   defaults,errors=remount-ro       0      0

References

https://man7.org/linux/man-pages/man5/fstab.5.html
[ linux  ] tags: linux