# /etc/fstab

`/etc/fstab` (file system table) is a critical configuration file on Unix-like systems that defines how and where disk partitions, filesystems, and other storage devices should be mounted. It is read during system boot to automatically mount the specified filesystems without manual intervention.

## File Format

Each non-comment line in `/etc/fstab` describes one filesystem and contains six fields separated by whitespace (tabs or spaces). Blank lines and lines beginning with `#` are ignored.

### Field Structure

1. **File System**\
   The device or resource to be mounted (e.g., `/dev/sda1`, `UUID=...`, or `LABEL=...`).
2. **Mount Point**\
   The directory where the filesystem will be attached (e.g., `/`, `/home`, `/mnt/usb`).
3. **File System Type**\
   The type of filesystem (e.g., `ext4`, `xfs`, `nfs`, `swap`).
4. **Mount Options**\
   A comma-separated list of options that control the mount behavior (e.g., `defaults`, `noatime`, `ro`, `rw`).
5. **Dump**\
   A number (usually `0` or `1`) indicating whether the filesystem should be backed up by the `dump` utility. (Typically set to `0` for non-critical filesystems.)
6. **Pass**\
   A number that determines the order in which filesystems are checked by `fsck` at boot time. The root filesystem should usually be `1` and other filesystems `2` (or `0` to skip checking).

## Example /etc/fstab

```ini
# <file system>            <mount point>   <type>   <options>                            <dump>  <pass>
UUID=123e4567-e89b-12d3-a456-426614174000 /            ext4     defaults,noatime                    1       1
UUID=223e4567-e89b-12d3-a456-426614174001 /home        ext4     defaults,noatime                    1       2
/dev/sdb1                 none           swap     sw                                  0       0
//server/share            /mnt/share     cifs     credentials=/etc/samba/creds,iocharset=utf8,sec=ntlm  0  0
```

### Explanation

* **Root Filesystem**:\
  The first line mounts the filesystem identified by its UUID at `/` as an `ext4` filesystem using default options with no access time updates. It is set to be dumped and is checked first during boot.
* **Home Directory**:\
  The second line mounts another `ext4` filesystem at `/home`. It is set to be checked after the root filesystem.
* **Swap Partition**:\
  The third line designates a swap partition, with the mount point set to `none` because it is not mounted in the filesystem hierarchy.
* **Network Share (CIFS)**:\
  The fourth line mounts a network share using the CIFS protocol. It specifies a credentials file and additional options to handle character encoding and security.

## Best Practices

* **Use UUIDs or Labels**:\
  Instead of device names (like `/dev/sda1`), use `UUID=` or `LABEL=` to ensure the correct partition is mounted even if device names change.
* **Backup the File**:\
  Always make a backup of `/etc/fstab` before editing, as mistakes can prevent the system from booting correctly.
*   **Test Changes**:\
    After editing, test the configuration without rebooting by running:

    ```bash
    sudo mount -a
    ```

    This command attempts to mount all filesystems specified in `/etc/fstab` and helps catch errors.
* **Comment and Document**:\
  Add comments to explain non-standard mount options or the purpose of specific entries. This practice aids in system maintenance and troubleshooting.

## Conclusion

The `/etc/fstab` file is vital for automating the mounting of filesystems during system boot, ensuring that local and network storage devices are available and correctly configured. By understanding its format and following best practices, administrators can maintain a stable, secure, and efficient system environment.
