Site's logo

KL, MY

7:30:00 AM

Welding by Alex Rosamello on Pexels

How to Expand a docker VHDX Disk in Windows Without Data Loss

Need to expand a fixed-size VHDX in Windows? This guide shows how to mount, resize, and safely reclaim space inside ext4 disks (WSL2-compatible).

May 14, 2025

5 min read

A fixed-size VHDX disk can be expanded in Windows without data loss. Expanding a fixed-size VHDX disk in Windows can be frustrating because it requires resizing the internal partition, which isn’t immediately obvious. This guide will show you how to do this step by step.

Resizing the VHDX Disk

Before proceeding, ensure you back up your VHDX disk in case something goes wrong. You should already have Hyper-V installed and enabled on your Windows machine.

  1. Stop and exit Docker Desktop. This is important to ensure that no processes are using the VHDX disk while you are trying to resize it.

  2. Open Hyper-V Manager:

    • Press Windows + S, type “Hyper-V Manager”, and open the application.
    Hyper-V Manager interface
    Hyper-V Manager interface
  3. Edit the Virtual Hard Disk:

    • In the Hyper-V Manager, locate and click Edit Disk… in the right sidebar.
    • Click Next to proceed.
    Setup wizard starting page for editing a hard disk
    Setup wizard starting page for editing a hard disk
  4. Locate the VHDX Disk:

    • Click on Browse… and select the VHDX disk you want to expand. Docker Desktop stores all its data in the docker_data.vhdx file.
    • Click Next to proceed.
    Locating the VHDX disk in the setup wizard
    Locating the VHDX disk in the setup wizard
  5. Expand the Disk:

    • The Expand option should be selected by default. Click Next to proceed.
    Action to expand the VHDX disk in the setup wizard
    Action to expand the VHDX disk in the setup wizard
  6. Specify the Size:

    • Enter the new size for the VHDX disk. Enter a size larger than the current size. In this example, we are expanding the disk to 100 GB from 75 GB.
    • Click Next to proceed.
    Specifying the new size for the VHDX disk
    Specifying the new size for the VHDX disk
  7. Summary:

    • Review the summary of the changes you are about to make. If everything looks good, click Finish to apply the changes.
    Summary of the VHDX disk expansion
    Summary of the VHDX disk expansion

    The VHDX disk will now be expanded to the new size. This should not take long.

Resizing the Internal Partition

Now that the VHDX disk has been expanded, we need to resize the internal partition to utilize the newly allocated space. If you were to start Docker Desktop now, you would see that the disk size remains unchanged. This is because the internal partition has not been resized yet.

Docker Desktop disk usage before resizing the internal partition; limit 73.52 GB
Docker Desktop disk usage before resizing the internal partition; limit 73.52 GB
  1. Enter the WSL2 environment:

    • Open Windows Terminal or Command Prompt.

    • Type wsl and press Enter to enter the WSL2 environment.

    • Check the existing devices in your WSL2 distribution by running the following command:

      Terminal window
      ls /dev/sd* -la
  2. Next, we need to mount this expanded VHDX within WSL2 using PowerShell.

    • Press Windows + S, type “PowerShell”, right-click on it, and select Run as administrator.
  3. Mount the VHDX Disk to WSL2:

    • Run the following command to mount the VHDX disk to WSL2:

      Terminal window
      wsl --mount --vhd <path-to-vhdx-file> --bare
    • Replace <path-to-vhdx-file> with the actual path to your docker_data.vhdx file. For example:

      Terminal window
      wsl --mount --vhd "D:\docker\DockerDesktopWSL\disk\docker_data.vhdx" --bare
  4. Resize the Internal Partition:

    Now, returning to the WSL2 environment, we need to resize the internal partition to utilize the newly allocated space.

    • Identify the newly mounted disk in WSL2 by running the following command:

      Terminal window
      ls /dev/sd* -la

      Carefully compare this output with the output from the previous ls /dev/sd* -la command to identify the newly mounted disk (e.g., /dev/sdb or /dev/sdc).

    • To resize the partition on the newly mounted disk (in this example, we’ll assume it’s /dev/sdf), run the following command:

      Terminal window
      sudo resize2fs /dev/sdf
  5. Unmount the VHDX Disk:

    • After the resizing process is complete, unmount the VHDX disk by executing the following command in PowerShell:

      Terminal window
      wsl --unmount <path-to-vhdx-file>
    • Replace <path-to-vhdx-file> with the actual path to your docker_data.vhdx file.

  6. Start Docker Desktop:

    • Open Docker Desktop again. You should now see that the disk has been expanded to the new size.
    Docker Desktop disk usage after resizing the internal partition; limit 98.12 GB
    Docker Desktop disk usage after resizing the internal partition; limit 98.12 GB

Congratulations! You have successfully expanded a fixed-size VHDX disk in Windows without losing any data. This process involves two key steps: first, resizing the VHDX disk using Hyper-V, and second, resizing the internal partition within WSL2 to utilize the newly available space.