Persistent Partition Mounting in Linux: Automating /etc/fstab Configuration for /dev/sda3


2 views

When working with additional partitions in Linux systems, manually executing mount commands after each reboot becomes tedious. Let's examine how to permanently mount /dev/sda3 as an ext3 filesystem at /foo.

The /etc/fstab file controls automatic mounting at boot time. Each entry follows this structure:

<file system> <mount point> <type> <options> <dump> <pass>

For our specific case of mounting /dev/sda3, add this line to /etc/fstab:

/dev/sda3    /foo    ext3    defaults    0    2

After editing /etc/fstab, always verify with these commands:

sudo mount -a        # Tests fstab entries without rebooting
findmnt /foo         # Checks if mount succeeded
lsblk -f             # Verifies filesystem type

For more control, consider these alternatives:

# Using UUID instead of device path (more reliable):
UUID=1234-5678    /foo    ext3    noatime,errors=remount-ro    0    2

# For encrypted partitions:
/dev/mapper/crypt_sda3    /foo    ext3    defaults    0    2

If mounting fails at boot:

  1. Check dmesg | grep sda3 for hardware errors
  2. Verify filesystem integrity with fsck
  3. Ensure mount point directory exists (mkdir -p /foo)

For systemd-based systems, you can create a mount unit:

# /etc/systemd/system/foo.mount
[Unit]
Description=Mount /dev/sda3 at /foo

[Mount]
What=/dev/sda3
Where=/foo
Type=ext3
Options=defaults

[Install]
WantedBy=multi-user.target

Then enable it with:

sudo systemctl enable --now foo.mount

The standard method for persistent mounting is through the /etc/fstab file. This system file contains information about filesystems and their mount points. Here's how to implement it:

# Open fstab with your preferred editor
sudo nano /etc/fstab

# Add this line for an ext3 partition:
/dev/sda3    /foo    ext3    defaults    0    2

Breakdown of the fields:

1. Device identifier (/dev/sda3)
2. Mount point (/foo)
3. Filesystem type (ext3)
4. Mount options (defaults)
5. Dump flag (0 for no backup)
6. Filesystem check order (2 for non-root partitions)

For more reliability (since device names might change), use UUID instead:

# First find your partition's UUID:
sudo blkid /dev/sda3

# Then use in fstab:
UUID=1234-abcd-5678-efgh   /foo   ext3   defaults   0   2

For systems using systemd, you can create a mount unit:

# Create a mount unit file
sudo nano /etc/systemd/system/foo.mount

[Unit]
Description=Mount foo partition

[Mount]
What=/dev/sda3
Where=/foo
Type=ext3
Options=defaults

[Install]
WantedBy=multi-user.target

Then enable it:

sudo systemctl enable foo.mount
sudo systemctl start foo.mount

After modifying fstab or creating mount units, always test:

# Test fstab entries without rebooting
sudo mount -a

# Check if mounted correctly
mount | grep /foo
df -h

Common issues and fixes:

# If filesystem checks fail:
fsck -y /dev/sda3

# If mount point doesn't exist:
sudo mkdir -p /foo

For specific needs, customize mount options:

# Example with specific options:
UUID=1234-abcd   /foo   ext3   noatime,nodiratime,data=writeback   0   2

# NFS example:
nas:/share   /mnt/share   nfs   rw,soft,intr,rsize=8192,wsize=8192   0   0