How to extend LVM disks in vCenter

LVM disk extension can be a challenging experience for who are not familiar with unix environment. I will try to explain it as simple as possible in this guide.
- Heads up: You need to reboot the virtual machine twice! There is no live-extension way for LVM in vSphere environment.
- If you want to do it live-extension, you need to add new VMDK hard disk to the VM and extend in the LVM console. I will write about that later.
- This guide is based on Ubuntu 12.04 LTS.
1. Enter your VM’s “Edit Properties” menu. Choose your hard drive and give more space as you want:
2. In the same window, click “Options” tab, choose “Boot Options” and enable “Force BIOS Setup” on the right side:
3. Click “OK”.
4. Go to g-parted web site and download the ISO file from there: http://gparted.org/
5. Right click on your VM and click “Open Console”. Click the “Connect CDROM” button on top right and choose “Connect to ISO image on local disk”.
6. Choose your g-parted ISO file and click “OK”.
7. Now reboot your VM. You will see the BIOS screen. Go to “Boot” tab. Using UP-DOWN arrow select “CD-ROM drive” and bring it before Hard Drive using “+” sign on your keyboard. Go to Exit tab and select “Exit Saving Changes”. This will reboot your virtual machine.
8. You will see boot screen of g-parted. Click “Enter” for G-Parted Live. (You can hit Enter for default selections for 9-10-11 steps)
9. Choose “Don’t touch keymap” for Configuring console-data.
10. It will ask for language selection. Type your language number and hit Enter. Default is 33 (English).
11. Choose G-Parted mod, default is “0”.
12. G-parted will boot and Device manager screen will be shown in the screen. Now select LVM device which’s File System is “extended”. It is /dev/sda2 in this example. Click “Resize/Move” button on top.
13. You will see a new popup resize screen.
14. Extend it by using scroll on the screen or by typing here. Click Resize/Move button. On main screen “Apply” button will be activated, click it to apply the configuration. It will ask again to be sure about it. After operation is successful, click “Close”. Exit the main screen and reboot your VM.
15. Your system will be boot normally, but you need to format the new size in order to use it in the LVM.
16. Check your disks in the OS, here are the some examples :
ls -al /dev/sda* output:
1 2 3 4 |
brw-rw---- 1 root disk 8, 0 May 12 15:27 /dev/sda brw-rw---- 1 root disk 8, 1 May 12 15:27 /dev/sda1 brw-rw---- 1 root disk 8, 2 May 12 15:27 /dev/sda2 brw-rw---- 1 root disk 8, 5 May 12 15:27 /dev/sda5 |
fdisk -l output:
1 2 3 4 |
Device Boot Start End Blocks Id System /dev/sda1 * 2048 499711 248832 83 Linux /dev/sda2 501758 31457279 15477761 5 Extended /dev/sda5 501760 20969471 10233856 8e Linux LVM |
As you can see we have sda5 device for LVM volume group.
17. We need to format and add the disk to sda.
Type:
1 |
fdisk /dev/sda |
Type “n” and “l” letters. Here we created /dev/sda6 (6 number is automatically selected by system):
1 2 3 4 5 6 7 8 9 10 |
Command (m for help): n Partition type: p primary (1 primary, 1 extended, 2 free) l logical (numbered from 5) Select (default p): l Adding logical partition 6 First sector (20971520-31457279, default 20971520): Using default value 20971520 Last sector, +sectors or +size{K,M,G} (20971520-31457279, default 31457279): Using default value 31457279 |
Change the type of the file system to LVM:
Type “t”, “6” and “8e” (We typed 6th device as we need to change sda6. 8e is the LVM type code)
1 2 3 4 |
Command (m for help): t Partition number (1-6): 6 Hex code (type L to list codes): 8e Changed system type of partition 6 to 8e (Linux LVM) |
Type “p” to check if it is correctly set:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Command (m for help): p Disk /dev/sda: 16.1 GB, 16106127360 bytes 255 heads, 63 sectors/track, 1958 cylinders, total 31457280 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x000028bf Device Boot Start End Blocks Id System /dev/sda1 * 2048 499711 248832 83 Linux /dev/sda2 501758 31457279 15477761 5 Extended /dev/sda5 501760 20969471 10233856 8e Linux LVM /dev/sda6 20971520 31457279 5242880 8e Linux LVM |
Type “w” to write the changes and use q to quit:
1 2 3 4 5 6 7 8 9 10 11 |
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 or after you run partprobe(8) or kpartx(8) Syncing disks. Reboot the server. |
As warning mantioned, we need to reboot the server.
After reboot, check if we can see the new device or not:
1 2 3 4 5 6 |
ls -al /dev/sda* brw-rw---- 1 root disk 8, 0 May 12 15:27 /dev/sda brw-rw---- 1 root disk 8, 1 May 12 15:27 /dev/sda1 brw-rw---- 1 root disk 8, 2 May 12 15:27 /dev/sda2 brw-rw---- 1 root disk 8, 5 May 12 15:27 /dev/sda5 brw-rw---- 1 root disk 8, 6 May 12 15:27 /dev/sda6 |
18. Create physical volume for sda6:
1 2 |
pvcreate /dev/sda6 Physical volume "/dev/sda6" successfully created |
19. Add sda6 disk to Volume Group:
Check the name of the volume group
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
vgdisplay --- Volume group --- VG Name ubuntutemp-vg System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 9.76 GiB PE Size 4.00 MiB Total PE 2498 Alloc PE / Size 2498 / 9.76 GiB Free PE / Size 0 / 0 |
Extend the Volume group with sda6:
1 2 |
vgextend ubuntutemp-vg /dev/sda6 Volume group "ubuntutemp-vg" successfully extended |
20. Extend the Logical Volume:
Check the logical volume:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
lvdisplay --- Logical volume --- LV Name /dev/ubuntutemp-vg/root VG Name ubuntutemp-vg LV UUID xxx LV Write Access read/write LV Status available # open 1 LV Size 8.76 GiB Current LE 2242 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:0 |
Extend the logical volume using all free space in the volume group:
1 2 3 4 5 6 7 8 |
lvextend -l +100%FREE /dev/ubuntutemp-vg/root Extending logical volume root to 13.75 GiB Logical volume root successfully resized root@mysql:/home/ubuntu# resize2fs /dev/ubuntutemp-vg/root resize2fs 1.42 (29-Nov-2011) Filesystem at /dev/ubuntutemp-vg/root is mounted on /; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 1 The filesystem on /dev/ubuntutemp-vg/root is now 3605504 blocks long. |
Check the mount points:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
df -ah Filesystem Size Used Avail Use% Mounted on /dev/mapper/ubuntutemp--vg-root 14G 8.1G 4.8G 64% / proc 0 0 0 - /proc sysfs 0 0 0 - /sys none 0 0 0 - /sys/fs/fuse/connections none 0 0 0 - /sys/kernel/debug none 0 0 0 - /sys/kernel/security udev 992M 4.0K 992M 1% /dev devpts 0 0 0 - /dev/pts tmpfs 401M 244K 401M 1% /run none 5.0M 0 5.0M 0% /run/lock none 1002M 0 1002M 0% /run/shm /dev/sda1 228M 56M 161M 26% /boot |
Thats it!