Wednesday, March 02, 2011

Resizing VirtualBox Virtual Hard Disk (vdi image)

بسم الله الرحمن الرحيم

Assalamualaikum WBT. Today I stumbled upon my VirtualBox hard disk problem. I wanted to install Adobe Photoshop CS5 however, the space available was too small for the disk hogged software. I googled around and luckily found a blog as if it was created to solve my not so little problem. Here is the exact url I will try to make it easier to understand. I am using Crunchbang linux (Statler) as the host and a closed source VirtualBox (I need USB support).

What You Need?
  1. Shut down the Virtual Box that uses the disk you want to resize.
  2. Remove any snapshots you have.
  3. Backup your vdi image (the VirtualBox hard disk).
  4. Download GParted LiveCD iso here.
  5. Create a new larger disk (according to size that you need).
  6. Attach the new created disk to your VirtualBox as slave.
  7. Mount the GParted iso to your VirtualBox.

Next Steps
  • Boot the virtual machine from the mounted ISO – you may need to reconfigure your VirtualBox to ensure that you boot from the CD-ROM drive before the HDD, so change the VirtualBox settings as shown below or hit F12 at boot and change there.

  • During the boot process the gparted Live CD will prompt you to select the correct keymap – if you are using a QWERTY keyboard, simple select the ‘Don’t Touch Kepmap’ option; next, you will be prompted for the language settings to be used – select the appropriate language code, in my case ’02′ for British English; finally, you will be prompted for the X-Windows mode – select ’0′ to automagically start gparted in an X-Windows session.

  • Once gparted starts, you will be presented with a graphical representation of your disks – left-click the left-to-right bar named /dev/sda1 (your primary hard disk that is to be expanded) and then click on the Copy icon.

  • Select the drop-down-box to the right of the tool-bar and select the second (currently empty) disk – /dev/sdb (possibly /dev/hdb in your environment), the graphical representation of your disks will change to show you the second slave disk which is currently empty. Click on the Paste icon.

  • gparted will will prompt you that all data on the new partition will be erased and if you’re happy, subsequently prompt you on how the disk should be formatted. For a Windows environment, select MSDOS (this will give you an NTFS partition, trust me!).

  • gparted will finally present you with a slider dialog indicating the desired size of the new disk. Drag the slider to the right to select the maximum size of the new partition on this new disk (I’d just drag it so the partition consumes the whole disk), as shown in the screenshot below:

  • Click the Apply icon, you’ll be presented with something along the lines of the screenshot below as the contents of the source disk are copied to the new, larger, disk:
  • Once the copy has completed (approx. 35 mins to create a 30Gb disk from an original 20Gb disk), you will need to mark the new disk as bootable (if this is to be a bootable partition – if not, simply skip the next step).

  • To mark the partition as bootable, right-click the graphical representation of the new disk and left-click Manage Flags. In the dialog that appears, select Boot and click Ok to close. gparted will apply the necessary flag and re-scan your disks.

  • Close gparted and click the Exit icon to shutdown the system.

Completing the Re-Sizing
  • Once the virtual machine has powered off, re-configure the hard disks to use the newly created/copied disk as the primary and remove the old primary disk from the system; finally, unmount the System Rescue ISO from the CD-ROM.

  • Power on your new VM and you should be presented with the the usual Windows boot sequence; if you are just presented with a black screen with a flashing cursor at the top left-hand corner of the screen, there isn’t a boot sector on the disk, so restart gparted and add the boot flag as directed above.

  • Hopefully, your virtual machine will start without issue. Windows may perform a check of the disk during boot. Once logged-in, open Windows Explorer and confirm that the newly created drive is the new larger size.

No comments:

Post a Comment