gpt4 book ai didi

powershell - 通过 powershell 挂载 VHD 引发 ResourceBusy 错误

转载 作者:行者123 更新时间:2023-12-03 07:48:30 26 4
gpt4 key购买 nike

我正在尝试在虚拟机中使用 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

为什么说它正在使用?我应该怎么做才能安装它?

编辑:

如果我尝试通过上下文菜单安装它,则会引发此错误:

enter image description here

最佳答案

我通常对 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 未安装在您的脚本中是因为磁盘未初始化和格式化

希望这有帮助

关于powershell - 通过 powershell 挂载 VHD 引发 ResourceBusy 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40328871/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com