To enlarge a disk in a VMware Linux virtual machine, you'll need to follow a multi-step process. This involves both VMware-related operations and Linux command-line instructions to resize the partition and the filesystem. Here is the complete step-by-step guide:
Step 1: Enlarge the Virtual Disk in VMware
- Shutdown the VM: Power off the virtual machine to ensure you can safely modify the virtual disk.
- Increase the Disk Size:
- Open the VMware vSphere client (or VMware Workstation/Player).
- Locate the VM you want to resize.
- Right-click the VM and select Edit Settings.
- Select the virtual hard disk you want to resize.
- Increase the size of the disk by modifying the Provisioned Size.
- Save the changes.
Step 2: Boot the VM and Identify the New Disk Size
- Power On the VM: Start the virtual machine.
- Verify the Disk Size: Check the new disk size with the following command:
lsblk
This will list all block devices and their sizes.
Step 3: Resize the Partition
If you're using a partitioned disk (e.g., /dev/sda
), you'll need to resize the partition before resizing the filesystem.
- Identify the Partition: Find the partition you want to resize (e.g.,
/dev/sda1
). You can usefdisk
orparted
to resize the partition. - Resize the Partition Using
fdisk
(For MBR Partitions):- Open the disk in
fdisk
:sudo fdisk /dev/sda
- Delete the partition you want to resize (don't worry, your data will remain intact).
- Recreate the partition with the same starting sector and a larger size.
- Save and exit
fdisk
by pressingw
.
Note: Ensure that the starting sector is the same as before to avoid data loss.
- Open the disk in
- Resize the Partition Using
parted
(For GPT Partitions):- Start
parted
:sudo parted /dev/sda
- Use the following command to resize the partition:
resizepart <partition_number> <end_position>
For example, to resize
/dev/sda1
to use the entire disk:resizepart 1 100%
- Exit
parted
.
- Start
Step 4: Resize the Filesystem
Now that the partition has been resized, you need to resize the filesystem to take up the new space.
- Resize the Filesystem: Depending on the filesystem type, use one of the following commands:
- For ext4/ext3 Filesystem:
sudo resize2fs /dev/sda1
- For XFS Filesystem:
sudo xfs_growfs /dev/sda1
(Note: XFS filesystems cannot be shrunk, but they can be expanded online.)
- For ext4/ext3 Filesystem:
- Verify the Filesystem Size: Check if the filesystem has been resized correctly:
df -h
This will display the filesystem's current size and usage.
Summary of Commands:
- Resize the partition using
fdisk
orparted
. - Resize the filesystem using
resize2fs
for ext filesystems orxfs_growfs
for XFS filesystems.
After completing these steps, your virtual machine's disk and filesystem should reflect the newly allocated size.