Add a New Disk to Ubuntu Server: Partition, Format and Mount

1. Identify the disk:

lsblk
sudo fdisk -l

2. Create the partition (example: /dev/sdd):

sudo fdisk /dev/sdd
g          # new GPT partition table (empty disk)
n          # new partition
<Enter>    # default number
<Enter>    # default start
<Enter>    # use the whole disk
w          # write and exit

3. Format as ext4:

sudo mkfs.ext4 /dev/sdd1

4. Mount it (/srv is meant for service data):

sudo mkdir -p /srv/data
sudo mount /dev/sdd1 /srv/data
df -h

5. Permissions for the service user:

sudo chown -R user:user /srv/data
sudo chmod 755 /srv/data
ls -ld /srv/data

6. Make it permanent in /etc/fstab:

sudo blkid /dev/sdd1

Add a line with that UUID:

UUID=YOUR_UUID   /srv/data   ext4   defaults,nofail   0   2

nofail lets the server boot even if the disk is missing. Test without rebooting:

sudo systemctl daemon-reload
sudo mount -a

No errors means the fstab entry is correct.

Related: list disks and partitions and extend a disk.

Written by Daniel Ruiz Peláez, Systems & Infrastructure Engineer (Linux, VMware, Proxmox, Active Directory, networking and security). These are notes from real problems I have solved.

← Back to all posts