Sunday, January 30, 2011

Resizing a VirtualBox Virtual Hard Disk

Prior to version 4.0, expanding the size of a virtual disk was not a task that was directly supported by VirtualBox. After some trial and error, I've cobbled together a solution documented below which consolidates and amends information found elsewhere online.

For VirtualBox versions before 4.0, the procedure, in broad strokes, involves the following steps.

  1. Create a new virtual disk.
  2. Clone the existing virtual disk into the new virtual disk.
  3. Replace the old virtual disk on your virtual machine with the new one.
  4. Expand the partition in the new virtual disk clone.

As of VirtualBox 4.0 (released December 22, 2010), the process has gotten a lot simpler. You may replace the first three steps with a single VBoxManage command. [Thanks to Przemysław for pointing this out.] You will still need to perform the final step of expanding the partition in your newly resized virtual disk image.


Before you start this procedure you'll need to do the following.

  • Make sure you have the VBoxManage command-line tool installed on your host system.
  • Download the ISO for a GParted Live CD or else a Linux Live CD using a Linux distribution that includes the GParted partition editor utility.
  • IMPORTANT: If the virtual disk you want to resize is attached to a virtual machine with snapshots, you will need to delete these snapshots so that all disk state information is merged into the base virtual disk VDI file.

0. Resize the virtual disk (VirtualBox version 4.0+ only)

If you are using VirtualBox version 4.0 or later, you can resize the logical capacity of a virtual disk using the VBoxManage modifyhd --resize command.

On the host system, run the following command:

cd /path/to/vbox/disks

VBoxManage modifyhd OldDisk.vdi –-resize 30000

where OldDisk.vdi is the filename of the virtual disk VDI file you want enlarge and 30000 is the new maximum size (in megabytes) of the virtual disk.

If your host OS is Windows, then the commands you need to enter at the Command Prompt will look more like the following.

cd "C:\Documents and Settings\myusername\.VirtualBox\HardDisks"

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyhd OldDisk.vdi --resize 30000

Once you've resized your existing virtual disk, you should skip to Step 4: Expand the partition on the larger disk.

1. Create a new virtual disk

You can create a new virtual disk of the desired storage size in two ways: using the VirtualBox GUI or using the VirtualBox command-line utility VBoxManage.

1a. Using the VirtualBox GUI

On the host system, launch VirtualBox, and navigate to File → Virtual Media Manager… → Hard Disks. Click Add to add a new virtual hard disk, and step through the wizard, making sure to create a new maximum disk size that accommodates your needs.

1b. Using the VirtualBox command-line utility

On the host system, run the following command:

cd /path/to/vbox/disks

VBoxManage createhd –-filename NewDisk.vdi --size 30000 --remember

where NewDisk.vdi is the filename of the new virtual disk VDI file and 30000 is the maximum size (in megabytes) of the virtual disk.

Note that on Windows you may need to designate the full path to the VBoxManage command. For example, on a Windows host system at the Command Prompt, the above commands will instead look something like the following.

cd "C:\Documents and Settings\myusername\.VirtualBox\HardDisks"

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" createhd –-filename NewDisk.vdi --size 30000 --remember

2. Clone the existing virtual disk into the new virtual disk

Now clone the old, small virtual disk into the new, large virtual disk.

cd /path/to/vbox/disks

VBoxManage clonehd OldDisk.vdi NewDisk.vdi --existing

If your host OS is Windows, then the commands you need to enter at the Command Prompt will look more like the following.

cd "C:\Documents and Settings\myusername\.VirtualBox\HardDisks"

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" clonehd OldDisk.vdi NewDisk.vdi --existing

3. Replace the old virtual disk on your virtual machine with the new one

3a. Using the VirtualBox GUI

On the host system, launch VirtualBox, and select the virtual machine whose hard disk you are expanding, and navigate to Settings → Storage. Change the SATA Controller so that it uses the new virtual disk file instead of the old one.

3b. Using the VirtualBox command-line utility

VBoxManage modifyvm "My Virtual Machine" --hda none

VBoxManage modifyvm "My Virtual Machine" --hda NewDisk.vdi

Or for Windows host systems:

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "My Virtual Machine" --hda none

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyvm "My Virtual Machine" --hda NewDisk.vdi

where My Virtual Machine is the name of the virtual machine whose disk you are expanding.

(At this point you may want to boot your virtual machine to test whether it works. If you do, remember to shut it down before continuing.)

4. Expand the partition in the larger virtual disk

Now that you have an enlarged version of your virtual disk, you will want to expand the new disk's partitions to take advantage of the increased disk size. To do so we'll use the GParted partition editor.

If you have created a GParted Live CD or Linux Live CD, place it in the CD/DVD drive on your host machine, and change the settings of your virtual machine to use the host drive as its CD/DVD drive. If you have the ISO for the Live CD, simply configure your virtual machine so that it uses the Live CD ISO file for its CD/DVD drive. Navigate to Settings → Storage to configure the CD/DVD settings for your virtual machine.

Make sure that the virtual machine is configured to include CD/DVD-ROM in the boot order. To check the boot order, navigate to Settings → System → Motherboard.

Start the virtual machine. The virtual machine should boot from the Live CD.

If you are using the GParted Live CD, then you should see the GParted utility. If you are using a Linux Live CD, you may need to click on a menu item to indicate you want to try the Linux distribution without installing it.

Once the Gnome or KDE desktop environment is finished loading, open the Terminal application, and then enter sudo gparted to launch the GParted utility.

Now that you have launched GParted, in the upper right of the GParted window, make sure the correct disk has been selected — e.g. /dev/sda (30.00GB). Select the partition you want to expand — e.g. /dev/sda1 — and click the Resize/Move button.

In the pop-up window, expand the partition to use the maximum size. You can do so by dragging the right edge of the partition block all the way to the left. Click the Resize/Move button.

Note: If there is a swap partition, you may need to take a few extra steps to ensure that the unallocated space is immediately after the partition you want to grow. See the addendum below for more information on how to move the unallocated space.

Click the Apply button to apply the partition changes.

Quit GParted, and shutdown the virtual machine. Eject the CD from the host machine's CD/DVD drive or modify the virtual machine settings to unmount the ISO from the virtual machine CD/DVD drive.

Start the virtual machine again, and at the command line, type df -h to validate that the partition has been resized properly.


ADDENDUM: Special Notes Regarding Swap Partitions

If virtual disk you are editing via GParted has a swap partition, you may find that the newly available free space on the disk is separated from the partition you want to expand by the swap partition. This presents a problem because in order to expand a partition, the free, unallocated disk space must be located immediately after the partition.

One way to deal with the problem is to move the swap partition so that the unallocated space is before the swap partition rather than after it. Another is to delete the swap partition altogether.

Moving the swap partition

Right-click the swap partition, and select the Swapoff item in the context menu to disable the swap partition. Doing so will unlock the swap partition so that you may modify it.

Select the extended partition that contains the swap partition, and click on the Resize/Move button.

In the pop-up window, take note of the partition size (e.g. 486 MB).

Drag the right edge of the partition all the way to the right, and then drag the left edge of the partition toward the right until the new partition size is back to what it was — in this example, 486 MB. Click the Resize/Move button.

Click the Apply button. Re-enable the swap partition by right-clicking on it and selecting Swapon.

You should now be able to expand the main partition into the unallocated space.

Deleting the swap partition

Right-click the swap partition, and select the Swapoff item in the context menu to disable the swap partition. Doing so will unlock the swap partition so that you may modify it.

Select the extended partition that contains the swap partition, and then click the Delete button.

You should now be able to expand the main partition into the unallocated space.

Friday, November 06, 2009

Terminal Colors in PuTTY, Shell Colors, Syntax Highlighting in Emacs

Getting colors to show up in my PuTTY terminal window while navigating the file system in bash and editing a JavaScript file via emacs — that’s all I wanted to do. It took a bit of web research to find a solution, so I’ve decided to compile what I’ve found and post it here.

Enabling Colors in PuTTY

First, you need to make sure your PuTTY sessions are configured to display colors.

As indicated in the PuTTY documentation, you should start your PuTTY client and then under the Window > Colours settings category, enable Allow terminal to use xterm 256-colour mode.

Enabling Command-Line Shell Colors

Enabling shell colors essentially involve two components: (a) coloring the output of an ls command, and (b) coloring the shell prompt.

The easiest way to color the output of ls commmand is, as this forum thread points out, to put the following lines in your .profile or .bashrc file (or in the system-wide /etc/profile file).


For now, how to color the shell prompt is not covered here.

Enabling Syntax Highlighting in emacs

To get emacs to attempt to perform syntax highlighting, you must set the font-lock-mode of the buffer. The following explanation is an excerpt from the emacs manual:

font-lock-mode is the standard way to have Emacs perform syntax highlighting in the current buffer.

To automatically invoke font-lock-mode for all major modes, you can turn on global-font-lock-mode by including the following line in your `.emacs' file:

(global-font-lock-mode 1)

To test whether emacs now displays colors, start emacs and then run M-x list-colors-display — i.e., press Alt-x, type list-colors-display, and then hit Enter. You should see a list of all the colors emacs knows how to display.

Recognizing JavaScript Syntax in emacs

Although you’ve now enabled syntax highlighting emacs, it may not know which files contain JavaScript or what the language syntax is. In order for emacs to recognize JavaScript, you need to load an emacs mode file. After some trial-and-error with other JavaScript mode files, I found the javascript.el mode file, which was recommended by Edward O’Connor.

Download the file, and place it in your emacs load path — e.g., under /usr/local/share/emacs/site-lisp on FreeBSD). Then add the following lines to your .emacs file:

(autoload 'javascript-mode "javascript" nil t)
(add-to-list 'auto-mode-alist '("\\.js\\'" . javascript-mode))

If you’re like me and prefer indentation as a tab rather than four character spaces, you may want to edit the javascript.el file by modifying the javascript-indent-level line so that the level value is 8 instead of 4:

(defcustom javascript-indent-level 8
    "Number of spaces for each indentation step."
    :type 'integer
    :group 'javascript)


That’s it. Hope this was useful to some.

Sunday, August 12, 2007

The Bourne Ultimatum Ultimatum: Day 3

From: Eugene
Date: Aug 12, 2007 7:36 PM
Subject: Re: Bourne Ultimatum Ultimatum

Great news, team! We did it!

You should all pat yourselves on the back. We couldn't have done it without the hard work of each and every person on the team. Kudos, gang!

As a special token of appreciation for all the outstanding work, everyone involved will receive an official "'Bourne Ultimatum' Theatrical Viewing" T-shirt. You should get your shirt in the next few days; I managed to dig up our corporate FedEx ID, so we'll be sending the shirts out next-day air. (Don't tell Donna at the front desk -- she'll throw a fit!) If you're curious and can't wait the two days, a preview of the T-shirt design is attached. Thanks to Dillon in creative for putting this together -- and on such short notice!

It has been a long, hard slog for some of us -- Mountain Dew at 3am? Yuck! -- but it has also been great fun working with such a talented group of people, and I'm not just saying that. I hope some of us will get the chance to work together again on another project in the future -- I believe "Superbad" is opening next weekend -- but if not, at the very least perhaps we'll run into one another at the next departmental off-site or the annual corporate retreat. (I hear next year's is slated for Orlando. Fun!)

Thanks again for all the stellar work!



P.S. Don't forget that the building alarm code has changed, so if you're the last one out tonight, please remember to use the new code. I got an earful from Donna this morning about how the alarm wasn't set properly over the weekend. Yikes!

Attachment #1:
Attachment #2:

Saturday, August 11, 2007

The Bourne Ultimatum Ultimatum: Day 2.2

Status Update:

The Bourne Ultimatum Ultimatum: Day 2.1

From: Eugene
Date: Aug 11, 2007 12:26 PM
Subject: Re: Bourne Ultimatum Ultimatum

I figure I'm about due for a progress report on my seeing "The Bourne Ultimatum" today.

SATURDAY 11:45 AM. Still in pajamas. (Dang.) No longer drunk. (Nice.) It's early in the day, yet somehow Chris Crane has already found the time to yell at me on the phone.

OPEN ACTION ITEMS: Take a shower. Eat a burrito or else eggs. Pick up some dry cleaning. Decide which of today's showings best fits my projected readiness time (PRT) and aversion to crowded theaters.

POTENTIAL BLOCKING ITEMS: TiVoed episode of "Mad Men." Deeply ingrained psychological predilection toward stasis.

PROGRESS: Project completion is at, let's say, 86%.

More information may or may not follow.



Friday, August 10, 2007

The Bourne Ultimatum Ultimatum: Day 1

From: Eugene
Date: Aug 10, 2007 10:39 AM
Subject: Bourne Ultimatum Ultimatum

I am definitely going to watch this bad boy this weekend and am prolly going to do this tomorrow (Saturday) in the late morning or early afternoon. (I have a BBQ in Sunnyvale that I hope to make around 3:30.)

If you're into it, let me know.


Thursday, June 01, 2006

Wireless Connectivity Problems with the ThinkPad T60p

Preamble: This is probably not the best place to post this information—a ThinkPad forum or Lenovo/IBM support site might make more sense—but I don’t really feel like going to the trouble of registering for an account at such a site. I hope that Google’s search engine will do the hard work of bringing interested users to this content.

Description of the original problem: I purchased a ThinkPad T60p and discovered that my wireless network adapter (Intel Wireless Pro 3945ABG) was not functioning properly. I used the ThinkVantage Access Connections utility to initiate the wireless network connection, as indicated by the ThinkPad documentation, and while the wireless adapter and Access Connections application recognized my home wireless network, the laptop would not properly acquire an IP address via DHCP. Oddly, if I connected an Ethernet cord to my built-in Ethernet adapter first and then initiated a wireless connection (using a Wireless LAN–only location profile in Access Connections), the laptop would successfully connect with my home wireless LAN.

Solution: After hours of fiddling, I finally called the Lenovo ThinkPad support number. The technical support representative I spoke to was cordial and knowledgeable, and after a few failed attempts at rectifying the problem, he instructed me to follow the following procedure. I have no concrete idea why this sequence of tasks proved successful; I simply offer it here for others to try with my endorsement.

Before anything else, I needed to go to the Support & Downloads page for the ThinkPad T60 and T60p. To do so, go to the IBM support site at, and search on the keyword "migr-62928". Click on the first search result, which should be this page. I was then told to perform the following steps in the given order.

  1. Download and install the Hotkey Utility.
  2. Download and install the Power Manager.
  3. Download and install the ACPI Power Management utility.
  4. Uninstall the Intel PRO/Wireless 3945ABG Network Connection driver. (This can be done by opening the Device Manager, looking under the Network adapters item, right-clicking the aforementioned driver listing, and then selecting Uninstall. The easiest way to open the Device Manager is to right-click on My Computer on the desktop or within Windows Explorer, select Manage, and then navigating to Computer Management > System Tools > Device Manager.)
  5. Download and install the Intel PRO/Wireless LAN 3945bg and 3945abg Mini PCI adapter driver.
  6. Uninstall the Access Connections application by going to Control Panels > Add/Remove Programs. (I went ahead and deleted all existing location profiles to be safe.)
  7. Download and install the Access Connections utility.
  8. Restart the system.

One admonition: Try not to run any applications while performing this procedure. While I was re-installing the Intel PRO/Wireless driver, I tried launching the Access Connections program to check what version I had currently installed, and the program launched but immediately froze. I think I may have interrupted the wireless adapter driver installation because when I first completed the above procedure, the wireless adapter was unable to see WPA-encrypted networks. I repeated steps 4–8, and then the wireless adapter worked fine.

Addendum: Well, after all that, my wireless connection was no less temperamental than before, although the new connectivity failure may have been separate and unrelated to the original one. After connecting to my home wireless LAN initially, if I later disconnected from the network and tried to re-connect, the ThinkPad adapter would authenticate with the network but then fail to acquire an IP address. However, this time I noticed that if I tried to connect to insecure wireless networks available in my building, I could do so successfully. Thus, I believed there was some sort of authentication error between the ThinkPad wireless adapter and my wireless router even though the system tray notifications and Access Connections messages to the user were indicating that wireless authentication was succeeding. I tried changing the wireless encryption scheme on my router (D-Link DI-624) from WPA to WPA2-Auto. (WPA2-Auto tries to authenticate wireless clients using WPA2 first and then falls back to using WPA. I chose this setting because I have another wireless client in my home that supports WPA security but not WPA2.) I then changed the wireless settings on my ThinkPad, by way of the Access Connections program, so that it used WPA2-PSK for authentication. When I did so, the wireless connection from my ThinkPad to my home network started working perfectly.