Tutorial: Exand an NTFS partition on virtual disk

I recently needed to expand the NTFS partion that I am using in a Virtual PC virtual machine. When I searched the web, I found several half solutions, but no one spelled everything out in detail. The steps below should help you get the job done. Most of these steps will work for any other virtual machine implementation, with the exception of the VhdResize tool that is used. You will need to find another utility that lets you expand the size of a virtual disk.

Preparation work:

  1. Make a copy of the file that contains the virtual disk. (I guess you could skip this step, but if something goes wrong, don’t complain about it. :))
  2. Download the GParted Live CD.
  3. Download VhdResize.

Resize the hard drive:

  1. Shutdown the vitual machine if it is running.
  2. Run VhdResize, and when prompted, open the virual hard disk that you want to resize.
  3. Select a file to save the resized file to. This cannot be the same as the file that you are resizing.
  4. Set the new disk size
  5. Eat a sandwhich and come back when it is done.
  6. Change the virtual machine settings to use the resized virtual disk instead of the original virtual disk.
  7. Boot the virtual machine and make sure that you are able to read and write to the resized disk. Notice that the partition is still the same size. That is because we have not made it any bigger yet. That is the next step.

Resize the partion:
Note: This part of the tutorial assumes that you have only 1 partition on your disk, if you have more than one, then you had better know what you are doing.

  1. Capture the GParted live CD
  2. Reboot the virtual machine
  3. From the boot menu, select the framebuffer option. This will cause X to fail, but since these instructions use the command line, the framebuffer option will give us more text-based screen real estate.
  4. When prompted, select a keyboard layout and a language.
  5. After X fails to launch, you should be prompted with a bash prompt. If X actually started, the Ctrl-Alt-Backspace will kill it.
  6. Execute fdisk /dev/hda. You may have to change the device if you are not changing the size of the primary partition.
  7. Enter d to delete the partion.
  8. When prompted for the partition choose enter 1.
  9. Enter n to create a new partition.
  10. Enter p to create a new primary partition.
  11. Hit the enter key to select the start of the disk as the default partition starting point.
  12. Hit the enter key to select the end of the disk as the default end point.
  13. Enter t to change the partition type.
  14. Enter 1 to select the first partion.
  15. Enter 7 to set the partion type to NTFS.
  16. Enter a to change the partion’s bootable flag.
  17. Enter 1 to select the first partition.
  18. Enter w to write the partion table out to the drive. This is the step that writes the changes out to the disk. You can still back out now.
  19. Enter q to exit fdisk. This will return you to the bash prompt.
  20. Execute ntfsresize -s 20480M -n /dev/hda1. You will need to change the size to the desired amount. This command does not actually do the resize, it just does a test run without making any changes. Once this step passes without any errors, then go on to the next one.
  21. Execute ntfsresize -s 20480M /dev/hda1.
  22. Eject the GParted live cd.
  23. Execute reboot.
  24. When the virtual machine boots, it will run chkdsk to check for errors. Once this is done, make sure that everything still works.

Now you should have succesfully resized your NTFS partion. Congrats!


One Response to “Tutorial: Exand an NTFS partition on virtual disk”

  1. Bob McCoy says:

    Wow. Thanks for the instructions. They were exactly what I needed. And though I was working with multiple partitions, the instructions were complete enough to allow me to figure out what was going on. Great job. Thanks again.

Leave a Reply