VMware Cloud Community
StageCoach20111
Enthusiast
Enthusiast

Expanding Linux Virtual disk

What is the easiest and cleanest way to increase hard drive space on a Linux virtual machine when LVM is being used?

0 Kudos
9 Replies
logiboy123
Expert
Expert

You could try using http://gparted.sourceforge.net/ after backing up the VM of course.

0 Kudos
StageCoach20111
Enthusiast
Enthusiast

gparted can't expand LVM disks only non-LVM

0 Kudos
MauroBonder
VMware Employee
VMware Employee

Hello,

Check out this link http://vsphere-land.com/tips-tricks/re-sizing-virtual-disks

May help.

Good Luck

*Please, don't forget the awarding points for "helpful" and/or "correct" answers. *Por favor, não esqueça de atribuir os pontos se a resposta foi útil ou resolveu o problema.* Thank you/Obrigado
0 Kudos
StageCoach20111
Enthusiast
Enthusiast

This is great info although I don't think any of the methods described at that link apply when LVM is being used though....

0 Kudos
DSTAVERT
Immortal
Immortal

You can add space to the disk by editing the VM and increasing the VMDK size. You should then be able to use the LVM tools within the OS to modify the volume.

-- David -- VMware Communities Moderator
0 Kudos
StageCoach20111
Enthusiast
Enthusiast

You can use the tools inside the OS to expand the logical volume, but you can't expand the partition on which the logical volume sits.  For example if my logical volume is on dev/sda3, then I have to create a new partition, dev/sda4, add it to the volume group and then expand to include that space.  I can't just expand the sda3 partition to include the new size I just added to the virtual disk using "edit settings" on the VM.  If I had not used LVM, I could use gparted or another tool to expand sda3 partition to fill the newly expanded virtual disk.  If you keep having to add space periodically, you don't want to keep adding more partitions every time you need more space in your logical volume.

0 Kudos
Texiwill
Leadership
Leadership

Hello,

Two ways exist to extend a volume when LVM is in use. But first answer this question:

     Are you comfortable with your backup?

Then:

1) In vSphere change the size of the VMDK to be greater

2) In vSphere add a new VMDK/RDM/vRDM to the VM <=== Recommended over the other if this is the boot volume

Now from within the Linux VM:

1) create LVM partitions on the volumes for all the free space of the virtual disks

2) Use your favorite LVM tool to add the newly created partitions to your LVM volumes.

I use RHEL so use fdisk or gparted then use system-config-lvm but you can also use pv*, lv*, vg* commands as well.

It also may be possible to use vConverter but I have not tested this.

Best regards,

Edward L. Haletky

Communities Moderator, VMware vExpert,

Author: VMware vSphere and Virtual Infrastructure Security,VMware ESX and ESXi in the Enterprise 2nd Edition

Podcast: The Virtualization Security Podcast Resources: The Virtualization Bookshelf

--
Edward L. Haletky
vExpert XIV: 2009-2023,
VMTN Community Moderator
vSphere Upgrade Saga: https://www.astroarch.com/blogs
GitHub Repo: https://github.com/Texiwill
0 Kudos
nancy31
Enthusiast
Enthusiast

I use the tools inside the OS to expand the logical volume and with all the suggested solution, I sorted everything.  I have no difficulties so far and I am looking forward to maintain my performace until the next upgrade http://imagicon.info/cat/5-59/1.gif

0 Kudos
BSRKrishna
Enthusiast
Enthusiast

HI ,

Please take the backup priort to increase virtual disk .

This tool is from VMware. It is used for Virtual-disk and VMFS management.

Be aware, always use Virtual Center GUI to create VMFS Volumes. Otherwise you will end up with an unaligned VMFS partition and decreased performance.

vmkfstools VM-Disk and VMFS Management in the console

vmkfstools  -X

Extend virtual Disk

vmkfstools  -X  12G ./testing.vmdk

To extend an existing Virtual Disk to 12GB. Instead of G you can use M for Megabytes
With the same command you can shrink the disk (only for ESX Version prior to 3.0)   if you choose a smaller than the present size. Be aware if the  shrinked size is smaller as the partition size in the guest there might  be a data losse or a corrupted system resulting!


In some cases the shrink command must be issued with the --force option:

vmkfstools -X  4G ./testing.vmdk --force

For shrinking on ESX 3.0x   use the VMWare Converter (download from the VMware Website for  freee).  Point the source and destination to the same ESX Host.

If you receive an error one parameter was incrorrect the size might be smaller as the original size!

If you have blanks in the file or directoryname, mask the full path with  '

vmkfstools  -i

To export or clone a virtual disk from VMFS
vmkfstools -i  <source-file> -d diskformat <destination-file>

Example:

Copy from one vmfs to another:

Source=/vmfs/volumes/esxpublic/testvm2.vmdk
Destination=/vmfs/volumes/production/testvmnew2.vmdk

vmkfstools -i /vmfs/volumes/esxpublic/testvm2.vmdk /vmfs/volumes/production/testvmnew2.vmdk

Export to ext3 partition:

Source=/vmfs/volumes/esxpublic/testvm2.vmdk
Destination=/vmimages/testvm2.vmdk

vmkfstools -i  /vmfs/esxpublic/testvm2.vmdk -d 2gbsparse /vmimages/testvm2.vmdk

vmkfstools  -E

Rename files associated with a specified virtual disk

vmkfstools  -U

Delete Virtualdisk
Delete files associated with the specified virtual disk.

vmkfstools  -c 4000M ./file.vmdk

To create a new empty virtual disk

vmkfstools -c 300G -a lsilogic /vmfs/volume/vmfslabel/directory/newdisk.vmdk

or in current directory

vmkfstools -c 300G -a lsilogic ./newdisk.vmdk

This command is very useful because you can use user-friendly names for the disks

Thanks & Regards,

BSR Krishna

Thanks & Regards, BSR Krishna If you find this or any other answer useful please consider awarding points by marking the answer correct or helpful
0 Kudos