Tutorials

Reduce the Size of a Windows Boot Volume Using Gparted

Table of Contents

Introduction

This guide will demonstrate the process of reducing the size of the boot volume for a virtual machine running a Microsoft Windows operating system. You may find that after you have created or migrated a virtual machine you no longer need a significant amount of space that was provisioned for the boot volume. To remedy this situation, we will utilize the combination of tools built into Windows along with the free GNOME partition editor.

Requirements

  • A virtual machine running the Microsoft Windows operating system.
  • Familiarity with working inside the ProfitBricks DCD (Data Center Designer).
  • Access to the Microsoft Windows installation CD or ISO for your version of Microsoft Windows.
  • GParted is leveraged to perform some of the actions in this process.

Please Note: As with any operation where data is being manipulated, changed, moved, or touched, it is very important to BACKUP ALL YOUR DRIVES AND DATA before attempting anything in this guide.

Preliminary Steps

Confirm that your boot drive is using a "Bus Type" of VirtIO, not IDE. This information is displayed on the Storage tab to the right in the DCD when you have the server selected.

Then connect to the virtual machine with the DCD Remote Console.

Use the Windows "defrag.exe" tool to analyze and defragment the drive you are looking to shrink and move to a smaller ProfitBricks storage drive. There are third-party defragementation tools that could be used as well. The goal is to get all the files moved to the "beginning" of the drive so that we can shrink the partition by removing empty space at the "end" of the disk.

Shrink the Disk

Within Computer Management, go to the C: drive.

Right-click and select Shrink Volume.

Shrink Volume

A dialog box similar to this should open:

Shrink C

Change the value for "Enter the amount of space to shrink in MB". This number is how much will be removed from the original disk size during the shrink operation.

Example: 102 GB, shrink 42047 MB will give us about 60 GB remaining for the entire disk.

Shrink C adjusted

Please Note: Make sure you leave some space for growth. Alternatively, you could choose to add an additional storage volume later if the required space increases and it doesn't need to be part of the boot volume.

Continue by hitting the Shrink button.

Once complete, you should see the new size of the drive in the Disk Management window.

Disk Management Disk 0 Local Disk C

Shut down the virtual machine from inside the operating system.

Copy Partitions

Within the ProfitBricks DCD, add a new HDD Storage, attach it to the virtual machine, and adjust the size to match the "Total size after shrink in MB" previously used.

Example: 60 GB

On the Storage tab of your server, Add CD-ROM, from the Image drop-down menu, choose ProfitBricks Image and then gparted-linux-0.26.1-1-amd64.iso (the name may be slightly different as new revisions are made available). Make sure Boot from Device is checked.

Provision the changes.

When your server boots, you should be presented with Linux screen on the DCD remote console.

Enter your keyboard options and language type.

Example: "33" for US English

Hit 0 or Enter to continue into GParted.

Inside the Gparted interface you should see your main drive (/dev/vda – 102 GB, ~60 GB used, ~43 GB unallocated):

Dev vda2 Unallocated

In the upper right corner, select the drop-down menu showing drive /dev/vda.

You should see the new drive (/dev/vdb) you recently created/attached. Select it and go to Device > Create partition Table

Create Partition Table

You will be prompted with a warning:

Warning Erase All Data

Select the partition type. If you’re going to be using a Windows format, select msdos type.

You should now see the unallocated drive without a warning:

Unallocated Without Warning

Go back to your first drive, click the first partition "/dev/vda1 (ntfs / System Reserved)", right-click and select Copy.

Go back to the second drive, right-click on the unallocated drive and select Paste.

Repeat this procedure for the second partition. Copying it from /dev/vda2 to /dev/vdb2.

Note:  If you did not allocate the exact amount of space for the partitions, you may want to extend the partition to consume the rest of the unallocated space.

Click on Apply.

GParted will begin the copy process for both of the partitions:

GParted Copy Process

Once completed successfully, press Close.

GParted will rescan the drives for updated information.

Once refreshed, you should see the second disk should look similar to the first disk, only without as much unallocated space.

One option which will not carry over during the copy process is the boot flag on the "System Reserved" partition.

Right-click on the second disk's "System Reserved" partition.

Select Manage flags.

Check the box for the boot flag and press Close.

Manage Flags

It will apply the change and rescan the partitions.

Both drives should look similar now:

vda (original)

vda Original

vdb (new)

vdb New

From the GParted interface, go ahead and Quit. You will be prompted to Reboot/Shutdown/Logout.

Go ahead and select Shutdown.

Wrapping Up

Switch over to the ProfitBricks DCD.

Disconnect the old, larger drive from the virtual machine.

Select the virtual machine and remove GParted from the CD-ROM.

Make the new, smaller storage volume ("New Storage") the boot device.

New Storage Boot Device

Now is a good time to select the new storage volume and update the "OS type" to Windows and give it a new name.

Update Storage Type and Name

Provision the changes and confirm the reboot if necessary, your machine should remain in the Shut off status.

Add a CD-ROM back to the storage of the VM and assign the ProfitBricks or your own image of the OS which is running.

Example: windows-2012-r2-server-setup.iso

Open a remote console for the virtual machine prior to powering it on.

Provision the changes and start up the virtual machine.

If you see the message in the remote console to "Press any key to boot to the CD/DVD ROM", press a key to do so.

If you receive an error such as "no operating system found", or that "you must repair the system with the Windows system disc", that is what we must do.

You may need to wait a few moments for the system to restart again and should hopefully see the "Boot from CD/DVD" option.

Select to start in Safe Mode with Command Prompt.

Once the Command Prompt is open, type "bootrec /fixmbr" (Master Boot Record).

Fixmbr

After this is complete, type "bootrec /rebuildbcd" (Boot Configuration Data).

Rebuildbcd

You should see your Windows installation listed in the scan results.

Select Yes(Y) or All(A):Type Exit, then press Continue or restart to restart the system or turn off your PC.

If you reboot with the installation disc still in the CD-ROM, you may see the “boot to CD/DVD” message, it is okay to ignore the prompt and continue to boot into the OS.

You should be able to log into your machine and see that under Computer Management you have a fully healthy disk with the adjusted/smaller size.

Computer Management Healthy Disk

Summary

We have successfully reduced the size of the boot volume using a combination of Windows system tools and Gparted. You may find additional helpful information at one or more of the following links:

If you have questions or comments, you are welcome to post them here or open a thread in the Community section of this site.