Skip to content
Commitpedia
Log in Join & edit

Add a new disk: partition, format and mount it by UUID

Find a new disk with lsblk, partition it with parted, create an ext4 or XFS filesystem and mount it permanently through /etc/fstab using its UUID.

Not checked by a trusted editor yet Last edited Outdated?

Edit history of Add a new disk: partition, format and mount it by UUID: 1 recorded edit
Edit history · 1 edit
Type
Article
Edits
1
Editors
1
First issued
15 Oct 2026
Last edit
15 Oct 2026
Reading
3 min

You attached a new disk to a server (a physical drive or a virtual disk on a VM) and want it mounted at /srv/data. The steps are the same on Debian, Ubuntu, RHEL, Rocky and AlmaLinux: identify the disk, create a partition, put a filesystem on it, and add one line to /etc/fstab.

Warning: partitioning and formatting destroy everything on the target device. Picking the wrong disk is the classic mistake. Do every check in step 1 before running any command that writes.

1. Identify the new disk

lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS
lsblk -f

Example output:

NAME   SIZE TYPE FSTYPE MOUNTPOINTS
sda     40G disk
├─sda1   1G part xfs    /boot
└─sda2  39G part LVM2_member
  ├─rl-root 35G lvm xfs /
  └─rl-swap  4G lvm swap [SWAP]
sdb    100G disk

The new disk is the one with the expected size, no partitions, no filesystem and no mount point; here /dev/sdb. On VMs it may be /dev/vdb, on NVMe /dev/nvme1n1 (partitions are then nvme1n1p1). Confirm the disk carries no data signatures; with no options, wipefs only lists them and changes nothing:

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
sudo wipefs /dev/sdb        # no output = no known filesystem or partition table

If it lists anything, stop and find out what is on that disk before continuing.

2. Create a partition table and one partition

parted can do this in one non-interactive command. GPT is the right choice for new disks, and starting at 1MiB keeps the partition aligned:

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
sudo parted -s -a optimal /dev/sdb mklabel gpt mkpart data ext4 1MiB 100%
sudo parted /dev/sdb print

data is the GPT partition name and ext4 is only a type hint; parted does not format the partition. That happens in step 3.

If you prefer an interactive tool, sudo fdisk /dev/sdb works too: g creates a GPT table, n a new partition (accept the defaults to use the whole disk), p prints, and w writes and quits. Nothing is written before w.

3. Create a filesystem

RHEL and its rebuilds default to XFS; Debian and Ubuntu default to ext4. Both are fine. Remember that XFS can grow but cannot be shrunk.

Check before you run this

  • Formats or repartitions a disk and erases its data.
  • Runs with administrator rights. Make sure you understand every line.
# ext4
sudo mkfs.ext4 -L data /dev/sdb1

# or XFS
sudo mkfs.xfs -L data /dev/sdb1

4. Find the UUID

Device names such as /dev/sdb can change when disks are added or removed, so fstab should refer to the filesystem’s UUID, which stays the same.

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
sudo blkid /dev/sdb1
# /dev/sdb1: LABEL="data" UUID="0f1e2d3c-4b5a-6978-8a9b-0c1d2e3f4a5b" TYPE="ext4" ...

5. Add the fstab entry

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
sudo mkdir -p /srv/data
sudo cp /etc/fstab /etc/fstab.bak
sudo nano /etc/fstab

Add one line (use your UUID):

UUID=0f1e2d3c-4b5a-6978-8a9b-0c1d2e3f4a5b  /srv/data  ext4  defaults,nofail  0  2

The six fields are: what to mount, where, filesystem type, mount options, dump flag (0) and fsck order (1 for the root filesystem, 2 for others, 0 to skip). nofail lets the server finish booting even if this disk is missing, which is a good idea for data disks; leave it off for disks the system cannot run without.

6. Test before you reboot

A broken fstab line can stop the server at boot and drop it into emergency mode. Test now, while you still have a shell:

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
sudo findmnt --verify          # checks /etc/fstab for errors
sudo systemctl daemon-reload   # systemd builds mount units from fstab
sudo mount -a                  # mounts everything in fstab that is not mounted yet
findmnt /srv/data
df -h /srv/data

If mount -a or findmnt --verify reports an error, fix the line (or restore /etc/fstab.bak) before rebooting.

7. Set ownership

Check before you run this

  • Runs with administrator rights. Make sure you understand every line.
sudo chown appuser:appuser /srv/data

Should I use LVM instead?

If the data may grow, consider putting LVM on the new disk instead of a plain partition. It lets you extend the volume later, also across several disks, without unmounting. See the LVM concept entry.

Official documentation

See also

  • 0102 Proxmox VE storage types: local, LVM-thin, ZFS, NFS and Ceph Proxmox VE stores disks, ISOs, templates and backups in storage pools defined in /etc/pve/storage.cfg. Learn the main storage types, what local and… Intermediate · Concept · Linux Article Disks, LVM & filesystems · Storage 15 Oct 2026
  • 0168 Server health check script: disk, memory and failed units A dependency-free bash script that checks disk and inode usage, available memory, load, failed systemd units and pending reboots, and exits non-zero… Intermediate · Reference · Linux Script Disks, LVM & filesystems · Services & systemd 15 Oct 2026
  • 0170 LVM explained: physical volumes, volume groups and logical volumes LVM puts a flexible layer between disks and filesystems, so you can grow volumes, add disks and take snapshots without repartitioning. Intermediate · Concept · Linux Article Disks, LVM & filesystems 15 Oct 2026
  • 0171 Extend an LVM logical volume and filesystem online (safe script) A bash script that grows the LVM volume behind a mount point, checks the filesystem type and free space first, and runs… Advanced · How-to · Linux Script Disks, LVM & filesystems 15 Oct 2026
  • 0172 Fix: No space left on device Writes fail because a filesystem is full, out of inodes, or holding space for deleted files that are still open. Find which… Beginner · Fix · Linux Article Disks, LVM & filesystems 15 Oct 2026

History

Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.

  1. Commitpedia +3,870 chars

Report a problem

Something wrong, unsafe or copied? Tell the editors.
What is wrong?