Azure Temporary Storage Drive Letter Reassignment

On occasion you may have a need to move the Azure temporary drive to a different drive letter. Azure by default is set to use the D drive. This drive letter configuration may conflict with existing scripts or company OS installation standards. I’ve created an ARM template that uses PowerShell DSC to allow you to move the drive letter. It performs the following steps:

1) Disables the Windows Page File and reboots the VM
2) Changes the drive letter from the D drive to a drive letter you specify in the ARM template parameters file
3) Re-enables the Windows page file and reboots the VM

This project is in GitHub here: https://github.com/perktime/MoveAzureTempDrive. To use it, modify the azuredeploy.parameters.json file with your vmName and your desired tempDriveLetter:


{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "value": "<put_your_existing_vm_name_here>"
    },
    "assetLocation": {
      "value": "https://petedscutil.blob.core.windows.net/scripts"
    },
    "tempDriveLetter": {
      "value": "Z"
    }
  }
}

Optionally, you can copy the MoveAzureTempDrive.ps1.zip DSC file to your own Azure storage account and modify the assetLocation parameter as well. Also, if you have an existing DSC extension you will have to remove it before deploying this.

If you are interested in how this works, here is the explanation (note: assuming you understand how PowerShell DSC works):

To disable the Windows page file, we use “gwmi win32_pagefilesetting” which uses WMI to first check if the page file is enabled or not. If it is, we use this script to delete it and restart the VM:

gwmi win32_pagefilesetting
$pf=gwmi win32_pagefilesetting
$pf.Delete()
Restart-Computer –Force

Once the VM restarts, the PowerShell DSC module will then change the drive letter to your desired drive and then re-enable the page file and reboot:

Get-Partition -DriveLetter "D"| Set-Partition -NewDriveLetter $TempDriveLetter
$TempDriveLetter = $TempDriveLetter + ":"
$drive = Get-WmiObject -Class win32_volume -Filter “DriveLetter = '$TempDriveLetter'”
#re-enable page file on new Drive
$drive = Get-WmiObject -Class win32_volume -Filter “DriveLetter = '$TempDriveLetter'”
Set-WMIInstance -Class Win32_PageFileSetting -Arguments @{ Name = "$TempDriveLetter\pagefile.sys"; MaximumSize = 0; }

Restart-Computer -Force

 

Last month I was working for a customer who wanted to migrate some existing virtual machines (VMs) to Azure with data and applications stored on the D: drive. In the same process he wanted to upgrade from W2K8 R2 to W2k12 R2 and keep those same drive letters in place. So all VMs had to be built from scratch on the Azure IaaS platform. But like you all probably know, each new VM on Azure gets a Temporary storage disk (scratch disk) with drive letter D: So I had to come up with a workaround to use the D: as a data/application drive, which can be found below.

If you’re interested, you can find more info about the Temporary Disk via following link: http://blogs.msdn.com/b/mast/archive/2013/12/07/understanding-the-temporary-drive-on-windows-azure-virtual-machines.aspx

Before we start, two things to keep in mind:

  • The Temporary Storage drive (D:) on an Azure IaaS VM hosts the page file, so this has to be relocated before the drive letter can be changed.
  • If you attach an empty disk to an Azure VM always use the maximum size of 1 TB. When you format this disk inside the VM, always choose quick format. This way data only actually written is stored and that is what you’re charged for. This will minimize your costs.

1) Create the VM. If you do not know how follow this link: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-tutorial-classic-portal/

2) Attach an extra data disk to the VM

3) Use RDP to logon to the VM

4) Open Disk Management with choosingRun and typing diskmgmt.msc

5) The following screen will pop up. Select GPT and press OK

6) The Disk Management screen will look like the screenshot below

7) To relocate the Windows Page File (pagefile.sys) open Control Panel – System – Advanced system settings

 

8) Under Performance select Settings… Select the tab Advanced. Under Virtual memory select Change…

 

9) Select the Cdrive and then click System managed size and then click Set. Select the D drive and then click No paging file and then click Set. Click OK

 

10) A System Properties page pops up, where you need to click OK

11) Restart the VM to apply the changes

12) When the VM is rebooted, use RDP to logon to the VM and open Disk Management again

13) Right-Click the CD-ROM (E:) and select Change Drive Letter and Paths to change the drive letter to Z:

14) Right-click on D, the Temporary Storage drive, and select Change Drive Letter and Paths to change the drive letter to E:

15) Create a New Simple Volume… on Disk 2 and assign it to the drive letter D:

 

16) After all adjustments are made, Disk Management should look like this

17) Now you can move the Windows Page File back to the Temporary Storage now assigned with the drive letter E:

18) To apply the changes, reboot the VM

19) After the reboot, login to the VM and validate if everything is working fine and you don’t see a message like shown in the screenshot below.

20) To check if everything is still OK when the VM is de-provisioned, SHUT DOWN the VM from the Azure Classic portal. In this way it comes in the Stopped (Deallocated) state. Afterwards START the VM from the portal. In this case your VM will get re-deployed with its specific configuration and the Temporary Storage will be wiped, and your VM could be brought up on a different Hyper-V host in the Azure Datacenter. If everything is OK, the drive letter change for the Temporary Storage is OK and you can use this VM in production.

That ends this blog post. Till next time!

Wim Matthyssen (@wmatthyssen)

One thought on “Azure Temporary Storage Drive Letter Reassignment

Leave a Reply

Your email address will not be published. Required fields are marked *