Manage Disk Partitions and LVM on Linux VPS

Manage Disk Partitions and LVM on Linux VPS

June 2026 · 8 min read

When your VPS disk fills up or you need additional storage, understanding disk partitions and LVM (Logical Volume Manager) helps you expand capacity without reformatting or causing downtime. This article covers checking current disk status, adding new disks, and resizing LVM volumes safely.

View Current Disk Status

# View all disks and partitions
lsblk

# View disk space usage
df -h

# View detailed partition information
sudo fdisk -l

# View filesystem type
lsblk -f

Add a New Disk with fdisk

When your VPS provider adds a new volume (e.g., /dev/vdb), you must create a partition and format it before use:

# Open fdisk on the new disk
sudo fdisk /dev/vdb

# In fdisk, type in order:
n   # Create new partition
p   # Primary partition
1   # Partition number 1
    # Enter = use default (first sector)
    # Enter = use default (last sector = entire disk)
w   # Write and exit
# Format as ext4
sudo mkfs.ext4 /dev/vdb1

# Mount temporarily
sudo mkdir /mnt/data
sudo mount /dev/vdb1 /mnt/data

# Mount permanently (add to /etc/fstab)
echo "UUID=$(blkid -s UUID -o value /dev/vdb1) /mnt/data ext4 defaults 0 2" | sudo tee -a /etc/fstab

Extend Root Partition with LVM

If your VPS uses LVM (check with lsblk -f and look for lvm type), expansion is much simpler:

# View logical volumes
sudo lvdisplay
sudo vgdisplay

# View physical volumes
sudo pvdisplay

# Extend the logical volume to use all remaining space
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

# Resize the filesystem to recognize new space
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
Tip: Before resizing, always create an LVM snapshot or request a backup through your VPS control panel. A typo in the device name could result in data loss.

Add a Physical Volume to LVM Group

# After adding a new disk /dev/vdb to LVM
sudo pvcreate /dev/vdb1
sudo vgextend ubuntu-vg /dev/vdb1

# Check that VG has additional space
sudo vgdisplay | grep "Free  PE"

# Extend LV to use the new space
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv

Verify Disk is Working Correctly

# Check mounted filesystems
df -h

# Detailed LVM check
sudo lvs
sudo vgs
sudo pvs

# Check disk health (SMART)
sudo apt install smartmontools -y
sudo smartctl -a /dev/sda

# Check for filesystem errors
sudo dmesg | grep -i "error\|I/O error" | tail -20
Tip: Set a disk usage alert at 80% to give you time to plan expansion before running out of space: df -h | awk '$5 > "80%" {print "DISK ALERT:", $0}'

Common Issues & Troubleshooting

Error: "No space left on device" when df -h shows free space

This typically means you've run out of inodes (common on servers with many small files, such as mail servers or session directories):

# Check inode usage
df -i

# Find directories with the most files
find / -xdev -printf '%h\n' | sort | uniq -c | sort -rn | head -10

# Delete unwanted files (e.g., old sessions)
find /var/lib/php/sessions -mtime +7 -delete

mount: wrong fs type or bad superblock

The format did not complete successfully or the disk has problems. You need to reformat:

# Check the current filesystem type
sudo blkid /dev/vdb1

# If you need to reformat (all data will be erased)
sudo mkfs.ext4 -F /dev/vdb1

# Check for filesystem errors
sudo e2fsck -f /dev/vdb1

resize2fs: device or resource busy

You cannot resize a root filesystem while it is mounted. You need to use Live mode or use resize2fs with online resize capability:

# ext4 supports online resize
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv

# If you get an error, unmount first (for non-root partitions)
sudo umount /mnt/data
sudo e2fsck -f /dev/vdb1
sudo resize2fs /dev/vdb1

Disk suddenly full — can't find the culprit

A deleted file still open by a process will continue consuming space. You must restart that process:

# Find deleted files still held by processes
sudo lsof | grep deleted | awk '{print $7, $1, $2}'

# Restart the process holding the file (e.g., nginx holding old logs)
sudo systemctl restart nginx

Frequently Asked Questions

How does LVM differ from regular partitions?

Regular partitions (MBR/GPT) divide the physical disk directly and are difficult to expand without reformatting. LVM is an abstraction layer on top of partitions that allows you to expand, move, and snapshot volumes without reformatting. Most VPS orders come with LVM already configured.

Do I need to reboot after resizing a partition?

LVM + ext4/xfs support online resizing — no reboot needed. However, if you extend a non-LVM partition using fdisk/parted, some cases require a reboot for the kernel to recognize the new partition table. Try running sudo partprobe first to reload the table without rebooting.

How large should a swap partition be?

For modern VPS: RAM ≤ 2GB → swap = 2× RAM, RAM 2–8GB → swap = RAM, RAM > 8GB → 4GB is sufficient. Alternatively, use a swapfile instead of a partition for more flexibility (see the article Set Up Swap Memory on Linux VPS).