Increase A VMware Disk Size (VMDK) Formatted As Linux LVM without rebooting

Mattias Geniar, Friday, August 27, 2010 - last modified: Sunday, July 24, 2016

To increase the size of your VMware Virtual Machine, you need to do 2 major steps. First, you need to increase the disk's size in your vSphere Client or through the CLI. This will increase the "hardware" disk that your Virtual Machine can see. Then, you need to utilize that extra space by partitioning it. If you're interested in just resizing your Linux LVM, please proceed to step 2.

In this example, I'm increasing a 3GB disk to a 10GB disk (so you can follow using the examples).

I would advise you to read the excellent documention on Logical Volume Management on tldp.org.

Just a small note beforehand; if your server supports hot adding new disks, you can just as easily add a new Hard Disk to your Virtual Machine. You can increase the LVM volume without rebooting your Virtual Machine by rescanning the SCSI bus, more on that later in this article.

1) Checking if you can extend the current disk or need to add a new one

This is rather important step, because a disk that has been partitioned in 4 primary partitions already can not be extended any more. To check this, log into your server and run fdisk -l at the command line.

# fdisk -l

Disk /dev/sda: 187.9 GB, 187904819200 bytes
255 heads, 63 sectors/track, 22844 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          25      200781   83  Linux
/dev/sda2              26        2636    20972857+  8e  Linux LVM

If it looks like that, with only 2 partitions, you can safely extend the current hard disk in the Virtual Machine.

However, if it looks like this:

~# fdisk -l

Disk /dev/sda: 187.9 GB, 187904819200 bytes
255 heads, 63 sectors/track, 22844 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          25      200781   83  Linux
/dev/sda2              26        2636    20972857+  8e  Linux LVM
/dev/sda3            2637       19581   136110712+  8e  Linux LVM
/dev/sda4           19582       22844    26210047+  8e  Linux LVM

It will show you that there are already 4 primary partitions on the system, and you need to add a new Virtual Disk to your Virtual Machine. You can still use that extra Virtual Disk to increase your LVM size, so don't worry.

2) The "hardware" part, "physically" adding diskspace to your VM

Increasing the disk size can be done via the vSphere Client, by editing the settings of the VM (right click > Settings).

Edit settings

Now, depending on the first step, if there aren't four primary partitions yet, you can increasing the privisioned disk space.

Increase disk size

If the "Provisioned Size" area (top right corner) is greyed out, consider turning off the VM first (if it does not allow "hot adding" of disks/sizes), and check if you have any snapshots made of that VM. You can not increase the disk size, as long as there are available snapshots.

Alternatively, if you already have 4 primary paritions, you can also choose "Add..." to add new Hardware "Virtual Disk" to your VM, with the desired extra space.

3) Partitioning the unallocated space: if you've increased the disk size

Once you've changed the disk's size in VMware, boot up your VM again if you had to shut it down to increase the disk size in vSphere. If you've rebooted the server, you won't have to rescan your SCSI devices as that happens on boot. If you did not reboot your server, rescan your SCSI devices as such.

First, check the name(s) of your scsi devices.

$ ls /sys/class/scsi_device/
0:0:0:0 1:0:0:0  2:0:0:0

Then rescan the scsi bus. Below you can replace the '0\:0\:0\:0' with the actual scsi bus name found with the previous command. Each colon is prefixed with a slash, which is what makes it look weird.

~$ echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan

That will rescan the current scsi bus and the disk size that has changed will show up.

3) Partitioning the unalloced space: if you've added a new disk

If you've added a new disk on the server, the actions are similar to those described above. But instead of rescanning an already existing scsi bus like show earlier, you have to rescan the host to detect the new scsi bus as you've added a new disk.

$ ls  /sys/class/scsi_host/
total 0
drwxr-xr-x  3 root root 0 Feb 13 02:55 .
drwxr-xr-x 39 root root 0 Feb 13 02:57 ..
drwxr-xr-x  2 root root 0 Feb 13 02:57 host0

Your host device is called 'host0', rescan it as such:

$ echo "- - -" > /sys/class/scsi_host/host0/scan

It won't show any output, but running 'fdisk -l' will show the new disk.

Create the new partition

Once the rescan is done (should only take a few seconds), you can check if the extra space can be seen on the disk.

~$  fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         391     3036285   8e  Linux LVM

So the server can now see the 10GB hard disk. Let's create a partition, by start fdisk for the /dev/sda device.

~$  fdisk /dev/sda

The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): n

Now enter 'n', to create a new partition.

Command action
e   extended
p   primary partition (1-4)
 p

Now choose "p" to create a new primary partition. Please note, your system can only have 4 primary partitions on this disk! If you've already reached this limit, create an extended partition.

Partition number (1-4): 3

Choose your partition number. Since I already had /dev/sda1 and /dev/sda2, the logical number would be 3.

First cylinder (392-1305, default 392): <enter>
Using default value 392
Last cylinder or +size or +sizeM or +sizeK (392-1305, default 1305): <enter>
Using default value 1305

Note; the cylinder values will vary on your system. It should be safe to just hint enter, as fdisk will give you a default value for the first and last cylinder (and for this, it will use the newly added diskspace).

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

Now type t to change the partition type. When prompted, enter the number of the partition you've just created in the previous steps. When you're asked to enter the "Hex code", enter 8e, and confirm by hitting enter.

Command (m for help): w

Once you get back to the main command within fdisk, type w to write your partitions to the disk. You'll get a message about the kernel still using the old partition table, and to reboot to use the new table. The reboot is not needed as you can also rescan for those partitions using partprobe. Run the following to scan for the newly created partition.

~$ partprobe -s

If that does not work for you, you can try to use "partx" to rescan the device and add the new partitions. In the command below, change /dev/sda to the disk on which you've just added a new partition.

~$ partx -v -a /dev/sda

If that still does not show you the newly created partition for you to use, you have to reboot the server. Afterwards, you can see the newly created partition with fdisk.

~$  fdisk -l

Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14         391     3036285   8e  Linux LVM
/dev/sda3             392        1305     7341705   8e  Linux LVM

3) Extend your Logical Volume with the new partition

Now, create the physical volume as a basis for your LVM. Please replace /dev/sda3 with the newly created partition.

~$  pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created

Now find out how your Volume Group is called.

~$  vgdisplay
--- Volume group ---
VG Name               VolGroup00
...

Let's extend that Volume Group by adding the newly created physical volume to it.

~$  vgextend VolGroup00 /dev/sda3
Volume group "VolGroup00" successfully extended

With pvscan, we can see our newly added physical volume, and the usable space (7GB in this case).

~$  pvscan
PV /dev/sda2   VG VolGroup00   lvm2 [2.88 GB / 0    free]
PV /dev/sda3   VG VolGroup00   lvm2 [7.00 GB / 7.00 GB free]
Total: 2 [9.88 GB] / in use: 2 [9.88 GB] / in no VG: 0 [0   ]

Now we can extend Logical Volume (as opposed to the Physical Volume we added to the group earlier). The command is "lvextend /dev/VolGroupxx /dev/sdXX".

~$  lvextend /dev/VolGroup00/LogVol00 /dev/sda3
Extending logical volume LogVol00 to 9.38 GB
Logical volume LogVol00 successfully resized

If you're running this on Ubuntu, use the following.

~$  lvextend /dev/mapper/vg-name /dev/sda3

All that remains now, it to resize the file system to the volume group, so we can use the space. Replace the path to the correct /dev device if you're on ubuntu/debian like systems.

~$  resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 2457600 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 2457600 blocks long.

If you got an error like this, it may mean your filesystem is XFS instead of standard ext2/ext3.

$ resize2fs /dev/mapper/centos_sql01-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos_sql01-root
Couldn't find valid filesystem superblock.

In that case, you'll need to increase the XFS partition. Read here for more details: Increase/Expand an XFS Filesystem in RHEL 7 / CentOS 7.

And we're good to go!

~$  df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 9.1G 1.8G  6.9G  21% /
/dev/sda1              99M   18M   77M  19% /boot
tmpfs                 125M     0  125M   0% /dev/shm


Hi! My name is Mattias Geniar. I'm a Support Manager at Nucleus Hosting in Belgium, a general web geek, public speaker and podcaster. Currently working on DNS Spy. Follow me on Twitter as @mattiasgeniar.

I respect your privacy and you won't get spam. Ever.
Just a weekly newsletter about Linux and open source.

SysCast podcast

In the SysCast podcast I talk about Linux & open source projects, interview sysadmins or developers and discuss web-related technologies. A show by and for geeks!

cron.weekly newsletter

A weekly newsletter - delivered every Sunday - for Linux sysadmins and open source users. It helps keeps you informed about open source projects, Linux guides & tutorials and the latest news.

Share this post

Did you like this post? Will you help me share it on social media? Thanks!

Comments

Simon Kirsch Sunday, October 24, 2010 at 12:27 (permalink)

This article is really well written, clear, to the point, and was really useful. It guided me though a difficult task which I finished successfully on the first attempt. Well done and thanks to the author.
Regards, Simon

Reply


    Stephen Palmateer Tuesday, November 8, 2011 at 00:40 (permalink)

    I agree with Simon Kirsch.
    This article could not be more accurate.

    Reply


Jared Tuesday, January 25, 2011 at 11:39 (permalink)

This works perfect and even on XenServer 5.6. Thank you so much as i was having difficulty doing this.

Reply


Tuong Huynh Monday, March 7, 2011 at 23:44 (permalink)

Thank you for sharing this great article.

Reply


Glenn Wednesday, March 9, 2011 at 10:05 (permalink)

As an alternative you can delete the partition and recreate it with the exact same start sector. Then use pvresize.

Reply


Prasenjit Monday, March 14, 2011 at 10:57 (permalink)

Thanks…gr8 article and works for me like champ in one go…save lots of time..

Reply


bcdeg Sunday, March 27, 2011 at 13:33 (permalink)

excellent article! worked exactly has described. Thank you!

Reply


meltice Thursday, May 26, 2011 at 11:42 (permalink)

It really works. Thanks.

Reply


preyo999 Thursday, June 16, 2011 at 14:11 (permalink)

Yes it worked
Thanks for such a detailed post saved my lots of time

Reply


Vinod Tuesday, July 5, 2011 at 19:00 (permalink)

Wonderfully explained.. !! Excellent tutorial.. cleared my confusions and I successfully completed my task with your help. Thanks a lot .

Reply


Roy Wednesday, July 6, 2011 at 14:22 (permalink)

Excellent! well written, Only needed step 2 but it works!
This quality doc should be on the major Linux pages

THANK YOU

Reply


Matthew Auger Wednesday, July 27, 2011 at 04:50 (permalink)

Not a Linux user but was asked to resolve an issue like this. This is a great article BUT I found that we couldn’t get it to work using “LogVol00” in the “lvextend -L+7GB /dev/VolGroup00/LogVol00” and “resize2fs /dev/VolGroup00/LogVol00” commands. Our VG was called system which was easy enough to determine but it took ages to find that our eq to “LogVol00” was “root” (ie lvextend -L+7GB /dev/system/root Once we used this all was working, many thanks.

Reply


Adrian Thursday, August 4, 2011 at 11:50 (permalink)

Hi,

When I used the syntax of -L+XXGB I’ve got an error:
root@mail2:~# lvextend -L+70GB /dev/mapper/mail2-root
Extending logical volume root to 98.49 GiB
Insufficient free space: 17920 extents needed, but only 17919 available

So I have used lvextend a bit different and it worked:
root@mail2:~# lvextend /dev/mapper/mail2-root /dev/sda3
Extending logical volume root to 98.48 GiB
Logical volume root successfully resized

Thanks,
Adrian

Reply


Wouter Wednesday, August 10, 2011 at 15:18 (permalink)

If you want to extend with the complete size of your extent and use it until the last bit, its easier to do

#lvextend /dev/VolGroup00/LogVol00 /dev/sda3

;-)

Reply


Dave Wednesday, August 10, 2011 at 18:23 (permalink)

Great post, I had to extend a volume on my linux boxes. This worked as advertised. Does this work with Redhat 4?? I have Redhat 5 with LVM and it worked like a champ

Reply


Alex K Tuesday, August 23, 2011 at 13:01 (permalink)

Thank you, very much. Very useful guide

Reply


Rashid Wednesday, September 7, 2011 at 08:24 (permalink)

Thanks for posting the solution, Its worked for me.

Reply


Linux type Thursday, September 29, 2011 at 15:36 (permalink)

Excellent! Thanks a lot!

Reply


Kashif Friday, October 7, 2011 at 12:15 (permalink)

Thanks its perfect solution for increase HD in VM

Reply


Kdavid Saturday, October 15, 2011 at 15:22 (permalink)

Wonderful Post..It work perfect……Thumbs up to you man!

Reply


avoker Thursday, October 20, 2011 at 00:52 (permalink)

If someone already has the extended partition created then the newly added space will be out of that and you won’t be able to create a new partition just yet. An easy way to get over it is to use “cfdisk” to create a new partition on the free space so to extend the “Extended” partition.

Reply


faust Saturday, October 22, 2011 at 21:54 (permalink)

Excellent post! Very straightforward – I had tried many other scenarios and pages and this worked first time through.

Thank you.

(Ubuntu 10.04.3 LTS, VMWare ESXi 4.1)

Reply


Karvin Friday, November 11, 2011 at 05:19 (permalink)

Awesome, you are life saver!

Reply


Jacob Thursday, November 17, 2011 at 01:38 (permalink)

Awesome article, worked first try. Thank you!

Reply


Meghan Calvo Wednesday, November 23, 2011 at 19:25 (permalink)

Perfect. Thank you so much!

Reply


kK Santosh Friday, November 25, 2011 at 23:29 (permalink)

Great Buddy !
I am struck completely on finding ur Doc’ I can easily able to increase Disk Space
Many Many Thanks

Reply


Sunny Friday, December 9, 2011 at 12:27 (permalink)

Great Article…..Really helped me…

Reply


Mohamed Monday, December 12, 2011 at 23:03 (permalink)

Excellent upto the point How to do article. Thanks for sharing the knowledge.

Reply


PHOHAT Tuesday, December 13, 2011 at 21:47 (permalink)

Thank you very much for the sharing!!

After 1 day of research on the all wide web you’re the most one clear about this.

(Sorry for my poor english i’m french PEACE !)

Reply


ll Friday, December 23, 2011 at 21:32 (permalink)

You are the best work excelent in Centos 5.6 and ESX. Thanx!!!

Reply


Chris Carmichael Thursday, December 29, 2011 at 03:39 (permalink)

What a well written article…there are several out there, but they all leave out steps or make assumptions about the readers experience.

Thank you.

-chris

Reply


Ben Wednesday, January 11, 2012 at 02:20 (permalink)

Great article, even someone with next to no Linux experience (like me!) can easily follow these steps.

Reply


George Friday, January 27, 2012 at 20:02 (permalink)

Thank u very much for this tutorial. You save my work place. Thank u again. This is very very useful guide.

Reply


Eddie Friday, February 3, 2012 at 00:33 (permalink)

Great article. Really well written and very useful.

Reply


justin Wednesday, February 22, 2012 at 23:26 (permalink)

Awesome.

Reply


Josh Holt Friday, March 23, 2012 at 23:08 (permalink)

My kudos to the author. A very well written article.

Reply


Raja Sunday, April 8, 2012 at 16:45 (permalink)

Awesome work… Made my day easy…

Reply


Sky Monday, April 9, 2012 at 18:32 (permalink)

Absolutely perfect! Thank you for being straight and to the point. Easy to follow and understand, you should be hired to write the ‘man’ pages and the ‘How-To’s’.

Reply


Miguel Angel Arribas Friday, August 3, 2012 at 12:04 (permalink)

I can’t thank you enough for this article.
After looking among dozens of related articles, I was not able to understand what to do.
I am new at linux and by reading your article I was able to resize my virtual system in minutes.
Great job.

Reply


Brian Afshar Friday, September 28, 2012 at 02:18 (permalink)

This is the best step by step instructions I have ever used that actually worked flawlesly. Thank you Mattias

Reply


Michael L Tuesday, October 16, 2012 at 17:46 (permalink)

Thank you these steps are so detail and useful.

Reply


Jeff Catania Thursday, November 1, 2012 at 20:15 (permalink)

Mattias, Thank you very much for the great article! Works like a charm.

Reply


Vahid Tuesday, January 8, 2013 at 12:55 (permalink)

Terrific, Thanks a million!!!

Reply


Shiv Tuesday, March 19, 2013 at 23:50 (permalink)

Heartfelt thanks. immensely helped us to resolve.

Reply


guillaume Wednesday, June 26, 2013 at 14:08 (permalink)

REally good and helpfull. The only issue was how to find out the name of LogVol00 .
I found a “lvdisplay” command and then I could catch the name used on my system.

Reply


tuchella Wednesday, September 25, 2013 at 16:27 (permalink)

awesome

Reply


Joris Hontelé Friday, July 18, 2014 at 11:01 (permalink)

Excellent article.
It worked like a charm and I’m a linux noob.
Thanks a lot!

Reply


Morris zhang Friday, August 22, 2014 at 05:53 (permalink)

very Good and THKs.

Reply


ChiVu Truong Monday, October 6, 2014 at 18:22 (permalink)

It works. Thanks a lot

Reply


Swift M Tuesday, September 8, 2015 at 12:01 (permalink)

Best step-by-step LVM extension article on the internet.

Reply


    saw Wednesday, February 24, 2016 at 17:05 (permalink)

    True that. Glad I found it!

    Reply


Perry Monday, April 4, 2016 at 03:11 (permalink)

Very well written tutorial which works. Thank you!

Reply


Wim Melchers Friday, June 24, 2016 at 10:45 (permalink)

good stuff, short, useful
and it works.
thanks a lot

Reply


Theerachai Ruangsoong Friday, July 8, 2016 at 03:51 (permalink)

This article is really useful.
All steps are easy to read and follow.
Thank you very much.

Reply


Larry Steinke Sunday, July 31, 2016 at 03:03 (permalink)

The two articles about increasing the VMDK size and working it through to the xfs_growfs command were both very, very helpful. Thank you for putting this together.

Reply


Felipe Monday, August 1, 2016 at 22:07 (permalink)

Hi!

i had attached a second HD to this VM, i was able to xpand HD size partition on vSphere config,
but when i try to extend this on VM ssh i saw that i don’t have a Volume Group,
a df -h command show the Second HD partition but lvdisplay or vgdisplay they only show the partitions of VM disk.

how can i expand this second HD partition ?
its using a ext4.

thanks

Reply


Anthony Wednesday, August 24, 2016 at 22:50 (permalink)

Great post, thank you for posting this.

Reply


Alexandre Tuesday, November 15, 2016 at 13:30 (permalink)

Thank you, you made my day :D

Reply


Intars Tuesday, February 14, 2017 at 12:23 (permalink)

Thank you!

Reply


Fran Lois Tuesday, April 11, 2017 at 08:18 (permalink)

Great post! Better than https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1006371
Tested with CentOS6. Thank you.

Reply


lance Sunday, April 16, 2017 at 03:47 (permalink)

Great, detailed post. Keep up the good work!

Reply


Yury Thursday, June 29, 2017 at 18:52 (permalink)

Thank you very much! Best guide.
Can you give me a advice, how to extend LVM without adding new partition (/dev/sdb3,4,5). How to resize current device (/dev/sdb1 for example) carefully? Can I make it without reboot?

Reply


Alexei Wednesday, August 30, 2017 at 20:35 (permalink)

Very helpful article. And I know this is a few years old, but I am getting an error in the lvextend command. Maybe you can help?

CentOS Linux release 7.3.1611

Thanks.

[root@localhost /]# lvextend /dev/cl /dev/sda3
“/dev/cl”: Invalid path for Logical Volume.
Run `lvextend –help’ for more information.
[root@localhost /]#

The sba3 volume I created called itself “cl”

[root@localhost /]# vgdisplay
— Volume group —
VG Name cl
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 43.99 GiB
PE Size 4.00 MiB
Total PE 11262
Alloc PE / Size 4863 / 19.00 GiB
Free PE / Size 6399 / 25.00 GiB
VG UUID v7CMTB-JI8p-Ahhj-ACCh-1aOj-Ftv0-diCFnm

Reply


BSUK Sunday, November 19, 2017 at 02:45 (permalink)

Great article! Many thanks! :)

Reply


Leave a Reply

Your email address will not be published. Required fields are marked *

Inbound links