有没有办法在没有临时存储驱动器的情况下在 Azure 中创建虚拟机?

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

我使用这个命令来启动虚拟机:

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

每次它创建一个标有 "Temporary Storage" 的驱动器 D 时,有什么办法可以摆脱这个驱动器吗?

P.S我知道它的作用,我不需要它。

不幸的是,所有的Azure虚拟机至少有两个磁盘,一个是操作系统磁盘,另一个是临时磁盘。临时磁盘随 VM 大小一起提供。您可以看到 vm sizes,使用临时存储回显一个。

所以没有临时磁盘就无法创建虚拟机。您需要考虑的是如何根据驱动器编号的需要更改您的应用程序。例如,将需要的磁盘更改为驱动器号 E。

我想到了这个解决方案:

$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'

正如@Charles Xu 所说,你不能删除它,但你可以忽略它并使其离线。 我费了好大劲才弄明白,但它可能会比其他人节省一些时间。

如果您只需要 powershell,就是这样:

$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

日期 18-02-2021 没有本地临时磁盘的 Azure VM 大小,现在有可能 https://docs.microsoft.com/en-us/azure/virtual-machines/azure-vms-no-temp-disk