Expanding Ubuntu Server Disk Space
By default, Ubuntu Server installations often don't utilize all available disk space, leaving you with a smaller root filesystem than expected. This commonly occurs because Ubuntu uses LVM (Logical Volume Manager) and may not automatically extend the logical volume to fill the entire disk during installation.
The Problem
After installing Ubuntu Server, you might notice:
- The root filesystem (
/
) shows limited space usingdf -h
- Available disk space appears much smaller than your actual disk capacity
- The system reports low disk space warnings despite having a large physical disk
This happens because the Ubuntu installer creates a logical volume that doesn't span the entire volume group, leaving unallocated space unused.
Solution
To expand the disk to use all available space, run these two commands:
# Step 1: Extend the logical volume to use all free space
sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
# Step 2: Resize the filesystem to match the expanded logical volume
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
Command Explanation
Command 1: sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
lvextend
: LVM command to extend a logical volume-l +100%FREE
: Extends the volume by 100% of the free space available in the volume group/dev/mapper/ubuntu--vg-ubuntu--lv
: The default path to Ubuntu's root logical volumeubuntu--vg
: The volume group name (with hyphens replacing spaces)ubuntu--lv
: The logical volume name
Command 2: sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs
: Utility to resize ext2/ext3/ext4 filesystems/dev/mapper/ubuntu--vg-ubuntu--lv
: The logical volume containing the filesystem to resize- This command expands the filesystem to fill the newly extended logical volume
Verification
After running both commands, verify the expansion worked:
# Check filesystem usage
df -h /
# Check logical volume information
sudo lvdisplay
# Check volume group information
sudo vgdisplay
You should now see that your root filesystem (/
) utilizes the full available disk space.
When to Use This
- Fresh Ubuntu Server installations where disk usage seems unusually low
- After expanding a virtual machine's disk in hypervisors like VMware, VirtualBox, or cloud platforms
- When you see unallocated space in volume group displays but your root filesystem is small
Important Notes
- These commands are safe to run on a live system and won't cause data loss
- The resize operation happens online without requiring a reboot
- This procedure specifically applies to Ubuntu's default LVM setup with ext4 filesystem
- Always ensure you have backups before performing disk operations, though these commands are non-destructive
Alternative: Create Dedicated Volume for the View Software
Instead of expanding the root filesystem, you can create a separate logical volume mounted at /opt/View
specifically for the View software. This approach allows you to:
- Allocate exactly the amount of space you want for View
- Keep the system and application data separate
- Easily manage View-specific storage requirements
Steps to Create a Dedicated View Volume
-
Check available space in the volume group:
sudo vgdisplay ubuntu-vg
-
Create a new logical volume for View (replace
50G
with your desired size):sudo lvcreate -L 50G -n view-lv ubuntu-vg
-
Format the new logical volume with ext4:
sudo mkfs.ext4 /dev/mapper/ubuntu--vg-view--lv
-
Create the mount point:
sudo mkdir -p /opt/View
-
Mount the volume:
sudo mount /dev/mapper/ubuntu--vg-view--lv /opt/View
-
Make the mount permanent by adding to
/etc/fstab
:echo '/dev/mapper/ubuntu--vg-view--lv /opt/View ext4 defaults 0 2' | sudo tee -a /etc/fstab
-
Verify the mount:
df -h /opt/View
Benefits of This Approach
- Flexible sizing: Allocate exactly the space you need for View software
- Isolation: Keep View data separate from system files
- Easy management: Can easily extend or manage the View volume independently
- Better organization: Clear separation between system and application storage
Example Size Allocations
- Small deployment: 50G-100GB
- Medium deployment: 100-200GB
- Large deployment: 500GB or more
Choose the size based on your expected View data storage requirements.
Updated 7 days ago