Linux / Windows · July 20, 2025

How to Safely Shrink a Data Disk Size Without Data Loss on Azure VPS / Cloud Servers

**Key Takeaways**
* **Safe Disk Reduction:** Azure does not support directly shrinking data disks. This is achieved by creating a new smaller disk and copying data.
* **Applicability:** This guide applies to managing data disks on Azure Virtual Machines (VMs) hosted on Hong Kong VPS or Hong Kong Cloud Servers.
* **Data Safety:** Always verify data integrity and back up critical data before deleting the old disk.
* **Technical Requirements:** Familiarity with the Azure portal, RDP connections, and Windows Disk Management tools is necessary.

**Overview**

When managing Azure Virtual Machines, optimizing disk usage can significantly reduce costs, especially for VMs running on Hong Kong VPS or Hong Kong Cloud Servers. Since Azure does not support directly shrinking data disks, you must create a new smaller disk, copy data from the old disk to the new one, and then delete the old disk. The following steps outline how to safely complete this process.

**Applicability**

This guide applies to data disks on Windows Virtual Machines. It does not cover shrinking the Operating System (OS) disk. The steps are based on Azure official documentation and are applicable to Azure deployments in the Hong Kong region.

**Important Considerations**
* Back up data before proceeding to prevent accidental loss.
* Ensure the new disk capacity is sufficient to hold all data from the old disk.
* Verify the integrity of the data transfer.

**Detailed Step-by-Step Guide**

This guide details how to safely shrink an Azure data disk size without data loss, specifically tailored for Azure VMs deployed in the Hong Kong region.

> **Note:** This document does not cover shrinking the OS disk. It serves as a general guide for data disk reduction. Adjust steps according to your specific environment.

**1. Create a New Data Disk**

First, create a new, smaller capacity data disk in the Azure portal.

1. Log in to the [Azure portal](https://portal.azure.com/).
2. Search for and select **Virtual machines**.
3. From the list of VMs, select the VM to which you want to attach the new data disk.
4. In the VM’s navigation pane, under **Settings**, select **Disks**.
5. In the **Data disks** section, click **Create and attach a new disk**.
6. In the configuration row for the new disk, fill in or select the following fields:
* **LUN:** Logical Unit Number. Ensure it doesn’t conflict with existing disks.
* **Disk name:** Assign a unique name for easy identification.
* **Storage type:** Select based on performance needs (e.g., Standard HDD, Standard SSD, Premium SSD).
* **Size (GiB):** Enter the smaller target capacity. **Crucially, ensure this is larger than the *used* space on the old disk.**
* **Max IOPS:** Select based on performance requirements (if applicable).
* **Max throughput (MB/s):** Select based on performance requirements (if applicable).
* **Encryption:** Select encryption type if security requirements dictate.
* **Host caching:** Select caching mode based on read/write needs (e.g., **ReadOnly**, **ReadWrite**).
7. Click **Save**. The new disk will be created and automatically attached to the VM.

> **Tip:** Before selecting the new disk size, check the **used space** on the old disk (via Azure portal metrics or Disk Management within the VM) to determine an adequate capacity.

| Configuration Field | Description | Example Value |
| :—————— | :——————————— | :———– |
| **LUN** | Logical Unit Number (disk slot ID) | 0 |
| **Disk name** | Unique identifier for management | NewDataDisk |
| **Storage type** | Impacts performance & cost | Premium SSD |
| **Size (GiB)** | Target capacity of the new disk | 64 |
| **Max IOPS** | Input/Output Operations Per Second | 500 |
| **Max throughput (MB/s)** | Data transfer rate | 100 |
| **Encryption** | Data security option | Enabled |
| **Host caching** | Optimizes read/write performance | ReadWrite |

**2. Configure the New Data Disk within the VM**

After attaching the new disk, you must configure it within the VM’s operating system (Windows).

1. Connect to the VM using Remote Desktop Protocol (RDP). (Refer to [Connect to a Windows VM using RDP](https://learn.microsoft.com/en-us/azure/virtual-machines/windows/connect-rdp)).
2. Open **Disk Management**:
* Right-click the **Start** button (or **This PC**).
* Select **Manage**.
* Navigate to **Storage** > **Disk Management**.
3. **Initialize the new data disk**:
* Locate the new disk (listed as “Unknown” and “Not Initialized”).
* Right-click the disk label (e.g., Disk 1, Disk 2) and select **Initialize Disk**.
* Choose a partition style (typically **GPT** for disks >2TB or modern systems) and click **OK**.
4. **Create a Volume and Assign a Drive Letter**:
* Right-click the **Unallocated** space on the new disk.
* Select **New Simple Volume…**.
* Follow the wizard, assigning a drive letter (e.g., `Y:`) and formatting the volume (recommended file system: **NTFS**).
5. **Verify Size:** Ensure the new disk’s formatted capacity is sufficient to hold the data from the old disk.

> **Tip:** Ensure the new disk is correctly formatted (NTFS recommended) and has a drive letter assigned before proceeding to data copy.

**3. Copy Files from the Old Data Disk to the New Data Disk**

This is the critical step. Proceed carefully to avoid data loss. Using the Windows `robocopy` command is recommended for efficiency and reliability.

1. **Stop Applications:** Stop any applications or services actively using files on the old data disk (`X:` in this example) to prevent data corruption during copy.
2. Open a **Command Prompt (Admin)**.
3. Run the `robocopy` command:
“`
robocopy X:\ Y:\ /MIR /Z /W:5 /R:2 /MT
“`
* `X:\`: Drive letter of the **Old Disk**.
* `Y:\`: Drive letter of the **New Disk**.
* `/MIR`: Mirror mode. Copies directory trees, including empty directories, and removes files/dirs on `Y:` that no longer exist on `X:`.
* `/Z`: Copies files in restartable mode (resumes interrupted transfers).
* `/W:5`: Wait time between retries (5 seconds).
* `/R:2`: Number of retries on failed copies (2 times).
* `/MT`: Use multithreading (default is 8 threads) for faster copying.
4. **Verify Data Integrity:** After `robocopy` completes, meticulously verify the data on the new disk (`Y:`). Methods include:
* Running `robocopy` again with the `/L` (List only) and `/X` (Report all extra files) flags to compare source and destination.
* Using file comparison tools (e.g., `fc`, WinMerge).
* Manually spot-checking critical files and directories.
* Checking folder sizes and file counts.

> **Tip:** The copy process duration depends heavily on the data volume. Exercise patience. Double-check verification before detaching the old disk.

**4. Detach and Delete the Old Data Disk**

**Part 1: Detach the Old Disk from the VM**
1. Return to the [Azure portal](https://portal.azure.com/).
2. Search for and select **Virtual machines**.
3. Select the VM name from which you want to remove the old disk.
4. In the VM’s navigation pane, under **Settings**, select **Disks**.
5. In the **Data disks** section, locate the **old data disk**.
6. Click the **Detach** icon (typically an “X” symbol) at the end of the disk’s row.
7. Click **Save**. The old data disk will be detached from the VM but still exists in your Azure storage.

**Part 2: Delete the Old Disk (Unmanaged/Managed)**
* **Unmanaged Disks:** Navigate to the associated Storage Account > Blobs and delete the VHD blob.
* **Managed Disks:**
1. Search for **Disks** in the Azure portal.
2. Locate the detached old disk (check its status is **Unattached**).
3. Select the disk and click **Delete**.
4. Confirm deletion.
*(Refer to Azure Docs: [Find and delete unattached Azure managed disks](https://learn.microsoft.com/en-us/azure/virtual-machines/disks-find-unattached-portal))*

> **WARNING:** Only delete the old disk **after** confirming the new disk (`Y:`) contains all necessary data and is functioning correctly. Ensure you have a verified backup before deletion.

**Conclusion**

By following these steps, you can safely reduce the size of an Azure data disk without data loss. Whether managing Azure VMs on Hong Kong VPS or Hong Kong Cloud Servers, this process helps optimize resource utilization and reduce costs. **Always verify data transfer integrity before deleting the old disk and maintain reliable backups to ensure data safety.**