1

I used this command to spin up a virtual machine :

az vm create -n $virtualMachine -g $resourceGroup --size Standard_D2_v3 --image win2016datacenter --data-disk-sizes-gb 40
--location $location --admin-username $admin --admin-password $password

Every time it creates a Drive D labeled "Temporary Storage", Is there any way I could get rid of this drive?

P.S I know what it dose and I do not need it.

Ehsan Zargar Ershadi
  • 24,115
  • 17
  • 65
  • 95

3 Answers3

1

Unfortunately, all the Azure virtual machines at least have two disks, one is operating system disk and another is the temporary disk. And the temporary disk comes with the VM size. You can see the vm sizes, echo one with Temp storage.

So you cannot create a VM without the temporary disk. What you need to think is how to change your application with the need of drive number. For example, change the disk need as drive number E.

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • It seems you are right, but my question is how to get rid of it, is there away to remove the drive? – Ehsan Zargar Ershadi Apr 18 '19 at 08:35
  • 1
    @EhsanZargarErshadi No, you cannot remove it. But if need, you can change the drive number after you create the VM. – Charles Xu Apr 18 '19 at 08:36
  • I do agree that it is helpful, but unfortunately it is not the answer to the question and if I accept is as an answer it might misguide others, I have added the way I solved it. Indeed you would get a vote from me. – Ehsan Zargar Ershadi Apr 18 '19 at 08:54
1

I have came up with this solution:

$resourceGroup = "your resource group name"
$virtualMachine = "your virtual machine name"

# remove page file from drive d
az vm run-command invoke -g $resourceGroup -n $virtualMachine --command-id RunPowerShellScript --scripts '$CurrentPageFile = Get-WmiObject -Query "select * from Win32_PageFileSetting"; $CurrentPageFile.delete(); Set-WMIInstance -Class Win32_PageFileSetting -Arguments @{name="c:\pagefile.sys";InitialSize = 0; MaximumSize = 0}; Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\cdrom -Name Start -Value 4 -Type DWord'

# restart server
az vm restart -g $resourceGroup -n $virtualMachine

# set drive d and it's related disk into offline mode
az vm run-command invoke -g $resourceGroup -n $virtualMachine --command-id RunPowerShellScript --scripts 'get-disk -Number (Get-Partition -DriveLetter D).disknumber | Set-Disk -IsOffline $true'

# get azure disks and initialize, format and label it (assign a drive letter as well)
az vm run-command invoke -g $resourceGroup -n $virtualMachine --command-id RunPowerShellScript --scripts 'Get-Disk | Where partitionstyle -eq "raw" | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel "disk2" -Confirm:$false'

As @Charles Xu said you can not delete it but you can ignore it and make it offline. it took me a wile to figure it out , yet it might save some time from others.

If you just need the powershell this is it:

$CurrentPageFile = Get-WmiObject -Query "select * from Win32_PageFileSetting"; 
$CurrentPageFile.delete(); 
Set-WMIInstance -Class Win32_PageFileSetting -Arguments @{name="c:\pagefile.sys";InitialSize = 0; MaximumSize = 0};
Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\cdrom -Name Start -Value 4 -Type DWord
# you need to restart at this stage
get-disk -Number (Get-Partition -DriveLetter D).disknumber | Set-Disk -IsOffline $true
Get-Disk | Where partitionstyle -eq "raw" | Initialize-Disk -PartitionStyle MBR -PassThru | New-Partition -AssignDriveLetter -UseMaximumSize | Format-Volume -FileSystem NTFS -NewFileSystemLabel "disk2" -Confirm:$false
Ehsan Zargar Ershadi
  • 24,115
  • 17
  • 65
  • 95
1

Dated 18-02-2021 Azure VM sizes with no local temporary disk, Now it's possible https://learn.microsoft.com/en-us/azure/virtual-machines/azure-vms-no-temp-disk