Skip to content

Instantly share code, notes, and snippets.

@ilhamarrouf
Created October 16, 2025 02:44
Show Gist options
  • Save ilhamarrouf/9e11951d46f97163abfa6a33a0b60784 to your computer and use it in GitHub Desktop.
Save ilhamarrouf/9e11951d46f97163abfa6a33a0b60784 to your computer and use it in GitHub Desktop.
Increasing Disk LVM

You can increase a VMware Ubuntu Server disk size without rebooting the guest OS, but there are important caveats:

  • You can expand the virtual disk (.vmdk) while the VM is running (if VMware supports hot-extend).
  • But to make Ubuntu recognize and use the new space, you’ll need to rescan the disk and resize partitions/filesystems manually — all without rebooting.

Here’s the complete guide 👇


🧩 Step 1: Extend Disk in VMware

  1. Open VMware vSphere / Workstation / Fusion.

  2. Select your Ubuntu VM → Settings → Hard Disk.

  3. Increase the size (e.g., from 20 GB → 40 GB).

    • In vSphere, this can be done live (hot-extend) if the VM hardware supports it.
    • In Workstation, you might need to power off; check your VMware version.

🧰 Step 2: Rescan the Disk Inside Ubuntu (No Reboot)

SSH or open console to Ubuntu, then run:

sudo apt install -y parted
sudo parted -l

Find your main disk (example: /dev/sda).

Now rescan the disk:

echo 1 | sudo tee /sys/class/block/sda/device/rescan

Or more universally (using rescan-scsi-bus):

sudo apt install -y scsitools
sudo rescan-scsi-bus

Check the new size recognized:

lsblk

You should now see the updated disk size (but the partition may still be smaller).


🧩 Step 3: Extend the Partition (No Reboot)

If your root partition is on /dev/sda3, for example:

sudo growpart /dev/sda 3

Then verify:

lsblk

🧱 Step 4: Resize the Filesystem

For ext4:

sudo resize2fs /dev/sda3

For xfs:

sudo xfs_growfs /

✅ Step 5: Verify

df -h

You should now see the extra space added to /.


⚙️ Example (Typical Ubuntu LVM Setup)

If you use LVM (common in Ubuntu Server), do this instead of growpart:

sudo pvresize /dev/sda3
sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

The -r option automatically resizes the filesystem too.


🔄 Summary

Task Command
Rescan disk `echo 1 sudo tee /sys/class/block/sda/device/rescan`
Grow partition sudo growpart /dev/sda 3
Resize ext4 sudo resize2fs /dev/sda3
Resize xfs sudo xfs_growfs /
Resize LVM sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

You’re using LVM, with two logical volumes:

  • ubuntu-vg-ubuntu-lv (≈ 98 GB)
  • ubuntu-vg-data-lv (≈ 98 GB) backed by /dev/sda3 (≈ 197 GB physical volume).

Let’s make /dev/sda3 use the new space and extend your LVMs.


🧩 Step-by-step (No Reboot)

1️⃣ Rescan the disk to detect new size

echo 1 | sudo tee /sys/class/block/sda/device/rescan

Then check:

lsblk

You should see /dev/sda = 300G, /dev/sda3 = 197G (still smaller — that’s expected).


2️⃣ Grow the partition /dev/sda3 to fill the new space

Use growpart from cloud-guest-utils:

sudo apt install -y cloud-guest-utils
sudo growpart /dev/sda 3

Verify:

lsblk

Now /dev/sda3 should show ≈ 300 GB.


3️⃣ Resize the LVM Physical Volume

sudo pvresize /dev/sda3

Check with:

sudo pvdisplay

You should see Free PE > 0 (free space available for allocation).


4️⃣ Extend Your Logical Volume(s)

You have two options:

Option A — Extend one LV (e.g. root)

sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

→ automatically grows the filesystem.

Option B — Split the extra space manually

If you want to allocate some to ubuntu-lv and some to data-lv:

sudo lvextend -r -L +50G /dev/ubuntu-vg/ubuntu-lv
sudo lvextend -r -L +50G /dev/ubuntu-vg/data-lv

(Adjust the sizes as needed.)


5️⃣ Verify the Result

df -h
sudo lvdisplay

You should now see your logical volumes larger and the filesystem resized — no reboot required


🧠 Summary

Step Command
Rescan disk `echo 1 sudo tee /sys/class/block/sda/device/rescan`
Grow partition sudo growpart /dev/sda 3
Resize PV sudo pvresize /dev/sda3
Extend LV sudo lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Verify df -h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment