Keeping mount points persistent using fstab
By Aravind
Process to format drive and mount persistently
- Format the partition /dev/sda2 using “mkfs”
- Create the directory: The directory “/home/pi/Drive_B” was created using “mkdir /home/pi/Drive_B”
- Add the values to fstab. The UUID and the mount point is what binds things
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.
- Block device : This is the UUID part to signify which device need to be used
- Mount point: The mount point of the device : in my case “/home/pi/Drive_B”
- File system: In my case, ext4
- Options: These are options associated with the file system. I provided defaults, errors=remount-ro (remount as read only)
- Dump: default is 0, which means don’t dump. IMHO, I haven’t really used much of this option. I always end up leaving it as default
- Check: file system checks that need to be done at boot time and defaults to 0 which means don’t check the file system. I always leave it as default. Unless you need to run fsck everytime you boot.
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