How to Mount Disks on a Debian Server and Manage Reserved Space

Key Takeaway:
By partitioning, formatting, mounting, and configuring entries in /etc/fstab, you can flexibly mount disks of different sizes. Use tune2fs to adjust the reserved block percentage on ext4 file systems to balance space utilization and system stability.


1. Basic Process for Mounting a Disk

  1. Identify the New Disk Device
    Use lsblk or fdisk -l to confirm the newly recognized disk (e.g., /dev/sdb, /dev/sdc).

  2. Create a Partition
    Use fdisk (for MBR) or parted (for GPT, recommended for disks larger than 2 TB) to partition the disk:

    # Example: Create a primary partition on /dev/sdb
    fdisk /dev/sdb
    # In fdisk interactive mode, enter: n → p → 1 → <Enter> → <Enter> → w
  3. Format the File System
    The ext4 file system is commonly used:

    mkfs.ext4 /dev/sdb1
  4. Create a Mount Point

    mkdir -p /mnt/data
  5. Test a Temporary Mount

    mount /dev/sdb1 /mnt/data
    df -h /mnt/data
  6. Configure Automatic Mount at Boot
    Edit /etc/fstab and add:

    /dev/sdb1   /mnt/data   ext4   defaults   0 2

    Then run mount -a to verify.


2. Considerations for Different Disk Sizes

  • Disks Smaller than 2 TB:

    • Use MBR partitioning (via fdisk).
    • No special alignment is required for ext4 performance.
  • Disks Larger than 2 TB or NVMe SSDs:

    • Use GPT partitioning (via parted).
    • Align partitions on 1 MiB boundaries for optimal SSD performance:
      parted /dev/sdc mklabel gpt
      parted /dev/sdc mkpart primary ext4 1MiB 100%
  • Multiple Disks with LVM or RAID:

    • For flexible expansion or redundancy, create physical volumes on each partition, then combine them into an LVM volume group or software RAID array before creating logical volumes and file systems.

3. Purpose and Trade-Offs of Reserved Space

  • Reserved Blocks:
    ext4 reserves 5% of total blocks by default.

    • Purpose: Prevent the file system from filling completely, which can disrupt system services (e.g., log writes, SSH access, root operations).
    • Especially important on root partitions.
  • Drawbacks of Reserved Space:

    • On large data disks (several TB), 5% can amount to tens or hundreds of gigabytes of wasted space.
    • If the disk is used solely for general data storage and slightly lower safety margins are acceptable, consider reducing or disabling reserved space.

4. Viewing and Adjusting Reserved Space

  1. View the Current Reserved Percentage

    tune2fs -l /dev/sdb1 | grep 'Reserved block count\|Block count'
  2. Adjust the Reserved Percentage

    • Set by percentage (e.g., to 1%):
      tune2fs -m 1 /dev/sdb1
    • Set by absolute block count (e.g., reserve 1 GiB):
      # Assuming a block size of 4 KiB, 1 GiB = 262144 blocks
      tune2fs -r 262144 /dev/sdb1
  3. Disable Reserved Space

    tune2fs -m 0 /dev/sdb1

After adjustment, run df -h again to observe the change in available space.


5. Complete Example

Assume a new 4 TB disk /dev/sdd is added for pure data storage with no reserved space required:

# 1. Partition (GPT, 1 MiB alignment)
parted /dev/sdd mklabel gpt
parted /dev/sdd mkpart primary ext4 1MiB 100%

# 2. Format
mkfs.ext4 /dev/sdd1

# 3. Disable reserved space
tune2fs -m 0 /dev/sdd1

# 4. Create mount point
mkdir -p /data

# 5. Configure fstab (use UUID for reliability)
blkid /dev/sdd1
# Example output: UUID="abcd-1234" TYPE="ext4"
echo 'UUID="abcd-1234"  /data  ext4  defaults  0  2' >> /etc/fstab

# 6. Mount and verify
mount -a
df -h /data

Summary

Follow the sequence Partition → Format → Mount → fstab Configuration to mount a disk. The main difference between small disks (< 2 TB) and large disks (> 2 TB) lies in partition type (MBR vs GPT) and alignment. Adjust ext4 reserved space using tune2fs -m <percent> or -r <blocks> to strike the right balance between system safety and storage efficiency.

Mount Disk and Manage Reserved Space

Author

Shayne Wong

Publish Date

10 - 21 - 2025

License

Shayne Wong

Avatar
Shayne Wong

All time is no time when it is past.