Increasing CentOS LVM under VMWare

Background: I had an existing CentOS machine as a virtual machine running on VMWare ESX Server and it was running out of space so for future reference I did the following. Incidentally my disk is sda with the new partition create on the extra space as sda3.

I first increased the disk using the vSphere Client:

Increasing the disk size in VMWare

Then on the actual host (‘myhost’ in this example) I checked the existing partitions:

[root@myhost ~]# fdisk -l
Disk /dev/sda: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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        1958    15623212+  8e  Linux LVM

I then ran fdisk on the disk to create a new partition (‘n’) as primary partition 3 (change as necessary).

[root@myhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 13054.
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
Command action
e   extended
p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1959-13054, default 1959):
Using default value 1959
Last cylinder or +size or +sizeM or +sizeK (1959-13054, default 13054):
Using default value 13054

I printed the partition table (see below) and could see the new partition

Command (m for help): p
Disk /dev/sda: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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        1958    15623212+  8e  Linux LVM
/dev/sda3            1959       13054    89128620   83  Linux

But I need the partition type to be 8e Linux LVM so…

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)

Printing the partition table shows me what I wanted.

Command (m for help): p
Disk /dev/sda: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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        1958    15623212+  8e  Linux LVM
/dev/sda3            1959       13054    89128620   8e  Linux LVM

And save the changes (be careful!)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

So reboot.

[root@myhost ~]# shutdown -r now

And now for the LVM commands. Scan the Physical Volumes:

[root@myhost ~]# pvscan
PV /dev/sda2   VG VolGroup00   lvm2 [14.88 GB / 0    free]
Total: 1 [14.88 GB] / in use: 1 [14.88 GB] / in no VG: 0 [0   ]

And Create a new Physical Volume from /dev/sda3

[root@myhost ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created

Extend the Volume Group 00 to include /dev/sda3:

[root@myhost ~]# vgextend VolGroup00 /dev/sda3
Volume group "VolGroup00" successfully extended

Scan again and we can see /dev/sda3 included:

[root@myhost ~]# pvscan
PV /dev/sda2   VG VolGroup00   lvm2 [14.88 GB / 0    free]
PV /dev/sda3   VG VolGroup00   lvm2 [84.97 GB / 84.97 GB free]
Total: 2 [99.84 GB] / in use: 2 [99.84 GB] / in no VG: 0 [0   ]

Now extend the Logical Volume to extend (-L) the logical volume size by adding (+) 84 GigaBytes:

[root@myhost ~]# lvextend -L+84G /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 87.00 GB
Logical volume LogVol00 successfully resized

And now just to  extend the ext3 filesystem to take account of that extra space.

[root@myhost ~]# 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 22806528 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 22806528 blocks long.

Check that it worked and is now bigger.

[root@myhost ~]# df -h

Happy days.

10 Responses to “Increasing CentOS LVM under VMWare”

  1. Jens

    Hi,

    instead of adding an additional partition, you can delete the lvm partition and re-created it (of course in the same fdisk session 🙂 ). Save the changes and reboot.

    After that you execute the following commands
    * “pvresize /dev/
    * lvextend -l +100%FREE /dev//

    and last but not least the resize2fs on the lv and thats it 🙂

    Reply

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>