How to Extend the Disk Size in Rocky Linux Running in VMware
Expanding the disk size on a virtual machine (VM) running Rocky Linux in VMware is a task you might encounter when you need more storage space for your applications or files. The process involves several steps, starting with expanding the hard drive for the VM in VMware and then extending the partitions and filesystems within Rocky Linux to utilize the newly available space. This guide will walk you through the entire process.
Step 1: Expand the Hard Drive in VMware
Before making changes within Rocky Linux, you must allocate the additional space to your virtual machine. Here’s how:
- Power Off Your VM: It’s always a good idea to power off the VM before changing its virtual hardware.
- Edit VM Settings:
- Right-click on your VM in VMware and select Edit Settings.
- Locate the hard disk you want to expand in the hardware list.
- Increase the disk size by the desired amount (e.g., add 40 GB).
- Save your changes and power on the VM.
Step 2: Verify the New Disk Space
Once the VM is powered back on, log in to your Rocky Linux system and open a terminal. Start by checking if the system recognizes the additional space.
parted -l
The parted -l
command lists all the partitions on the disk. Look for your primary disk (/dev/sda
typically) and verify that the disk size reflects the newly expanded capacity.
Step 3: Modify the Partition
Next, you need to modify the partition to use the additional space.
cfdisk /dev/sda
The cfdisk
tool provides a user-friendly interface to manage disk partitions. Follow these steps within cfdisk
:
- Select the partition you want to resize (this is usually the main partition, like
/dev/sda2
). - Choose the option to resize or create a new partition if needed.
- Save the changes and exit
cfdisk
.
Step 4: Resize the Physical Volume
After modifying the partition, the next step is to resize the physical volume to acknowledge the new space.
pvresize /dev/sda2
The pvresize
command updates the physical volume (PV) to reflect the expanded partition size. This ensures that the volume group has access to the additional space.
Step 5: Extend the Logical Volume
Now that the physical volume is resized, you can extend the logical volume to use the newly available space.
lvextend -l +100%FREE /dev/mapper/rl-root
This command tells lvextend
to increase the size of the logical volume by using all the available free space in the volume group. The logical volume corresponding to your root filesystem (/dev/mapper/rl-root
) will now be expanded.
Step 6: Resize the Filesystem
Finally, the filesystem needs to be resized so it can use the extended logical volume space. Depending on your filesystem type, you’ll use one of the following commands:
- For ext4/ext3 filesystems:
resize2fs /dev/mapper/rl-root
- For XFS filesystems:
xfs_growfs /dev/mapper/rl-root
resize2fs
expands the ext4/ext3 filesystem to fill the larger logical volume, while xfs_growfs
grows the XFS filesystem, ensuring it fully utilizes the expanded logical volume.
Step 7: Verify the Changes
To confirm that the process was successful, you can check the size of the root filesystem:
df -h
This command will display your filesystems’ disk usage. Verify that your root filesystem now reflects the new, larger size.
Conclusion
And that’s it! You’ve successfully expanded the disk size of your Rocky Linux VM in VMware. By following these steps, you can ensure that your system can take advantage of the additional space without any data loss or downtime. Whether you’re managing a small VM or a critical server, this process will help keep your Rocky Linux system running smoothly with plenty of storage to spare.
Add Comment