Chinaunix首页 | 论坛 | 博客
  • 博客访问: 98648
  • 博文数量: 35
  • 博客积分: 637
  • 博客等级: 上士
  • 技术积分: 290
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-15 17:22
文章分类

全部博文(35)

文章存档

2015年(6)

2014年(1)

2013年(3)

2012年(25)

我的朋友

分类: Oracle

2015-05-26 16:31:57

Resize VirtualBox Disk Image -- the easy and the hard way.Today I actually used up the 20GB of virtual disk space I set for the Windows XP I use for specific Windows Software. Who would have thought that an old Windows XP license would be useful again, eh? :)


After performing a quick search on how to manipulate an existing VDI file, I found a bunch of lengthy guides, all pretty much saying the exact same thing… create a new VDI, load the old and new VDI disk images into a Virtual Machine as a master and slave drive, boot with a gParted or equivalent BootCD image, and then clone the old disk to the new one… or in short: do a lot of steps that take forever, but not what I want: Resize VirtualBox Disk Image.

virtualbox

After flipping through the 10th or so guide, I realized that pretty much all of them were written in 2008… very unusual as bloggers usually write about the same subject on a yearly basis. That in mind, I search a bit more and… BINGO! Since VirtualBox 4 is out, there is a simple command line tool to resize VDI images. Man, those extra 5 minutes of searching just saved me from a lot of hassle and a huge waste of time.

Since I want to pass on this crucial bit of information, I hope mentioning that this article is about how to resize VirtualBox Disk Image in 1 Minute! will help to put this post up on the first page in google for people searching for this simple solution, and don't think they have to go through all those steps mentioned in other guides on how to change the size of a vdi disk image file… your help in spreading the word about this article featuring a super easy way to resize VirtualBox disk image is very much appreciated :)

You CAN NOT resize a snapshot .vdi file.
If you use snapshots, you need to DELETE all of them before resizing the .vdi OR you could clone the latest snapshot .vdi to a new .vdi (automatically merging all existing snapshots into one): # VBoxManage clonehd fullpath/{uuid-of-last-snapshot}.vdi the-new-disk.vdi and link "the-new-disk.vdi" to your virtual machine.

This is for VirtualBox running on Linux, Mac, and Windows. I found the Mac solution in the comments, and there may be some more tips I may have missed to add here.

HERE WE GO:

Using Windows as a Host
Open the command prompt and enter:
C:\Program Files\Oracle\VirtualBox\VboxManage.exe modifyhd YOUR_HARD_DISK.vdi --resize SIZE_IN_MB

Using Mac as a Host
open a Terminal session (not sure if that is what it is called in Mac, hehe) and type:
/Applications/VirtualBox.app/Contents/MacOS/VBoxManage modifyhd YOUR_HARD_DISK.vdi --resize SIZE_IN_MB

Using Linux as a Host
open a Terminal session and type:
VBoxManage modifyhd YOUR_HARD_DISK.vdi --resize SIZE_IN_MB


YOUR_HARD_DISK.vdi could be something like:
"C:\Virtual Boxes\Windows XP\Windows XP.vdi" OR
/Users/username/VirtualBox VMs/Litter/Litter.vdi OR
/home/username/VirtualBox\ VMs/WindowsXP/WindowsXP.vdi
SIZE_IN_MB would be 30000 for 30GB
If you get an error mentioning the VirtualBox COM server, start the VirtualBox Dashboard and make sure you have Administrator rights (command prompt as Administrator / not sure about Mac / sudo in Linux), then try again.


An alternative to using the path to the vdi file
open a Terminal session/command prompt and type:
VBoxManage list hdds
you will see something like this:
UUID: 5ebf0266-4e9e-4b7e-b9f6-6d67514919c3
Parent UUID: base
Format: VDI
Location: /VBOX/Windows XP/Windows XP.vdi
State: inaccessible
Type: normal
Usage: Windows XP (x86)

Using the above as an example:
VBoxManage modifyhd 5ebf0266-4e9e-4b7e-b9f6-6d67514919c3 --resize SIZE_IN_MB

And that's already all there is to it… I just wish they would include this in the GUI.


Note: You probably need to grow the partition to take up the space of the resized .vdi, look below and in the comments for some suggestions :)
If you have Linux installed as a guest, do this:
sudo resize2fs /dev/sda1
If you get a message along the lines of: "filesystem is already x blocks", then you need to follow my comment from August 22, 2013 08:30
Here is probably the easiest way to grow the partition while Windows (7, Server 2008 R2, or newer) is running on the VirtualBox Guest.
Using Windows Guest System:
1. Right-click Computer and select Manage.
2. Double-click Storage.
3. Double-click Disk Management.
4. In the list, right-click the partition to expand and select Extend Volume.
5. Follow the prompts to resize the partition and click Finish. The partition item in the Disk Management pane displays its new size.
6. Close the Computer Management window

Should you be using a VirtualBox version older than VirtualBox 4 and are looking for a way to resize a VDI VirtualBox Harddisk file,  here are the articles I flipped through but luckily did not have to follow:

Increase the size of a .vdi file

Resize VirtualBox Disk Image vdi files to bigger size

How to Resize a VirtualBox vdi file

Expand vdi virtualbox disk image

http://blog.markloiseau.com/2010/05/expand-vdi-virtualbox/

Grow a virtual drive, vdi Virtual box disk image


Source of the easy way:

This post has been viewed 118031 times!

阅读(1885) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~