Sub topic 5
Using Space from an Enlarged Virtual or Cloud Disk
This chapter assumes you can use the Linux command line with sudo, identify block devices and partitions, and read lsblk and df output. It also assumes the disk has already been enlarged in your cloud provider or virtualization platform. Linux cannot use the extra capacity until it detects the larger disk, partition, and LVM physical volume.
An enlarged disk adds capacity in layers:
- The virtual disk becomes larger in the cloud platform.
- Linux rescans the disk and sees the new device size.
- The partition containing the LVM physical volume grows.
- LVM updates the physical volume with
pvresize. - The volume group gains free extents.
- You extend the logical volume and its filesystem.
Identify the disk and LVM layer
Before changing a partition, confirm the device name and the partition that contains the physical volume. Device names such as /dev/sda and /dev/sdb are not guaranteed to remain the same across reboots or cloud changes. Never copy an example device path without checking your server.
Use these commands:
sudo pvs
sudo vgs
sudo lvs
lsblk -f
df -hT /srv/dataSuppose the output shows /dev/sda3 as a physical volume in vg_data, and /srv/data uses a logical volume from that group. The complete storage path might look like this:
| Layer | Example | Purpose |
|---|---|---|
| Disk | `/dev/sda` | The virtual or physical disk |
| Partition | `/dev/sda3` | The partition holding LVM data |
| Physical volume | `/dev/sda3` | The disk space managed by LVM |
| Volume group | `vg_data` | A pool of physical volume space |
| Logical volume | `/dev/vg_data/lv_app` | A virtual block device for the filesystem |
| Filesystem | XFS on `/srv/data` | Stores directories and files |
The important distinction is between disk size, partition size, physical volume size, logical volume size, and filesystem size. A larger value at one layer does not automatically enlarge the next layer.
Rescan the enlarged disk
After the provider reports that the disk is larger, ask Linux to rescan it. For a SCSI-style device named sda, run:
echo 1 | sudo tee /sys/class/block/sda/device/rescan
lsblkThe lsblk output should show the new size for /dev/sda. If it still shows the old size, check the provider operation, the device name, and the virtual machine's storage interface. Some environments detect the change automatically, while others require a reboot.
Grow the partition
If the physical volume occupies a partition, the partition must fill the newly available disk space. The growpart command is commonly provided by the cloud-guest-utils package.
For a physical volume on partition 3:
sudo growpart /dev/sda 3
lsblkThe syntax separates the disk and partition number. Use /dev/sda and 3, not /dev/sda3, as the two arguments.
growpart changes the partition boundary. It does not change the LVM physical volume metadata. Check the result with lsblk before continuing.
If the physical volume was created directly on the whole disk, such as /dev/sdb, there is no partition to grow. In that case, skip growpart and use pvresize /dev/sdb after Linux sees the larger disk.
Partition layouts can have constraints. For example, another partition may exist after the LVM partition, preventing it from expanding into the available space. A partitioning tool may then be required, and the safest procedure depends on the layout. Do not delete or recreate a partition simply to make it larger.
Update the physical volume
Once the partition is larger, tell LVM to examine the new size:
sudo pvresize /dev/sda3
sudo vgspvresize updates the physical volume metadata. It does not resize any logical volume or filesystem. The expected result is that the VFree column for vg_data increases.
You can inspect the details with:
sudo pvs
sudo vgs vg_dataIf pvresize says the device has not changed, verify all earlier layers:
- The cloud disk was actually enlarged.
- Linux reports the larger disk in
lsblk. - The correct partition was grown.
- The physical volume path is correct.
- The partition is not blocked by another partition.
At this point, the new capacity is available to the volume group. It is not yet available to applications. The next operation is to extend a logical volume into the new free space, then grow its filesystem.
Plan the next resize
You can extend a logical volume by a fixed amount, such as 20G, or use all free space in the volume group. A fixed amount leaves room for future logical volumes and snapshots. Using all free space is convenient but removes that reserve.
For example:
sudo lvextend -L +20G /dev/vg_data/lv_appOr:
sudo lvextend -l +100%FREE /dev/vg_data/lv_appThe lowercase -l option works with logical extents, which are LVM allocation units. The uppercase -L option works with a size. These commands extend only the logical volume. You must also grow the filesystem, using resize2fs for ext4 or xfs_growfs for XFS.
Exercise
A cloud disk grew from 100 GiB to 150 GiB. lsblk shows that /dev/sda is 150 GiB, but /dev/sda3 is still 100 GiB. What should you do before extending a logical volume?
Show answer
Grow partition 3 with sudo growpart /dev/sda 3, then run sudo pvresize /dev/sda3 and confirm that the volume group's free space increased with sudo vgs.