When extra storage is attached to a VPS, Linux sees a new empty block device, but it cannot hold files until you partition, format and mount it. This guide shows the safe way to do that and make the mount permanent.
Before you start
- Root or sudo access over SSH.
- The new disk attached to the VPS. If your existing disk was enlarged instead, grow it as shown in LVM basics.
- A current backup (see back up a Linux VPS).
Danger: Formatting erases a disk. Triple-check the device name: formatting the system disk by mistake destroys the server.
Find the new disk
lsblk -fThe system disk has partitions mounted at paths like /. The new disk, for example /dev/vdb or /dev/sdb, has no partitions and no filesystem.
Create a partition
sudo parted /dev/vdb --script mklabel gpt mkpart primary 0% 100%This creates /dev/vdb1 covering the whole disk. Confirm with lsblk.
Format the partition
sudo mkfs.ext4 /dev/vdb1ext4 is the usual choice on Ubuntu and Debian; XFS (sudo mkfs.xfs /dev/vdb1) is the default on AlmaLinux and Rocky Linux. Both work well.
Mount it
sudo mkdir -p /data
sudo mount /dev/vdb1 /data
df -h /dataMake the mount permanent
Device names can change between boots, so mount by UUID:
sudo blkid /dev/vdb1Add a line to /etc/fstab (see editing files with nano and vim):
UUID=your-uuid-here /data ext4 defaults,nofail 0 2nofail lets the server still boot if the disk is missing. Test without rebooting:
sudo umount /data
sudo mount -a
findmnt /dataWarning: If mount -a prints an error, fix /etc/fstab before rebooting. A broken fstab can stop the VPS from booting.
Set ownership
The new filesystem belongs to root. Give your app user access with sudo chown -R deploy:deploy /data (see chown).
Troubleshooting
- wrong fs type, bad option: the type in fstab does not match what
blkidreports. - target is busy when unmounting: a shell or process uses the folder. Run
cd /and checksudo lsof +D /data. - Disk not visible: reboot the VPS from your control panel, or open a support ticket.
