How to mount disks and configure fstab

Topic: Servers linux

Summary

Mount a disk or partition manually with mount, add an entry to /etc/fstab for boot mount, and verify with mount and df. Use this when adding data disks or moving data to a new volume so the system mounts it correctly after reboot.

Intent: How-to

Quick answer

  • Find the device: lsblk, blkid; create mount point mkdir /data; mount /dev/sdb1 /data; add line to /etc/fstab with UUID and options (defaults or nofail).
  • Use UUID= in fstab (blkid) so mounts survive device name changes; test with mount -a and reboot before relying on it.
  • If mount fails at boot, system may wait or go to emergency; use nofail if the disk is optional; fix fstab or disk then reboot or mount -a.

Prerequisites

Steps

  1. Identify the block device

    lsblk; blkid /dev/sdb1 to get UUID and TYPE; partition if needed with fdisk or parted; mkfs if new (e.g. mkfs.ext4).

  2. Create mount point and mount

    mkdir -p /data; mount /dev/sdb1 /data; df -h and ls /data to verify; umount /data to unmount.

  3. Add to fstab

    Get UUID from blkid; add line: UUID=xxx /data ext4 defaults 0 2; use nofail for optional disks; run mount -a to test.

  4. Verify after reboot

    Reboot or run mount -a; df must show the mount; check systemd logs if mount failed (e.g. systemctl status local-fs.target).

Summary

You will attach a disk or partition, mount it manually, add it to /etc/fstab for automatic mount at boot, and confirm it survives reboot. Use this when adding storage or migrating data to a new volume.

Prerequisites

  • Root or sudo; a disk or partition that is not in use (or can be unmounted).
  • Know whether the filesystem already exists or you need to create it (mkfs).

Steps

Step 1: Identify the block device

lsblk
blkid /dev/sdb1

Note the UUID and filesystem type. If the partition is new, create it (fdisk/gdisk/parted) and run mkfs.ext4 or mkfs.xfs as needed.

Step 2: Create mount point and mount

sudo mkdir -p /data
sudo mount /dev/sdb1 /data
df -h /data
ls /data

To unmount: sudo umount /data (ensure nothing is using it; use fuser or lsof if umount says busy).

Step 3: Add to fstab

sudo blkid /dev/sdb1
# Add to /etc/fstab (use UUID):
# UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /data ext4 defaults,nofail 0 2
sudo nano /etc/fstab
sudo mount -a
df -h /data

Use nofail if the disk may be missing at boot (e.g. USB); then the system will not hang waiting for it.

Step 4: Verify after reboot

sudo reboot
# After boot
df -h /data
mount | grep /data

If the mount is missing, check journalctl -u local-fs.target and fix the fstab line or disk (UUID, type, options).

Verification

  • mount and df show the filesystem on the correct path; after reboot the same; fstab line uses UUID and correct type and options.

Troubleshooting

Mount failed: wrong fs type or bad option — Check filesystem type (blkid); ensure the correct mkfs was used; check for typos in fstab (e.g. ext4 vs xfs).

Device does not exist — UUID may be wrong; disk may not be attached (cloud) or may have a different name (e.g. nvme); use nofail or fix the device id.

Mount point busy — Something is using the path; fuser -vm /data; stop services or close shells, then umount and remount.

Next steps

Continue to