Friday, January 3, 2014

Online resize vhdx file in Windows Server 2012 R2 with Hyper-V role

Windows Server 2012 R2 Hyper-V started to support online resize the virtual hard disk which is vhdx format. 

To online resize the virtual hard disk, make sure you meet the following requirement.
  • The operating system is running Windows Server 2012 R2 with Hyper-V role
  • A user account is a member of local Hyper-V administrators group or local administrators group
  • The vhdx file must be attached the SCSI controller
Goal
  • Testing online expand and shrink vhdx files with fixed and dynamic disks type
  • Testing online expand and shrink avhdx files
Prerequisites
  • 1 server is installed Windows Server 2012 R2 with Hyper-V role
  • 1 VM is installed Windows Server 2012 R2 is named Server01.
  • 1 VM is installed Windows Server 2008 R2 is named Server02.
  • Server01 is a generation 2 virtual machine attached 1 vhdx file in dynamic disk type in SCSI controller.
  • Server02 is a generation 1 virtual machine attached 1 vhdx file in fixed disk type in SCSI controller.
  • Make sure both virtual machines are running

Steps
Expand the disk size by GUI of Hyper-V Manager
1. On the server which is installed Hyper-V role, log in as Local Administrator.
2. Launch "Hyper-V Manager".
3. On the "Actions" menu, click "Edit Disk".


4. On "Before You Begin" window, click "Next".


5. On "Locate Disk" window, click "Browse" to locate the virtual hard disk of "Server01".



In my lab environment, the virtual hard disk of "Server01" is located at above path. You may select the right path in your environment.

6. Click "Next".
7. On "Choose Action" window, select "Expand".


8. Click "Next".
9. On "Configure Disk" window, type a new size which is bigger than the current one.


10. Click "Next".
11. On "Summary" window, click "Finish".


12. On "Server01", log in as local administrator.
13. Launch "Server Manager".
14. Click "File and Storage Services".


15. On "Central pane", click "Disks".


Now, there are 5 GB unallocated disk space in the current hard disk.

16. Next to "VOLUMES", right-click "C:", select "Extend Volume".


17. On "Extend Volume" window, next to "New size", type "124".


18. Click "OK".


As a result, the disk size of Server01 has been expanded.

Shrink the disk size by GUI of Hyper-V Manager
1. Still in Server01, launch "Disk Management".
2. Right-click "C:", select "Shrink Volume".


3. Next to "Enter the amount of space to shrink in MB", type "26976".


4. Click "Shrink".


I would like to reduce the total size to almost 100GB.

Remark: You have to shrink the disk size in the VM before Shrinking in Hyper-V Manager.

5. Back to "Hyper-V Manager" of the Hyper-V host.

6. On the "Actions" menu, click "Edit Disk".
7. On "Before You Begin" window, click "Next".


8. On "Locate Disk" window, click "Browse" to locate the virtual hard disk of "Server01".


9. Click "Next".
10. On "Choose Action" window, select "Shrink".


11. Click "Next".

Remark: If the disk isn't shrunk in the VM, there is no "Shrink" option in "Edit Disk".

12. On "Configure Disk window, next to "New size", type "100".


13. Click "Next".
14. On "Summary" window, click "Finish".


15. Back to "Server Manager" of "Server01".
 

As a result. the disk size of Server01 has been shrunk to 100GB.

Expand the disk size by PowerShell

1. On the server which is installed Hyper-V role, log in as Local Administrator.
2. Launch "PowerShell" as Administrator.
3. Perform "Resize-vhd -Path <virtual hard disk path> -SizeBytes 10GB -PassThru" to expand the virtual hard disk size of Server02.


4. On "Server02", log in as local administrator.
5. Launch "Disk Management".


We expanded a virtual hard disk of Server02, then we will extend the volume in this VM.

6. Right-click "E:", select "Extend Volume".


7. On "Welcome to the Extend Volume Wizard", click "Next".
8. On "Select Disks" windows, click "Next".


9. On "Completing the Extend Volume Wizard" window, click "Finish".



As a result. the disk size of Server02 has been expanded to 10GB.

Shrink the disk size by PowerShell
1. Still in "Disk Management" of Server02, right-click "E:", select "Shrink Volume".


2. Next to "Enter the amount of space to shrink in MB", type "2048".


3. Click "Shrink".


4. Back to "PowerShell" of the Hyper-V host.
5. Perform "Resize-VHD -Path <virtual hard disk path> -SizeBytes 8GB -PassThru" to shrink the virtual hard disk.


6. Back to "Disk Management" of "Server02", on the menu, click "Action > Refresh".



As a result, the virtual hard disk has been shrunk.

Expand and Shrink a avhdx file
1. Back to Hyper-V Manager, right-click "Server02", select "CheckPoint".


2. On the "Actions" menu, click "Edit Disk".
3. On "Before You Begin" window, click "Next".
4. On "Locate Disk", click "Browse" to select the "AVHDX" file of "Server02".


Remark: This virtual hard disk is attached SCSI controller.

5. Click "Next".
6. On "Choose Action" window, select "Expand".


7. Click "Next".
8. On "Configure Disk window, next to "New size", type "15".


9. Click "Next".
10. On "Summary" window, click "Finish".
11. Go to "Disk Management" of "Server02", on the menu, click "Action > Refresh".


The virtual hard disk of this snapshot has been expanded to 15 GB.

12. Launch "Windows Explorer" and then navigate to the virtual hard disk path of "Server02".


Because the virtual hard disk of this snapshot is based on dynamic expand, the hard disk size of this snapshot hasn't been changed.

13. To shrink the virtual hard disk of this snapshot, go to "Disk Management" of "Server02", right-click "E:", select "Shrink Volume".


14. Next to "Total size after shrink in MB", type "5120".


15. Click "Shrink".


16. Go to "PowerShell", perform "Resize-VHD -Path <avhdx path> -SizeBytes 3GB -PassThru" to shrink the virtual hard disk.


17. Go to "Disk Management" of "Server02", on the menu, click "Action > Refresh".


18. Go to "Hyper-V Manager", right-click the "checkpoint" of "Server02", select "Delete Checkpoint".


19. On "Delete Checkpoint" window, click "Delete".


20. Go to "Windows Explorer" and then navigate to the virtual hard disk path of "Server02".


The shrink virtual hard disk setting has been merged to the Hard disk.

As a result, we can shrink and expand avhdx and vhdx in SCSI controller.

Reference:


This posting is provided “AS IS” with no warranties, and confers no rights!

No comments:

Post a Comment