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

时间:2019-04-17 13:13:31

标签: azure powershell azure-cli azure-cli2

我使用此命令启动虚拟机:

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

每次创建一个标有“临时存储”的驱动器D时,有什么方法可以摆脱此驱动器?

P.S我知道它的剂量,我不需要它。

3 个答案:

答案 0 :(得分:1)

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

因此,如果没有临时磁盘,则无法创建VM。您需要考虑的是如何根据驱动器号更改应用程序。例如,将磁盘需求更改为驱动器号E。

答案 1 :(得分:0)

我想出了以下解决方案:

$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

答案 2 :(得分:0)

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

相关问题