我尝试在VM中使用Powershell创建,装载和格式化VHDX。第一步没有任何问题:
New-VHD -Path $path -Dynamic -SizeBytes 20GB
但是现在,当我尝试装载它时:
Mount-VHD -Path $path
Powershell引发了这个错误:
Mount-VHD : Failed to mount the virtual disk.
The system failed to mount <my_path>.
The operation cannot be performed while the object is in use.
At line:1 char:2
+ Mount-VHD -Path <my_path>
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ResourceBusy: (Microsoft.Hyper...l.VMStorageTask:VMStorageTask) [Mount-VHD], Virtualizat
ionOperationFailedException
+ FullyQualifiedErrorId : ObjectInUse,Microsoft.Vhd.PowerShell.MountVhdCommand
为什么说它正在使用?我该怎么做才能装上它?
修改
如果我尝试通过上下文菜单安装它,则会引发此错误:
答案 0 :(得分:1)
我通常对diskpart执行相同操作(以管理员身份运行以下powershell脚本):
$diskpartScript= @"
create vdisk file=c:\test.vhd maximum=2000 type=expandable
select vdisk file=c:\test.vhd
attach vdisk
create partition primary
format fs=ntfs label="Test VHD" quick
assign letter=v
"@
$diskpartScript | diskpart
请注意: 我相信vhd没有安装在你的脚本中是因为磁盘没有初始化和格式化
希望这会有所帮助