Decrease a Disk Size on Azure VM

Paulo Nunes
5 min readJun 25, 2020

--

Or, How to draw a smile to yourself.

Sometimes we see our environment and think of ways to reduce the costs.

We firstly can analyze and apply these alternatives. It is easy and we can do in a few minutes:

1 — Change the disk: Ultra Disk Storage ($$$$), Premium SSD ($$$), Standard SSD ($$), and Standard HDD ($);

2 — Downsize the Virtual Machine;

3 — Reduce the number of instances (if you have over one).

Exist an alternative more. The fourth alternative is downsizing a disk. The process should be as easy as to upsize a disk, but unfortunately is not so. The Azure only supports increasing the size of the disks using the portal. However, no worry about this obstacle, we will overcome it together and I will show below how to scale down a managed data disk for an Azure VM.

For this, I will use an old excellent IT technical tool: Robocopy.

What is Robocopy?

“Robust File Copy” is a command-line directory and/or file replication command for Microsoft Operation System. It looks like Xcopy, more powerfully. I can tell you it is one of the most-used utilities to copy large volumes between directories/disks.

Take a step back and pay attention:

1 — In ALL CASES of “migration”, always keep updated backups in mind;

2 — If you are using SQL instances on VM, and handling the disk manually, the connection will be broke and you will need to be managed it inside the virtual machine (and not through the SQL instance);

3 — Stop all services that will use these disks. We need to ensure that it will copy every metadata to the small disk. When we talk about database disk, attention is the most important, otherwise, the process could lose/inviability your database;

4 — Only delete the old disk(s) after doing a complete test in the new disk. Try the applications that will use the resized disk, check the consistency, size, number of items, and directory structure of the new disk with the new disk.

Well, go ahead and I will show you how it works.

1 — Check what are the applications that use the unit.

Check what these services could create or use the disk during the migration.

Example of application services.
Example of database services.

Note or print the actual configuration, stop these services and, for security, change the Startup Type for Manual. The last item is not mandatory, it is only an extra security step. You may need to reboot the server or start de applications or database in a specific order, in this way you can do the start manually.

2 — Create a new data disk

First, create a new data disk from the Azure portal. Remember to choose the best disk size.

Select ‘Create disk‘ and follow the wizard to create a managed disk.

The new disk. Here, I migrate the data from a storage space volume of 3TB (2 disks — 1TB + 2TB) to a unique disk (512GB).

3 — Configuration inside the Virtual Machine

RDP to the VM and mount the new disk. For this, go to Disk Management and assign a size and temporary drive letter for the new volume.

In this example, we will copy the data of 3TB Disk to 512GB Disk.

A curious fact about the cost (June 2020):

— A 3TB managed disk in South Brazil is U$ 294,91/month;

— 512GB managed disk costs U$ 52,22/month (-82%).

The Old Disk (F: — 3TB) and the new disk (E: — 512GB).

3 — Using the Robocopy

Once the new disk mounts, we need to move the files from the source disk to the new volume. We can do it using this command on PowerShell or Prompt:

Robocopy F:\ E:\ *.* /j /e /sec /Xd “System Volume Information” “$RECYCLE.BIN” /Xo

Explain the command:

  • Robocopy: replication command;
  • F:\: old disk (source);
  • E:\: new disk (destination);
  • *.*: copy every file using every extension;
  • /j: copy using unbuffered I/O;
  • /e: include all empty sub-folders;
  • /sec: to copy the data/attributes/timestamps/DACLs;
  • /Xd: exclude directories matching the names on the right;
  • “System Volume Information”: do not robocopy the system information of the old disk, the new disk needs to build its own partition/volume information;
  • “$RECYCLE.BIN”: ignore recycle bin;
  • /Xo: this option will not overwrite existing data unless the source copy is newer than the one possibly existing at the destination.
  • /e: include all empty sub-folders;
Start the robocopy command.
The result of robocopy.

In the Manage Disk, remove the letter of the old volume and change the new volume with the correct letter. In the Azure Portal, detach the old volume:

512GB Disk (F:/).
Detach the old volume.

4 — Test everything that you need.

Start again the services and test the applications completely.

When the files have migrated to the new volume, and you have confirmed that all works well, you can delete the source disk from the Azure Portal. Remember: we can delete the old volume after detached it.

Delete the old volume/disk on Azure to reduce the cost and be happy!

Your surprised face.

Reference

  • Grammatikos, George Chrysovaladis. TechNet, Azure VM: Decrease The Disk Size, 30 Jan. 2019, social.technet.microsoft.com/wiki/contents/articles/52487.azure-vm-decrease-the-disk-size.aspx.

--

--

Paulo Nunes

I am enthusiastic by Cloud and in-house computers, with a passion for BI and ML. • Azure Solutions Architect Expert, Microsoft Solution & BI Specialist.