Skip to content

Instantly share code, notes, and snippets.

@WesleyBlancoYuan
Created September 6, 2016 07:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WesleyBlancoYuan/1f3236bf006f97161a2df31bd1e97190 to your computer and use it in GitHub Desktop.
Save WesleyBlancoYuan/1f3236bf006f97161a2df31bd1e97190 to your computer and use it in GitHub Desktop.
Hyper-V .vhdx 格式磁盘镜像转换为VirtualBox可用的.vhd格式
Hyper-V 默认创建 **.vhdx** 格式的虚拟磁盘。
根据SuperUser上的这个问题:
http://superuser.com/questions/723381/how-to-open-vhdx-files-in-virtualbox
尽管第三个答案指出,
> VirtualBox since 4.2 changelog says support added for VHDX "Storage: added readonly support for VHDX images".
但这种格式在VirtualBox中是不支持的,要使用它建立新的镜像,会出现错误。具体信息为:
Could not open the medium 'D:\desarrollo\Hyper-V\Ubuntu2\Virtual Hard Disks\Ubuntu2.vhdx'.
VD: error VERR_NOT_SUPPORTED opening image file 'D:\desarrollo\Hyper-V\Ubuntu2\Virtual Hard Disks\Ubuntu2.vhdx' (VERR_NOT_SUPPORTED).
Código Resultado:
E_FAIL (0x80004005)
Componente:
MediumWrap
Interfaz:
IMedium {4afe423b-43e0-e9d0-82e8-ceb307940dda}
Receptor:
IVirtualBox {0169423f-46b4-cde9-91af-1e9d5b6cd945}
Receptor RC:
VBOX_E_OBJECT_NOT_FOUND (0x80BB0001)
根据搜索之后的信息,可以在启用Hyper-V后,使用PowerShell把.vmhk镜像转换为Virtualbox支持的VHD镜像。详情见以下答案:
http://superuser.com/questions/751954/how-to-convert-a-vhdx-file-to-vhd#answer-751957
具体操作步骤为:
- Windows + R打开“运行”对话框,键入cmd,在command窗口中键入PowerShell来使用PowerShell窗口。或者直接打开PowerShell。
- 在PS提示符后,使用以下命令:
Convert-VHD –Path YOUR VHDX PATH –DestinationPath YOUR DESTINATION PATH
例如:
Convert-VHD -Path c:\myDisk\Ubuntu.vhdx -DestinationPath d:\Ubuntu_vhd.vhd
注意两个路径都要带后缀。
- 等待处理完成,用VirtualBox加载生成的镜像,完成。
@QGB
Copy link

QGB commented Jul 17, 2021

PS C:\Users\Administrator> Convert-VHD -Path "C:\Users\Public\Documents\Hyper-V\Virtual hard disks\Ubuntu 18.04.1 LTS.vh
dx" E:\VirtualBox_VMs\Ubuntu_1804.vhd
Convert-VHD : 无法将“Convert-VHD”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,
请确保路径正确,然后再试一次。
所在位置 行:1 字符: 1
+ Convert-VHD -Path "C:\Users\Public\Documents\Hyper-V\Virtual hard dis ...
+ ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Convert-VHD:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Users\Administrator>

@ThinkZ
Copy link

ThinkZ commented Oct 15, 2022

You have to import the ServerManager module

Import-Module ServerManager

Of course you have to install it, you can find it as a feature named Hyper-V Module for Windows PowerShell

@WesleyBlancoYuan
Copy link
Author

PS C:\Users\Administrator> Convert-VHD -Path "C:\Users\Public\Documents\Hyper-V\Virtual hard disks\Ubuntu 18.04.1 LTS.vh
dx" E:\VirtualBox_VMs\Ubuntu_1804.vhd
Convert-VHD : 无法将“Convert-VHD”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径,
请确保路径正确,然后再试一次。
所在位置 行:1 字符: 1
+ Convert-VHD -Path "C:\Users\Public\Documents\Hyper-V\Virtual hard dis ...
+ ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Convert-VHD:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Users\Administrator>

Just as @ThinkZ said, please check here: https://stackoverflow.com/questions/31934795/where-can-i-find-convert-vhd-powershell-command. You have to install the module first to use the command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment