← Back to Dashboard
Storage Administration

Emergency Disk Recovery & LVM Expansion Guide

Comprehensive workflow for handling disk expansion and LVM management on Ubuntu during "Disk Full" scenarios.

1. Emergency: Freeing Space for Utilities

If the disk is 100% full, apt cannot download the tools required to fix the problem.

Case A: Manual Cleanup

Clear the package cache and old logs to gain immediate breathing room:

sudo apt-get clean
sudo apt-get autoremove -y
sudo journalctl --vacuum-size=50M

Case B: The RAM Disk Hack

If cleanup isn't enough, mount 50MB of RAM over the apt archives folder to allow package downloads:

sudo mount -t tmpfs -o size=50m tmpfs /var/cache/apt/archives

2. Expanding Partitions (Non-LVM)

Use growpart to expand a partition within an existing disk (e.g., after increasing a virtual disk size in your hypervisor).

Installation

sudo apt update
sudo apt install cloud-guest-utils -y

Execution

# Note the space between device and partition number
sudo growpart /dev/sda 1

3. LVM Management (Adding New Capacity)

Use this workflow to add a new partition or unallocated space from /dev/sda into an existing Volume Group.

Step 1: Create a New Partition

If you aren't growing an existing one, create a new one for LVM use:

  1. Run sudo fdisk /dev/sda.
  2. Type n (new), p (primary), then Enter for defaults.
  3. Type t (type), select the partition number, then enter 8e (Linux LVM).
  4. Type w (write) and exit.
  5. Run sudo partprobe /dev/sda to refresh.

Step 2: Initialize Physical Volume (PV)

sudo pvcreate /dev/sdaX  # Replace X with your partition number

Step 3: Extend Volume Group (VG)

Find your VG name first using vgs.

sudo vgextend <your-vg-name> /dev/sdaX

Step 4: Extend Logical Volume (LV)

Find your LV path using lvs (e.g., /dev/ubuntu-vg/ubuntu-lv).

# Add all available free space from the VG to the LV
sudo lvextend -l +100%FREE /dev/mapper/your--lv--path

4. Final Step: Resizing the Filesystem

The partition and LVM are now larger, but the filesystem must be "stretched" to see the space.

Filesystem Type Command
ext4 sudo resize2fs /dev/mapper/your--lv--path
XFS sudo xfs_growfs / (or the mount point)

Summary of Commands