Ehsan Zargar Ershadi
Ehsan Zargar Ershadi

Reputation: 24833

Is there any way do create a vm in azure without temporary storage drive?

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.

Upvotes: 1

Views: 6718

Answers (3)

Sameed Shaikh
Sameed Shaikh

Reputation: 21

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

Upvotes: 2

Ehsan Zargar Ershadi
Ehsan Zargar Ershadi

Reputation: 24833

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

Upvotes: 1

Charles Xu
Charles Xu

Reputation: 31384

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.

Upvotes: 1

Related Questions