I have virtualbox-4.1.0 with centos-5.6 installed in. Now I would like to extend the VM image, which I previously allocated for virtual machine installation, it was 8Gb, that's not enough now. Is there a way to extend the partition without loosing information?
Actually in centos I have one root fs with my home dir etc. so this partition eventually would need to be resized.
Thanks in advance for suggestions!
It can be done in 4 steps :
The detailed steps are below (tested with "Virtual Machine CentOS 6.4" and "VirtualBox 4.2.18");
Observe disk format of the virtualbox file, if it is not *.vdi, convert disk format from *.wmdk to *.vdi. Open windows terminal:
$ VBoxManage clonehd --format VDI "path_of_wmdk_file" "path_of_vdi_file"
Resize disk size of vdi file. Open windows terminal. For example to do disk size ~500 GB => 512000;
$ VBoxManage modifymedium "path_of_vdi_file" --resize 512000
Choose *.vdi file instead of *.wmdk file as disk
Virtual Machine -> Settings -> Storage -> Controller : SATA (Right Click on *.wmdk file) -> Remove Attachment -> Add HardDisk and choose newly created *.vdi file
Download "gparted-live-x.xx.x-x-ixxx.iso" file from http://gparted.sourceforge.net/download.php. Mount this iso file as CD.
Virtual Machine -> Settings -> Storage -> Controller IDE (Right Click) -> Add CD/DVD -> Select gparted-live-x.xx.x-x-ixxx.iso file
Run virtual machine, Virtual Machine will boot from this CD. Choose default values with pressing "Enter", "Enter" ... until Gpart ISO GUI starts. Select tool gpart program and start.
Extend disk size as below;
Virtual Machine -> Settings -> Storage-> Controller IDE (Right Click on gparted-live-x.xx.x-x-ixxx.iso) -> Remove Attachement
Open linux terminal and login as root. Run commands below;
lvm vgdisplay => Free PE / Size 122880 / 480.00 GiB
lvm lvdisplay /dev/VolGroup/lv_root => Current LE 3978
lvm lvresize -l 126858 /dev/VolGroup/lv_root
resize2fs /dev/VolGroup/lv_root
lsblk ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom sda 8:0 0 500G 0 disk +¦sda1 8:1 0 500M 0 part /boot L¦sda2 8:2 0 499.5G 0 part +¦VolGroup-lv_root (dm-0) 253:0 0 480G 0 lvm / L¦VolGroup-lv_swap (dm-1) 253:1 0 4G 0 lvm [SWAP] ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
fallocate -l 480G /test_file
rm -rif /test_file