Fstab

From DikapediaV2
Revision as of 00:17, 27 August 2024 by Ardika Sulistija (talk | contribs) (Created page with "ADD NOTES: https://xan.manning.io/2017/05/29/best-practice-for-mounting-an-lvm-logical-volume-with-etc-fstab.html <b>/etc/fstab</b> - static information about the filesystems (aka file system table) The file fstab contains descriptive information about the filesystems the system can mount. <b>fstab</b> is only read by programs, and not written; It is the duty of the system administrator to properly create and maintain this file. The order of records in fstab is...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

ADD NOTES: https://xan.manning.io/2017/05/29/best-practice-for-mounting-an-lvm-logical-volume-with-etc-fstab.html

/etc/fstab - static information about the filesystems (aka file system table)


The file fstab contains descriptive information about the filesystems the system can mount. fstab is only read by programs, and not written; It is the duty of the system administrator to properly create and maintain this file. The order of records in fstab is important because fsck(8), mount(8), and umount(8) sequentially iterate through fstab doing their thing.


The file systems specified in this file get mounted automatically as the system boots up. Primary way for the system to automatically mount files.


Fstab Examples



With block device name:

# /etc/fstab: static file system information.
# <file system>         <mount point>   <type>  <options>       <dump>  <pass>
proc                    /proc           proc    defaults        0       0
/dev/sda1               /               ext3    defaults        0       0
/dev/sda2               swap            swap    defaults        0       0
/dev/sda3               /var            ext3    defaults        0       0
/dev/sdb1               /home           ext3    defaults        0       0


With UUID (my RHEL 7 instance):

$ cat /etc/fstab
# /etc/fstab
# Created by anaconda on Wed Oct 17 12:18:06 2018
# 
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=88fd4d41-c180-4721-80c6-535249a4a2bb /                       xfs     defaults        0 0
UUID=8d978988-9373-4f8d-9c73-2896d4a4c334 /var/log/important_app_logs ext4 defaults 0 0
UUID=f5367baf-5afd-4d52-afa7-d8840b69fe7b /home/ec2-user ext4 defaults 0 0
UUID=80c3e45d-cb48-49a1-9ccc-215876091a7b /home/ardika ext4 defaults 0 0
  • Using UUID (Universally Unique Identifier) is the ideal way to specify the file systems for mounting, because the system can load the file systems/partition in a different order. Potentially messing the order around (sda, sdb, sdc is not always the same drive, or same order).


My Prod env:

$ cat /etc/fstab
#
UUID=afcf1342-1d40-41bd-bde9-e4ea5d87e3b6     /           xfs    defaults,noatime  1   1


Fstab Contents



  • Block device name, Label, or UUID.
  • The mount point (root mount point, and whatever else you got).
  • The file system type (ext2, ext3, ext4, xfs, etc.)
  • Options: (To list multiple option flags, separate by commas, no space.)
    • auto/noauto: auto mount on boot (or whenever mount -a is ran) or not.
    • exec/noexec: execute binaries or not
    • ro/rw: read only, read-write
    • sync/async: Sync forces writing to occur immediately on execution of the command. Ideal for floppies and USBs but not internal drives. Async allows to execute over an elapsed time period.
    • Nouser/user: allow user to have mounting/unmounting privileges.
    • Default: default setting are defined per file system at the file system level.
  • Binary value “0” for false, “1” for true, for dumping. (outdated method of back up, recommend to leave as 0)
  • Last option is a numeric value for “passing”. This tells the system the order in which to fsck, or perform a file system check.


Using /etc/fstab



Once you have made a new entry in /etc/fstab, you can test if the automatic mount will be successful by running the mount command:

$ sudo mount -a

-a, --all

Mount all filesystems (of the given types) mentioned in fstab (except for those whose line contains the noauto keyword). The filesystems are mounted following their order in fstab. Be sure to unmount the file system first before running it or else you will get an error saying "already mounted" or something like that.



Using init=/bin/bash when system is booting to Emergency Mode


This method works on a workstation.

You can use this method if a user has misconfigured an /etc/fstab entry.

  1. On boot/grub menu, select "e" to edit the kernel boot line. At the end of the line, add "init=/bin/bash". Ctrl-X to continue the boot process.
  2. After the above was done, you end up at a shell prompt.
  3. The root filesystem is read-only, so we had to remount it with rw permissions by running: "mount -o remount,rw /"
  4. Edit /etc/fstab as needed.
  5. Reboot system




References:
[+] https://www.howtogeek.com/howto/38125/htg-explains-what-is-the-linux-fstab-and-how-does-it-work/