103 ‐ Resizing Block Volumes - SanjeevOCI/Ocidocs GitHub Wiki
Resize and Extend Block Volumes on OCI Compute Instances
Applies to: OCI Linux compute instances with OCID block volumes
Goal: Increase a block volume’s size and extend the filesystem on the instance so that extra space becomes usable.
✅ Prerequisites
- A running OCI Compute instance with a block volume attached (e.g.
/dev/sdb) - Sudo access on the Linux instance
- Current block volume size (e.g. 50 GB)
- Understanding of partitions, logical volumes (if applicable), and filesystems (e.g. ext4, XFS)
First step is to resize the block volume in OCI
Step 1 : Increase size in console.
Note :- The existing size is 50 GB.
- Select the Edit option on the Block Volume page.
- Enter the new size you want for the volume and click on save changes.
Step 2 : Increase Disk Size
After saving the changes, we get the "Resize Block Volume" box containing the volume rescan commands, as shown below. These 2 commands need to be copied and run in the Linux server(via Putty) to increase the size of the block volume.
Note :- After running the volume rescan commands, we also need to extend the partition for the volume resize to take effect
- Before running the volume rescan commands, we need to check the size of block volume using "lsblk" command
lsblk
- We also need to run the command "lsblk -ap /dev/sdb | head -2" to check the current size of the specific disk, which we want to increase
lsblk -ap /dev/sdb | head -2
- This is an important step. We need to **Edit **the copied rescan commands according to the actual disk name in the Linux we want to upgrade
Copied rescan commands
sudo dd iflag=direct if=/dev/oracleoci/oraclevdb of=/dev/null count=1
echo "1" | sudo tee /sys/class/block/`readlink /dev/oracleoci/oraclevdb | cut -d'/' -f 2`/device/rescan
Updated rescan commands
sudo dd iflag=direct if=/dev/sdb of=/dev/null count=1
echo "1" | sudo tee /sys/class/block/sdb/device/rescan
- Run the lsblk command to check whether the disk size is increased or not
lsblk
lsblk -ap /dev/sdb | head -2
- We can see that the disk size is increased
- However, logical volume & partition size is still not increased
Step 3 : Verify in Linux server whether the partition exists
Run the command "sudo parted /dev/sdb print" to check the Disk and the partition size
sudo parted /dev/sdb print
In the output shown below, we can see that the disk size has increased, but the partition size remains the same as before.
Note :- Even though we are increasing the volume size from 50 to 70 GB, the disk size shows as 75.2 GB. This is coz Oracle gives some extra space.
Step 4 : **Grow **the partition size to the new size - 70 GB
- Use the command "sudo growpart /dev/sdb 1" to grow the partition
sudo growpart /dev/sdb 1
- We are able to see both the old and new size of partition
- Again run the partition command and check the size of part. The size of the partition is now increased.
sudo parted /dev/sdb print.
- Run lsblk command and check size of disk and partition
lsblk
As we can see, the size of disk and partition has increased, but logical volume
- Now, run the command to display detailed information about a specific logical volume (lv_u01) in a volume group (vg_u01)
lvdisplay -am /dev/mapper/vg_u01-lv_u01
The logical volume is still the same as before; it has not increased yet
- Next step is to Resize the Physical Volume using the below commands
pvresize /dev/sdb1
pvdisplay /dev/sdb1
Physical volume still display the old volume in allocated PE
- We can check volume group allocated PE also
vgdisplay vg_u01
in below screen, we can see total PE, allocated PE and free PE
- As we can see below, Logical volume size is still not increased
- To increase the Logical volume size, we need to Extend the Logical volume size using the command below
lvextend -l +100%FREE /dev/mapper/vg_u01-lv_u01
- Logical volume is increased now. However "df -h" still shows the old value
- The last step is to resize the file system to extended 20 GB with right file format
resize2fs /dev/mapper/vg_u01-lv_u01
- Finally, as shown in the screen below, running df -h confirms that the logical volume has been extended to the required size
8. ✅ Summary
In this lab, we increased the size of an OCI block volume and extended it all the way into our OS’s filesystem.
We learned to:
- Resize the block volume via OCI console
- Rescan the block device inside Linux
- Grow partition and/or LVM structures (PV, VG, LV)
- Expand the filesystem (ext4/XFS) to make the extra space usable
This operation is essential during scale-ups, storage extensions, or when application load grows.