Disks and Partitions: Check Space, Mount a Data Disk, Auto-Mount at Boot

From reading disk usage to partitioning, formatting, and permanently mounting a new data disk — step by step.

Attached a data disk to your server but not sure how to use it? This guide walks you through checking disk space, partitioning and formatting a new disk, and adding it to /etc/fstab so it mounts automatically at boot. Commands target Ubuntu/Debian.

First, See What You Have

Check used and available space per mount point. -h prints sizes in human-readable units:

df -h

To find out what's actually eating space inside a directory, use du:

du -sh /var/*        # summarize each subdirectory
du -sh /var/log      # total size of one directory

To list the disks and partitions on your server, lsblk gives a clear tree view:

lsblk

In the output, sda or vda is a whole disk, while sda1 or vda1 is a partition on it. The system disk is usually already mounted at /. A freshly attached data disk typically shows up as sdb or vdb, with no partitions and no mount point yet.

> Warning: the partitioning and formatting steps below erase everything on the target device, and there is no undo. Before you touch anything, run lsblk and double-check the device name so you're certain you have the empty new disk — never the system disk or a disk that already holds data. Back up anything important first.

Partition and Format the New Disk

Assume the new data disk is /dev/sdb (replace it with what your own lsblk shows). Use parted to create a partition table and one partition spanning the whole disk:

sudo parted /dev/sdb --script mklabel gpt
sudo parted /dev/sdb --script mkpart primary ext4 0% 100%

Run lsblk again to confirm sdb1 now exists. Then format it with an ext4 filesystem:

sudo mkfs.ext4 /dev/sdb1

Mount It and Make It Stick

Create a mount point and test the mount manually:

sudo mkdir -p /data
sudo mount /dev/sdb1 /data
df -h /data          # if /data shows up, it worked

A manual mount is lost on reboot. To mount automatically at boot, add it to /etc/fstab. Use the UUID rather than /dev/sdb1, because device names can shift across reboots while the UUID stays fixed:

sudo blkid /dev/sdb1     # note the UUID="...."

Edit /etc/fstab and append one line (swap in your real UUID):

UUID=your-uuid-here  /data  ext4  defaults  0  2

Before rebooting, verify the entry — a typo here can leave the server unable to boot:

sudo umount /data
sudo mount -a           # no errors means fstab is valid
df -h /data

mount -a mounts every entry in /etc/fstab. If this step throws an error, go back and fix the spelling on that fstab line, and only reboot once it's correct.

Summary

  • df -h for space, du -sh to hunt down space hogs, lsblk to see disks and partitions.
  • New-disk flow: parted to partition, mkfs.ext4 to format, mount to attach, then /etc/fstab to make it permanent.
  • Partitioning and formatting wipe data irreversibly — verify the device name and back up before you start; use a UUID in fstab and run mount -a to validate before rebooting.