Increasing a Logical Volume
This article contains instructions for increasing the size of a Logical Volume using a Debian Linux VMware Virtual Machine (VM). This how-to information should be similar with other distributions of Linux.
Initial Position
As the screenshot above shows, the entire hard disk area that has been allocated to a VM is assigned for the boot partition, for one thing, and for the LVM, for another.
The LVM configuration is as follows for this example.
vm208:~# pvs PV VG Fmt Attr PSize PFree /dev/sda2 vm208 lvm2 a- 19,75G 0 vm208:~# vgs VG #PV #LV #SN Attr VSize VFree vm208 1 6 0 wz--n- 19,75G 0 vm208:~# lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert home vm208 -wi-ao 10,54G root vm208 -wi-ao 332,00M swap_1 vm208 -wi-ao 1,07G tmp vm208 -wi-ao 380,00M usr vm208 -wi-ao 4,66G var vm208 -wi-ao 2,79G vm208:~# df -h File System Size Used Avail Used% Shared as /dev/mapper/vm208-root 322M 175M 131M 58% / tmpfs 187M 0 187M 0% /lib/init/rw udev 10M 612K 9,5M 6% /dev tmpfs 187M 0 187M 0% /dev/shm /dev/sda1 228M 28M 189M 13% /boot /dev/mapper/vm208-home 11G 155M 9,7G 2% /home /dev/mapper/vm208-tmp 368M 11M 339M 3% /tmp /dev/mapper/vm208-usr 4,6G 332M 4,1G 8% /usr /dev/mapper/vm208-var 2,8G 280M 2,4G 11% /var vm208:~#
The size of the "root" logical volume for the "vm208" (/dev/mapper/vm208-root) volume group should be increased.
Step-by-step Instructions
Increasing the Size of the Hard Disk Area at the VMware Level
The VM dialog for configuring the settings will be opened by right-clicking the VM from the vSphere Client and then clicking "Edit Settings". From there, select the hard disk and increase its size to the desired value, from 20 gigabytes to 25 gigabytes for our example.
Once the VM has been re-booted, the following image should then appear.
Creating an Additional Partition
To be able to use this additional hard disk space, an additional partition must be created (such as by using the cfdisk utility). To do that, the free memory will be selected using the arrow keys and New > Primary > completely available memory selected (if desired). Afterwards, the area will be partitioned.
Afterwards, the new partition table must be written using the "Write" command and the partitioning utility closed using the "Quit" command. To continue with this example, the partition table must be re-read. To avoid another reboot, the partition table can be re-read by the "partprobe" command (a component in the "parted" package).
Initializing the New Partition as a Physical Volume
So that this additional partition can be used for LVM and a volume group assigned, it must next be initialized as a Physical Volume (PV).
vm208:~# pvs PV VG Fmt Attr PSize PFree /dev/sda2 vm208 lvm2 a- 19,75G 0 vm208:~# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created vm208:~# pvs PV VG Fmt Attr PSize PFree /dev/sda2 vm208 lvm2 a- 19,75G 0 /dev/sda3 lvm2 -- 5,00G 5,00G vm208:~#
Increasing the Size of the Volume Group
So that the size of the logical volume "root" can be increased, the size of the corresponding volume group must first be increased.
vm208:~# vgs VG #PV #LV #SN Attr VSize VFree vm208 1 6 0 wz--n- 19,75G 0 vm208:~# vgextend vm208 /dev/sda3 Volume group "vm208" successfully extended vm208:~# vgs VG #PV #LV #SN Attr VSize VFree vm208 2 6 0 wz--n- 24,75G 5,00G vm208:~#
Increasing the Size of the Logical Volume
Next, the size of the logical "root" volume can be increased.
vm208:~# lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert home vm208 -wi-ao 10,54G root vm208 -wi-ao 332,00M swap_1 vm208 -wi-ao 1,07G tmp vm208 -wi-ao 380,00M usr vm208 -wi-ao 4,66G var vm208 -wi-ao 2,79G vm208:~# lvextend -L 1G /dev/mapper/vm208-root Extending logical volume root to 1,00 GB Logical volume root successfully resized vm208:~# lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert home vm208 -wi-ao 10,54G root vm208 -wi-ao 1,00G swap_1 vm208 -wi-ao 1,07G tmp vm208 -wi-ao 380,00M usr vm208 -wi-ao 4,66G var vm208 -wi-ao 2,79G vm208:~#
In this example, we will increase the size of the logical root volume to roughly 1 gigabyte. We will reserve the remaining free memory for the vm208 volume group for later use for another logical volume, for example.
Note: The lvextend command will not indicate the amount by which the logical volume should been increased, but rather the final size to which it should be increased. Alternatively, the + symbol can be used before setting the size and the logical volume will then be increased about the specified size.
Increasing the Size of the File System
To be able to use the additional storage area, the size of the file system must finally be increased. ext3, which will support such increases without problems (even in the mounted state), has been used as the file system in our example.
vm208:~# df -h File System Size Used Avail Used% Shared as /dev/mapper/vm208-root 322M 175M 131M 58% / tmpfs 187M 0 187M 0% /lib/init/rw udev 10M 616K 9,4M 7% /dev tmpfs 187M 0 187M 0% /dev/shm /dev/sda1 228M 28M 189M 13% /boot /dev/mapper/vm208-home 11G 155M 9,7G 2% /home /dev/mapper/vm208-tmp 368M 11M 339M 3% /tmp /dev/mapper/vm208-usr 4,6G 332M 4,1G 8% /usr /dev/mapper/vm208-var 2,8G 281M 2,4G 11% /var vm208:~# resize2fs -p /dev/mapper/vm208-root resize2fs 1.41.3 (12-Oct-2008) The file system under /dev/mapper/vm208-root will be mounted as /, and online size changes will be necessary. old desc_blocks = 2, new_desc_blocks = 4 Execute an online size change to /dev/mapper/vm208-root to 1048576 (1k) blocks. The file system under /dev/mapper/vm208-root will now be 1048576 block large. vm208:~# df -h File System Size Used Avail Used% Shared as /dev/mapper/vm208-root 993M 176M 766M 19% / tmpfs 187M 0 187M 0% /lib/init/rw udev 10M 616K 9,4M 7% /dev tmpfs 187M 0 187M 0% /dev/shm /dev/sda1 228M 28M 189M 13% /boot /dev/mapper/vm208-home 11G 155M 9,7G 2% /home /dev/mapper/vm208-tmp 368M 11M 339M 3% /tmp /dev/mapper/vm208-usr 4,6G 332M 4,1G 8% /usr /dev/mapper/vm208-var 2,8G 281M 2,4G 11% /var vm208:~#
Summarization of the Steps
- Increase the size of the hard disk area (at the physical or VMware level)
- Reboot the machine so that the additional hard disk space will be detected
- Create an additional partition, for example, by using
cfdisk
- Re-read the partition table, such as, by re-booting or using the
partprobe
command - Initialize a new physical volume using the
pvcreate
command - Increase the size of the volume group using the
vgextend
command - Increase the size of the logical volume using the
lvextend
command - Increase the size of the file system, such as, by using the
resize2fs
command
Additional Information
- Logical Volume Manager (Wiki Ubuntuusers)
- Changing the File System Size (Wiki Ubuntuusers)
- What is the procedure to increase the size of an LVM2 logical volume and its file system? (Red Hat Knowledgebase, registration mandatory)