When expanding a virtual disk in CentOS (or any Linux VM), you'll often encounter this frustrating scenario: The hypervisor shows the new disk size, but traditional tools like fdisk
stubbornly report the original capacity. This happens because Linux caches partition table information at boot time.
rescan Isn't Enough /h2>
The commonly suggested echo 1 > /sys/block/sda/device/rescan
command only updates the block device size - it doesn't force the kernel to re-read the partition table. Here's what's actually happening:
# This updates the block device size:
echo 1 > /sys/block/sda/device/rescan
# But partition tools still see old size:
fdisk -l /dev/sda
For CentOS 5 specifically, try these methods in order:
# Method 1: partprobe (if available)
partprobe /dev/sda
# Method 2: Block device revalidation
blockdev --rereadpt /dev/sda
# Method 3: Manual partition table reload (risky)
hdparm -z /dev/sda
After running any of the above commands, verify with:
# Check block device size
cat /sys/block/sda/size
# Verify with alternative tools
lsblk # If available
fdisk -l /dev/sda | grep Disk
If using LVM, additional steps are needed:
pvresize /dev/sdaX # Resize physical volume
lvextend -l +100%FREE /dev/mapper/your_volume
resize2fs /dev/mapper/your_volume
When standard methods fail:
- Check kernel messages:
dmesg | tail -20
- Verify hypervisor tools are installed (VMware: vmware-tools, VirtualBox: guest-additions)
- Test with alternative tools:
sfdisk -l /dev/sda
When expanding a virtual disk in CentOS (particularly older versions like CentOS 5), the kernel often fails to immediately recognize the new storage capacity. This creates a frustrating scenario where tools like fdisk -l
still report the original disk size despite successful hypervisor-level expansion.
The echo 1 > /sys/block/sda/device/rescan
approach typically works on modern kernels, but CentOS 5's older 2.6 kernel requires deeper intervention. The system maintains cached partition tables that persist even after SCSI rescan operations.
Method 1: SCSI Layer Rescan
First try forcing a deeper storage rescan:
for host in /sys/class/scsi_host/host*/scan; do echo "- - -" > $host done
Then verify with dmesg | tail
for new capacity messages.
Method 2: Manual Block Device Refresh
When SCSI rescan fails, directly manipulate the block device:
# First unmap the device echo 1 > /sys/block/sda/device/delete # In VMware environments, check for specific PCI devices lspci | grep -i vmware # Then rescan echo "- - -" > /sys/class/scsi_host/host0/scan
If the disk still shows old capacity after rescan, try these advanced techniques:
# For MSDOS partition tables: blockdev --rereadpt /dev/sda # Alternative using parted: parted /dev/sda print parted /dev/sda resizepart 1 -1
Once the system recognizes the new space, extend your filesystem:
# For LVM: pvresize /dev/sda1 vgextend vg_name /dev/sda1 lvextend -l +100%FREE /dev/mapper/vg_name-lv_name resize2fs /dev/mapper/vg_name-lv_name # For raw partitions (ext3/ext4): resize2fs /dev/sda1
Check these critical indicators when troubleshooting:
cat /proc/partitions cat /sys/block/sda/size hdparm -g /dev/sda
Remember that some VM tools like VMware's vmware-tools or VirtualBox additions may provide alternative rescan mechanisms specific to their platforms.