When working with virtual machines in VMware, you might need to manage disk space efficiently by extending a volume group and creating a SWAP partition. In this guide, we will cover how to check existing disks, extend a volume group, and configure SWAP space in a Linux environment.
Step 1. Check Existing Disks and Volume Groups
Before making any changes, it's essential to check the available disks and the current state of volume groups.
Run the following commands.
lsblk # Lists all block devices, including disks and partitions
pvs # Displays information about physical volumes
vgs # Shows details of existing volume groupsStep 2. Create a Physical Volume
If the new disk has not been initialized as a physical volume, you need to create one. Assuming the new disk is /dev/nvme0n2, use the following command:
pvcreate /dev/nvme0n2This command initializes the disk to be used with LVM (Logical Volume Manager).

Step 3. Extend the Volume Group
Identify the existing volume group where you want to add the new disk. If your volume group is named fedora, extend it using:
vgextend fedora /dev/nvme0n2This command adds the newly created physical volume to the fedora volume group.

Step 4. Create a Logical Volume for SWAP
Now, create a logical volume named swaplv with a size of 5GB:
lvcreate -L 5G -n swaplv fedoraThis will allocate 5GB from the volume group for SWAP space.

Step 5. Format the Logical Volume as a SWAP
To make the newly created logical volume usable as SWAP, format it with the following command:
mkswap /dev/fedora/swaplvStep 6. Enable the SWAP Partition
Activate the SWAP partition using:
swapon /dev/fedora/swaplvStep 7. Verify the SWAP Partition
Ensure the SWAP partition is active:
swapon --showThis command lists all active SWAP spaces.

Step 8. Make the SWAP Partition Persistent
To ensure that the SWAP partition is enabled after a reboot, add an entry to /etc/fstab.
Edit the file
nano /etc/fstabAdd the following line at the end of the file:
/dev/fedora/swaplv none swap sw 0 0Save and exit (CTRL + X, then Y and Enter).

Step 9. Reboot and Verify
Reboot the system to apply the changes:
rebootAfter rebooting, confirm that the SWAP partition is still active:
swapon --showChecking Memory Usage Before and After Configuration
Before creating and enabling the SWAP partition, check the memory usage:
free -h
After completing all the above steps, run the same command again to see the changes:
free -h
You should notice an increase in the available SWAP space, reflecting the newly added SWAP partition.
Conclusion
By following these steps, you have successfully extended a volume group, created a logical volume for SWAP, and configured it to persist after reboot. This ensures better memory management and system stability, especially for systems running resource-intensive applications.






Join the conversation! Your thoughts help the community grow.