Azure VHD image size reduction

Kamaraj P (kamp) 41 Reputation points
2022-09-21T15:47:36.44+00:00

Hi Team,

when we build a VHD image, the size of image is expanded more than actual disk size.
Due to this we cannot publish our image into Azure portal.

Is there way to reduce the image size during the build itself ?
Please share if there is any official guidelines.

Thanks,
Kamaraj

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,035 questions
Azure Disk Storage
Azure Disk Storage
A high-performance, durable block storage designed to be used with Azure Virtual Machines and Azure VMware Solution.
668 questions
0 comments No comments
{count} votes

Accepted answer
  1. Luke Murray 11,436 Reputation points MVP Volunteer Moderator
    2022-09-22T20:18:51.563+00:00

    Take a look at: https://learn.microsoft.com/en-us/powershell/module/hyper-v/optimize-vhd?view=windowsserver2022-ps

    Also, take a look at the FSShrinkDisk script: https://github.com/FSLogix/Invoke-FslShrinkDisk (make sure you run this on a backup first). Used to shrink FSLogix VHDs, that are Dynamically expanding. I haven't tested this personally but could be an option.

    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Martin Dimovski 1,636 Reputation points MVP
    2022-09-21T17:31:44.007+00:00

    Hi,

    Thank you for posting the question to the Q&A forum.

    As official guidelines can be found on this link on how to prepare the VHD: https://learn.microsoft.com/en-us/azure/virtual-machines/windows/prepare-for-upload-vhd-image

    I hope the above information can help you.

    If the ANSWER is helpful, please click "Accept Answer" and upvote it. Thanks

    0 comments No comments

  2. Kamaraj P (kamp) 41 Reputation points
    2022-09-22T04:11:49.75+00:00

    Hi,

    Thanks for the answer. But the limation comes around 2TB for single VM image.
    Our image crossed that limit. Is there any guidelines to shrink further on VHD image before pushing to Azure portal ?

    Thanks,
    Kamaraj

    0 comments No comments

  3. Kamaraj P (kamp) 41 Reputation points
    2022-09-22T04:27:43.227+00:00

    BTW we are checking with below link:
    https://learn.microsoft.com/en-us/azure/virtual-machines/linux/create-upload-generic

    This uses qemu-img resize MyLinuxVM.raw $rounded_size ==> Can we use the increase the rounded size to shrink the % of size image ?
    Will the azure not have any issue when booting the images ? Please suggest.

    Thanks,
    Kamaraj

    0 comments No comments

  4. Kamaraj P (kamp) 41 Reputation points
    2022-09-23T04:01:00.527+00:00

    Sure. will check thanks

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.