Extend a CentOS Oracle VirtualBox Image with more Disk Space

This is a note to myself. Hopefully good enough for me to reuse it one day. So the following instructions will probably only give you a rough idea if you found this page looking for help on Google.

Anyway, these steps worked fine for me. What a bliss not having the file systems 98% full when starting a project. Somehow, I always run out of disk space when I install SOA Suite. No matter how big I initially size it. 

The challenge certainly is to get VBoxManage, fdisk and lvm right without completely messing up your system.

 

Warning!

fdisk and to a lesser extend lvm are razor sharp tools that can easily cause bleeding wounds. So make sure you have a backup (<- repeat this last sentence after me).

 

On Host side (e.g. Windows 7 here)

VBox instance has to be shut down for the following steps.

Extend the VBox image

Run the from the command line on the host system:

C:\Users\frank>"\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyhd --resize 29696 "\01_work\30 vms\virt
box\CentOS 6.4 64b STUDENT\CentOS 6.4 64b STUDENT.vdi"

On Guest side (e.g. CentOS 6.4 here)

Stay calm

Double check that you are on the guest side. Runing fdisk accidentially on the host side can destroy your whole computer, whereas running it on the guest side typically reduces the risk to destroy your virtual image only.

fdisk

Use fdisk -l to list devices, then e.g. fdisk /dev/sda to add another primary partition (coomand n), next free number (e.g. 3), of type 8e (Linux LVM) (t), print part table (p), write table (w). Reboot…

 

Add new partition as physical volume (PV)

[root@ccloud12 ~]# lvm

lvm> pvcreate /dev/sda3
 Physical volume "/dev/sda3" successfully created

 

Extend existing volume group (VG)

lvm> vgextend vg_ccloud12 /dev/sda3
 Volume group "vg_ccloud12" successfully extended

 

Find out partition name

lvm> lvdisplay
 --- Logical volume ---
 LV Path /dev/vg_ccloud12/lv_root

 

Extend logical volume

lvm> lvextend -L+8.48G /dev/vg_ccloud12/lv_root
 Rounding size to boundary between physical extents: 8.48 GiB
 Extending logical volume lv_root to 25.56 GiB
 Logical volume lv_root successfully resized

Resize the File System (Guest System)

resize2fs -F /dev/vg_ccloud12/lv_root

That’s it

Try df -h and enjoy your new diskpace.

 

Let me know if you had any success eg. using Oracle Enterprise Linux. Any super secret tips how to improve or shorten this are welcome.

Comments

  1. you forgot the final command : resize2fs -F /dev/vg_ccloud12/lv_root

    thx !

  2. Awesome, worked like a charm and I am all new to Linux. Thanks for the post!

  3. Super, great post :), It was very helpful!

  4. SuperUser says:

    Great job! Thanks for the info. After using fdisk you can invoke system-config-lvm and initialize the new partition, add it to the existing volume group and edit properties of the existing logical volume. That will re-size your file system also.

  5. Amazing… It worked..thanks

  6. Thanks. Perfect.

  7. Thank you very very much. This was very helpful.

  8. Awesome! After having read a lot of stuff that didn’t work, THIS finally worked!
    You saved me. I’m in an importan customer project.
    *tumbs_up* :)

  9. Thank you so much for this post. It helped me a lot!!!

  10. You saved my day man..! Thanks a lot from the heart.!

    I had setup development server, perfectly working steps to increase LogicalVolume of Linux Virtualbox HDD.

  11. vladimirfp says:

    thanks a lot Man!

  12. mjackson says:

    Thanks! This is the only LVM resize recipe that worked for me on VirtualBox 4.3.

  13. Thanks so much for the article.
    3 elements of note from my experience tho I was able to get this working.
    Note, I’m recently returning to Linux so am very rusty but am suspect people using this guide are in the same boat.

    Firstly, most of the commands gave me permission errors but worked with sudo.

    Second, “vg_ccloud12″ is the name of the existing volume group.
    Users should replace that with whatever their volume group name is. This can be found using vgs.

    Lastly, resize2fs errored for me.
    If it does for anyone else, I recommend you read this (http://stackoverflow.com/questions/26305376/resize2fs-bad-magic-number-in-super-block-while-trying-to-open) and subsequently try using xfs_growfs (“xfs_growfs /dev/vg_ccloud12/lv_root” in the above example).

    Maybe some of this stuff is trivial but wanted to comment since the rest of the article was spot on perfect.
    Hope that helps someone and thanks again!
    JD

Speak Your Mind

*