Resize and Expand a Virtualbox Hard Drive and Media Made Easy

Sorry this post has moved.

You can find the “Resize and Expand a Virtualbox Hard Drive and Media Made Easy” article here.

Comments from all previous readers can be found below and at the new post’s home.

Advertisement

48 thoughts on “Resize and Expand a Virtualbox Hard Drive and Media Made Easy

  1. VboxManage: command not found

    Linux is case sensitive… the “b” should be “B”.

    I looked for answers for some time so thought I might save others the struggle.

    zeddock

    • Thanks Zeddock for the feedback, you’re likely right that others got the same error due to the case.

      The post now has a note to readers to pay attention to the case of the commands.

  2. Suppose the Disk is /dev/sdb, the second scsi disk:
    fdisk /dev/sdb
    create as many partitions as you need using command n
    Label them with command t as 8e for making it Linux LVM
    Write and Exit with the command w.
    Format the partitions you require using mkfs command:
    mkfs -t ext3 -c /dev/sdb1
    LVM commands:
    pvcreate /dev/sdb1
    vgextend VolGroup00 /dev/sdb1
    lvextend -L 15G /dev/VolGroup00/LogVol00 ;for extending LogVol to 15GB
    lvextend -L+1G /dev/VolGroup00/LogVol00 ;for adding one more GB to Logical Volume LogVol01
    resize2fs /dev/VolGroup00/LogVol00 ;for resizing the Logical Volumes

  3. Pingback: Delicious Bookmarks for May 13th from 14:31 to 16:56 « Lâmôlabs

  4. Great stuff. However on the latest VirtualBox you will need to type in the “-” twice. So it will be “–exisiting” instead of “-existing”. Other than that, great. This is on Windows which I’m using.

    • Thanks Divine for pointing that out! You are absolutely correct.

      Apparently the webpage filtered the two dashes, but it has been fixed using the HTML code for dash twice (––)

  5. I am using VBox version 4.0.8 r71778

    One note, I had to make sure both of my hard drives (the existing one and the newly created one) were not attached to the virtual machine, before I could get the clonehd commnad to work.

    I also moved the –existing option to the end of the command.

  6. Pingback: andy rosen » Blog Archive » Expanding a VirtualBox drive

  7. Hi
    Thanks Justin for posting this, it has been a fantastic help in cloning the hd. One thing, I have been using a windows environment and I had been entering the VBOXManage –existing command as specified, from the Program Files\Oracle\VirtualBox directory where the VBOXManage program is stored, however the command was still not working. I had to add speech marks ” ” around “my old” and “new” hard disk directory paths for the hd to be cloned, otherwise I just kept getting the error “invalid parameter c:\directory\directory_path”.

    I hope this helps anyone else with a similar problem.

    • Thanks a lot Guy for your tip (on behalf of other Windows users), it has been added to the notes about VBoxManage in the post.

      And you’re welcome! glad the instructions were helpful and you could contribute your solution finding here :-)

  8. Thank you for this great share and wonderful read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff your upcoming blog posts…

      • 7 Nov 2011. Justin, Is there some benefit of doing the expansion of a disk by your method rather than using the “modifyhd” command? I’m running Virtualbox 4.1.2 with a 40GB virtual drive which has a .vmdk extension and VB lists as “normal”. (I’m on a Mac OS 10.6.8 host with a Windows XP SP3 VM.) VB says the virtual disk size is 40GB, and actual is already 39.42GB, so I need to expand it, and soon! I’m not a techie at all and can not afford to mess this up. Seems to me the “modifyhd” is less hassle than what you recommended, which appears to me to be more involved and risky plan. My problem is I don’t really know what to type in Terminal to expand my drive. If I want it to be a 100GB drive, do I just type in “VBoxManage MY_HARD_DRIVE.vmdk –resize 100000″? [As typed, I have two dashes in there before the word "resize"; it may be that the wordpress system will change them to an en dash.]Or do I have to type in “102400″ (1024 bytes x 100 = 102400 MB = 102.4GB, which may be the real value of what we call 100GB??). Sorry for the very specific question, but maybe there are other like me. Thank you.

      • Hi Eric,
        If you are worried about corrupting your VirtualBox hard disk, the best thing would be to save a copy of your vmdk on your Mac OS host before attempting any of the commands or anything here in the article. If something does go wrong, you can always mount your backup disk as the real guest.

        Given your comments, I believe modifyhd will not work due to the VirtualBox manual saying: “This [resize command] currently works only for expanding the capacity of VDI and VHD formats, and only for the dynamically allocated variants“. The issue with modifyhd resize is it only works in certain cases, otherwise there wouldn’t be a need for all the steps listed in this article.

        However, you can try it following VirtualBox manual with the syntax VBoxManage modifyhd <your filename> –resize 100000. That command would be for 100GB. Make sure you have two dashes and read the details (takes about 2 minutes) at http://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi.
        It should give you an error if the type of disk you are using is not supported.

        The instructions in the article seem complicated, so he are a summary of the steps if it helps you:
        1. Create a new disk with dynamically expanding storage that will solve your space issues forever (unless you reach a 2 TB hard disk).
        2. Clone your existing hard disk to the new disk.
        3. Attach the new cloned disk to your guest.
        4. Resize the logical space in the guest to recognize the expanded space.

      • I hope you don’t mind if I continue my saga here. I got no help on the Virtualbox forums :(
        Seems that .vmdk disks cannot be expanded by modifyhd commands. I tried this command line

        VBoxManage modifyhd &#x2012&#x2012resize 102400 [that's two dashes before the word "resize"]

        and I got this error: VBoxManage: error: Resize hard disk operation for this format is not implemented yet!

      • 7 Nov 2011
        Hi again, Justin,
        I didn’t realize you were up and responding so quickly to posts here :) Thus my last post was sent before I read yours.

        Now I’ve got real trouble: I first made a copy of the original 40GB .vmdk file in Finder on my Mac.
        I decided to follow the long route (only route) and failed. I made a new .vmdk harddrive in VB (this time I made it 200GB dynamic).

        When I tried to clone the old one, something didn’t work right and I got an error. Then I noted that I DID NOT have the new and old disk unattached to the Virtual Machine. I don’t recall the error. But I thought “No problem, I’ve got the backup HD on the Mac, I’ll use it and verify that my virtual machine will work with it. It didn’t. I attached the copy of the original HD, and tried to start the VM: Error: “Locking of attached media failed.” Details: Result Code: VBOX_E_INVALID-_OBJECT_STATE (0x80BB007). Now I cannot get either of my 40GB harddrives to work and I’m worse off than when I started. Any advice for newbies?

      • I am happy that I was able to restore the 40GB virtual drive file from an external backup drive and now the VM is back where it was at least. I just don’t know how to do what I need to do to expand it.

      • Hi Eric,

        You know, just last year I was in a similar situation as you with a 40GB fixed size maxed out VMDK hard disk for a Windows guest.
        So, if you follow the instructions here in the article, you will get a new large hard disk you can use.

        After you clone your VMDK disk with the clonehd command (http://www.virtualbox.org/manual/ch08.html#vboxmanage-clonevdi) to a VDI, you just have to attach it to your VM and remove the old one. Since you’re using Windows XP, the remaining part is to resize the partition in the guest. There are some tips in the article including some free software you can use or you can try Microsoft’s method.

        You’re smart enough to use VirtualBox so you should be fine following the steps here :-) Good luck,
        Justin

      • 8 Nov 2011
        Thanks, Justin. I’ll try again. I didn’t think I could clone a .vmdk to a .vdi file. Based on your response, I guess I can. (I saw that the tutorial said the new drive had to be the same kind as the old one, and thought that probably included not only SATA and other types, but also .vdi, .vmdk, etc.) I also saw that stuff in your tutorial about the partitioning and went to the MS site and the free program site. Looked a little daunting to me. When I do it I’ll probably try the free program route. I don’t feel comfortable at all with command line stuff. I’ll try again when I have some more time. Thanks again! I’ll try to remember to let you know when it works for me. :)

      • 02 Jan 2012 Thank you, Justin! It worked, and I’m a happy camper. As a severe (or permanent) newbie, I’m glad to have made my 40GB .vmdk into a 503.5GB .vdi virtual disk. I couldn’t have done it without your help here. (BTW, I’m using a Mac running Snow Leopard 10.6.8 with a Win XP guest.)

        Two suggestions (if I’m not the only newbie / non-tech person who might try to do this) regarding this part of the tutorial:
        “Make sure your VirtualBox directory containing the VBoxManage command is in your operating system path. In the command line console, change directory to your HardDisk folder (e.g. ~/.VirtualBox/HardDisks) and run

        VBoxManage clonehd old_hard_disk.vdi new_hard_disk.vdi ––existing

        (1) I didn’t know how to make sure that the VirtualBox directory containing the VBoxManage command was in my operating system path. Maybe some instructions about how to find out, and how to make it that way would help. In my case, it was, since I just tried to use it, and it worked.
        (2) I wasn’t sure how to change the directory/folder in the command line console (in my case, Terminal). I just guessed that maybe the command cd would work like it did back in DOS days. It did. But for others, maybe an explanation or link would be helpful.

        I really appreciate your generosity in sharing all this info!

      • Hi Eric, you’re welcome and thanks for your detailed feedback. Based on your all your feedback the article has been updated (especially the VBoxManage comment) and I’m considering how to make the article easier to follow (like a short section outlining the steps and a detailed section with helpful links like the change directory command).

  9. Great article, this saved me quite a bit of time having to reinstall an entire OS. I made the mistake of making the second drive a sata when the drive i wanted to clone was an ide but changed the new drive to ide and worked just fine. Thanks a ton!

  10. Hi folks… I’m brazilian and maybe gonna make some mistakes with your language. So…
    I was working with a VM that has a Peoplesoft 9.1 installation built in and while I was creating datafiles in oracle to support FSCM tables the size of oradata increased until make my work impossible. Then I solved my problem resizing the VDI file with VBoxManage modifyhd command and
    with the new space non allocated in hd I made a new volume and I mounted in principal partition as a NTFS folder. I named this folder as PSFT and I moved all my PSFT files to it.

    I hope this solution can help you… The advantage is the fact of no extra software be needed.

    Luis Alves
    Peoplesoft Consultant at E-Novasys Tecnology (Brazil)

    • Hi Luis, thanks for sharing your troubleshooting. It will help anyone using Virtualbox to host databases, especially Oracle.
      Sounds like your were able to get around the oradata size increases by using a new expanded volume and switching the partition used by Peoplesoft – PSFT. That is pretty interesting!

  11. Hi,

    If you’re working with a LVM partition a nice little gui for lvm managment is system-config-lvm. I’m working with Ubuntu 10 server and this worked great. This lvm gui allows you to extend your lvm partition into the unallocated space you created through the VBoxManage clonehd as indicated in this article.

    Thanks for the article Justin.

    David

  12. Well done, Justin Tung. I found your article and see Todd krein suggested free partition manager. It fixed my low disk space problem for my XP. Not only saved me a lot of time. but also saved money. best software I have ever seen.
    I would like to recommend it here again:
    http://www.extend-partition.com/free-partition-manager.html
    And here is a helpful article introduced the detailed information about partitioning hard drive, helped me a lot:
    http://www.extend-partition.com/resource/how-to-partition-a-hard-drive.html

  13. Very helpful thank you. My problem though is that after cloning, the new drive seems to be in an original state not the “current state” I assume this is something to do with snapshots but can’t figure it out. Is there a way to get my cloned drive to reflect my latest snapshot of the old drive. When I look at the settings it is set to “current state”

    Thanks for your help

    • Hi Clive,
      Thanks for your feedback.

      The issue you have was encountered by lots of other people and there are different approaches.

      Here are two possible solutions:
      1. Consolidate all your existing snapshots into one state (use discard old snapshots function in GUI) so the current state is the only state which will solve your cloning problems. This solution is probably the easiest.

      2. If you do not want to lose your snapshots, you could clone your *VM*, consolidate the snapshots and use the cloned HD for expansion while you still have the old VM for older snapshots.

      Here are a variety of solutions you can find by searching that lists the details:
      e.g.
      http://geek.co.il/wp/2009/03/18/cloning-virtualbox-vm-snapshots
      https://forums.virtualbox.org/viewtopic.php?t=791

    • Thanks Rodrigo for the citing the modifyhd command and instructions for Windows 7 guest when you have already have a dynamically allocated disk.

      As said in a previous comment, it is definitely good for increasing the logical size of disks. Unfortunately, modifyhd doesn’t cover a lot of things some of the people here are looking for.
      Per the VirtualBox manual: “–resize option allows you to change the capacity of an existing image…
      This currently works only for expanding the capacity of VDI and VHD formats, and only for the dynamically allocated variants.”

  14. Pingback: On later by e44gece - Pearltrees

  15. Pingback: IT by e44gece - Pearltrees

    • Great to hear gyaru. I’m wondering the same thing you are and if Oracle will make expanding a hard desk in VirtualBox a feature in the future or automate the commands listed here.

      A good solution going forward is always use dynamically expanding storage and use the maximum available size (e.g. 2 terabytes)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s