Expanding Virtual Machine Resources in CentOS 7
This guide provides a comprehensive walkthrough for expanding memory and disk space in a CentOS 7 virtual machine running on VMware Workstation. The process involves both VMware configuration changes and Linux system administration tasks to properly utilize the additional resources.
Virtual Machine Environment
- Host OS: Windows 10 Education, 64-bit (Build 22000.1817)
- Hypervisor: VMware Workstation 16 Pro (Version 16.2.3)
- Guest OS: CentOS Linux 7 (Core)
Expanding VM Memory
- Shut down the virtual machine completely.
- Open VM settings by right-clicking the VM and selecting "Settings".
- Navigate to the "Memory" tab.
- Adjust the memory slider to your desired allocation.
- Click "Save" to apply the changes.
- Power on the virtual machine. The memory expansion is now complete.
Expanding Virtual Disk
- Ensure the VM is powered off.
- Open VM settings and select the "Hard Disk" from the hardware list.
- Click the "Expand" button in the Disk Utilities section.
- Enter the new maximum disk size and click "Expand".
- After completion, you'll see a message: "The disk has been successfully expanded. You must partition and expand the file system from within the guest operating system."
- Power on the VM to proceed with OS-level configuration.
Partitioning the New Disk Space
After booting into CentOS, verify the disk expansion:
df -h
You should notice that the total disk capacity (/dev/sda) now reflects the expanded size, but the filesystem hasn't yet been updated to use the addditional space.
Start the partitioning process:
fdisk /dev/sda
- Type 'n' to create a new partition.
- Accept the default values for partition type (primary), partition number (3), and sectors.
- Type 'p' to print the partition table and verify the new partition exists.
- Type 'w' to write the changes and exit fdisk.
Reboot the system to ensure the partition table is updated:
reboot
Integrating the New Partition with LVM
After rebooting, verify the partition is recognized:
fdisk -l
Format the new partition with the ext3 filesystem:
mkfs -t ext3 /dev/sda3
Initialize the partition as a physical volume for LVM:
lvs
pvcreate /dev/sda3
Display available physical volumes to verify the initialization:
pvdisplay
Extend the volume group (replace 'centos_super' with your actual volume group name):
vgextend centos_super /dev/sda3
Check the free space in the volume group:
vgdisplay
Look for "Free PE / Size" which should show the available space (e.g., 2559 / <10.00 GiB).
Extend the logical volume (replace with your actual volume path):
lvextend -L+9.9G /dev/mapper/centos_super-root /dev/sda3
Resize the filesystem to utilize the new space. For ext filesystems:
resize2fs /dev/mapper/centos_super-root
If you encounter an error "Bad magic number in super-block", check the filesystem type with:
mount |grep root
For XFS filesystems, use the appropriate command:
xfs_growfs /dev/mapper/centos_super-root
Finally, verify that the expansion was successful:
df -h
The output should now show the increased filesystem size (e.g., 45G instead of the previous 35G).