Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Configure fstab on a Raspberry Pi for Automatic Mounting of Drives

The fstab (file systems table) is a configuration file in Linux-based systems, including Raspberry Pi OS, that contains information about different filesystems and how they should be automatically mounted by the system. Configuring fstab is crucial for ensuring that external drives, network shares, or additional partitions are mounted consistently every time the Raspberry Pi boots up.

Understanding fstab Structure

The fstab file is located at /etc/fstab and consists of lines with six fields each. These fields are:

  1. Filesystem: The device or remote filesystem to be mounted.
  2. Mount Point: The directory where the filesystem will be mounted.
  3. Type: The filesystem type (e.g., ext4, vfat, ntfs).
  4. Options: Mount options (e.g., defaults, nofail, noatime).
  5. Dump: A number indicating whether the filesystem should be dumped (backup) by the dump command.
  6. Pass: A number indicating the order in which filesystems should be checked at boot time by fsck.

Examples

  1. Mounting an External USB Drive

    Suppose you have an external USB drive formatted with the ext4 filesystem, and you want it to mount automatically at boot. First, identify the drive using the lsblk or blkid command:

    lsblk

    Assume the drive is /dev/sda1. Create a mount point:

    sudo mkdir /mnt/usbdrive

    Add the following line to /etc/fstab:

    /dev/sda1 /mnt/usbdrive ext4 defaults,nofail 0 2

    This configuration will mount the USB drive at /mnt/usbdrive with default options and ensure it doesn't prevent booting if the drive is not present (nofail).

  2. Mounting a Network Share

    To mount a network share using NFS, first ensure the necessary packages are installed:

    sudo apt update
    sudo apt install nfs-common

    Create a mount point:

    sudo mkdir /mnt/nfs_share

    Add the following line to /etc/fstab:

    192.168.1.100:/sharedfolder /mnt/nfs_share nfs defaults 0 0

    Replace 192.168.1.100:/sharedfolder with the actual NFS server IP and shared folder path.

  3. Mounting a Windows Share (CIFS/SMB)

    Install the necessary package:

    sudo apt install cifs-utils

    Create a mount point:

    sudo mkdir /mnt/windows_share

    Add the following line to /etc/fstab:

    //192.168.1.100/sharedfolder /mnt/windows_share cifs username=user,password=pass,iocharset=utf8,sec=ntlm 0 0

    Replace 192.168.1.100/sharedfolder with the actual IP and share name, and user and pass with the appropriate credentials.

Testing the Configuration

After editing /etc/fstab, test the configuration without rebooting:

sudo mount -a

This command attempts to mount all filesystems mentioned in fstab. If there are errors, they will be displayed in the terminal, allowing you to troubleshoot before rebooting.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.