Change Size of Virtual Disk

This is for discussing general topics about how to use VirtualBox.
tenkros
Posts: 16
Joined: 16. Apr 2008, 17:25

Change Size of Virtual Disk

Post by tenkros »

Is it possible to increase the size of the virtual disk ?
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Change Size of Virtual Disk

Post by mpack »

Is it possible you didn't search the forums before asking?
tenkros
Posts: 16
Joined: 16. Apr 2008, 17:25

Re: Change Size of Virtual Disk

Post by tenkros »

Is it possible that you are more polite ?
FrodoHobbits
Posts: 237
Joined: 18. Apr 2009, 08:20
Primary OS: MS Windows 7
VBox Version: PUEL
Guest OSses: Windows, QNX & Linux
Location: Radstock, UK

Re: Change Size of Virtual Disk

Post by FrodoHobbits »

mpack is the author of the most excellent tool you are looking for.
The reply he came back with was the usual sort of reply you would expect :wink:
Search for CloneVDI or just look around and you will soon enough stumble upon it.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Change Size of Virtual Disk

Post by mpack »

Also, please update your profile so we know which guest and host OS you are using, as that influences the choice of best answer.
tenkros
Posts: 16
Joined: 16. Apr 2008, 17:25

Re: Change Size of Virtual Disk

Post by tenkros »

I am not used to get such kind of replies from companies who care for their customers.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Change Size of Virtual Disk

Post by mpack »

tenkros wrote:I am not used to get such kind of replies from companies who care for their customers.
You haven't had a reply from the company at all, nor are you a customer unless you paid for your copy of VirtualBox.

This site is run by volunteers and yes, we resent the time we volunteer being hogged by people who are too lazy to read the manual and/or search the site before asking a FAQ.
shawnlau
Posts: 20
Joined: 28. Nov 2010, 02:58
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: Ubuntu 64, Windows 7

Re: Change Size of Virtual Disk

Post by shawnlau »

What OS are you using for the host and what OS for the guest?
shawnlau
Posts: 20
Joined: 28. Nov 2010, 02:58
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: Ubuntu 64, Windows 7

Re: Change Size of Virtual Disk

Post by shawnlau »

tenkros wrote:Is it possible to increase the size of the virtual disk ?
Yes. How you do it depends on the host OS and the guest OS. If the host OS is windows, you will probably use the GUI CloneVDI tool found here : http://forums.virtualbox.org/viewtopic.php?f=6&t=22422

If you are using linux as a host OS, you will probably just run Vboxmanage with the clonevdi argument. E.g., Vboxmanage clonevdi "mydrive.vdi" "copyofmydrive.vdi"

Now I'm still looking into it but I'm sure there are other arguments you can add in the command line to enlarge the virtual size of the drive. I've little doubt the clonevdi tool is just creating a command line from the options you check in the GUI.

While you can do the same thing in Windows using the command prompt (the dos window), the CloneVDI tool saves you from having to go to the dos prompt, and has editable boxes to change attributes you would have to enter at the command prompt, e.g., virtual size.

After you have cloned the disk to a new size, you then have to use a tool to make that (unallocated) space available to the VM. What tool you use to do that depends on the guest OS. If its Windows 7 you can easily claim the space with the disk management tool. You simply grow your drive by the amount of unallocated space. In linux, you'll probably load the gparted.iso into the virtual CD and boot up the VM. The gparted program has a graphic interface that allows you to stretch and delete different partitions. In my case, I simply deleted the extended and swap file partitions and stretched the remaining partition to the new length. I really doubt this is the right way, but nothing has exploded yet and my data remained uncorrupted. I don't see a swap file pr extended partition after rebooting, but I'm willing to bet there's a way to add these with gparted. But as I've said, the VM runs fne.

So yes you can enlarge the virtual disk, but how you do it will depend on the host OS and guest OS and how comfortable you are with running programs from the command line.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Change Size of Virtual Disk

Post by Perryg »

Just a note. Gparted can assign a swap partition. When growing the primary partition stop short of the entire drive. Usually a few GB are all you need but if you want things like hibernate and ample disk space to swap you need to actually make it 1 1/2 times the size of RAM to 2 times the size of RAM. Be sure to mark it as swap.
shawnlau
Posts: 20
Joined: 28. Nov 2010, 02:58
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: Ubuntu 64, Windows 7

Re: Change Size of Virtual Disk

Post by shawnlau »

Perryg wrote:Just a note. Gparted can assign a swap partition. When growing the primary partition stop short of the entire drive. Usually a few GB are all you need but if you want things like hibernate and ample disk space to swap you need to actually make it 1 1/2 times the size of RAM to 2 times the size of RAM. Be sure to mark it as swap.

Thanks for that. I was confident it was wrong, and if I'm sure after time the side effects of no swap file would become apparent :) I wasn't so sure about the extended partition. I do remember from early windows days ( when it was still possible to set the size of your swap file) about the swap file being set to a percentage of ram. I of course have the source vdi and will try cloning it again, stretching the extended partition, moving the swap file to the end, and then stretching the primary partition.

If I get what is right, I'll post the exact steps. Thanks for the help.
tenkros
Posts: 16
Joined: 16. Apr 2008, 17:25

Re: Change Size of Virtual Disk

Post by tenkros »

Many thanks to shawnlau and Perryg for their exhaustive, very clear and helpfull assistance.
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Change Size of Virtual Disk

Post by mpack »

A couple of minor corrections :-
shawnlau wrote:If you are using linux as a host OS, you will probably just run Vboxmanage with the clonevdi argument. E.g., Vboxmanage clonevdi "mydrive.vdi" "copyofmydrive.vdi"
In fact the "clonevdi" argument for VBoxManage has been obsolete for quite some time. It is kept for backwards compatibility reasons, but new users should be encouraged to use the correct syntax: "VBoxManage clonehd", which is also how the command description can be found in the user manual.
shawnlau wrote:I've little doubt the clonevdi tool is just creating a command line from the options you check in the GUI.
In fact it isn't. As it says in the link which you posted, the CloneVDI tool is "not just a front end for VBoxManage". It is entirely stand alone and does not require any part of VirtualBox to be present in order to work. Indeed, that's why it can do things which VBoxManage can't, such as enlarge a drive, or compact a filesystem that hasn't had sdelete / zerofree run on it first, etc.
shawnlau
Posts: 20
Joined: 28. Nov 2010, 02:58
Primary OS: MS Windows 7
VBox Version: OSE other
Guest OSses: Ubuntu 64, Windows 7

Re: Change Size of Virtual Disk

Post by shawnlau »

mpack wrote: In fact it isn't. As it says in the link which you posted, the CloneVDI tool is "not just a front end for VBoxManage". It is entirely stand alone and does not require any part of VirtualBox to be present in order to work. Indeed, that's why it can do things which VBoxManage can't, such as enlarge a drive, or compact a filesystem that hasn't had sdelete / zerofree run on it first, etc.
That good to know. I had no idea Vboxmanage couldn't change the size of a virtual drive. I was assuming the size was kept somewhere in the header and it was a simple matter of editing that object member. I guess the VDI file structure is listed somewhere on this site?
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Change Size of Virtual Disk

Post by mpack »

shawnlau wrote:I guess the VDI file structure is listed somewhere on this site?
There's a tutorial called "All About AVIs" (see the "Howtos and Tutorials" forum) which gives a good description of the technical aspects. Of course the definitive source of structure information is the VirtualBox source code.

Changing a VDIs size isn't hard, but it's more than just changing a value in a header field. Eg. the block table needs to change to suit the new image size.
Post Reply