![](https://i-blog.csdnimg.cn/blog_migrate/3a9840f5dd52b9ec24284d3199e757ca.png)
VirtualBox allows you to choose either a dynamically allocated or fixed size disk when creating a new virtual hard disk file. Dynamically allocated disks are faster to create and can grow to larger sizes. Fixed size disks may be faster to use, but can’t grow any larger once they fill up. You can convert between the two formats and resize disks, if you like.
在创建新的虚拟硬盘文件时,VirtualBox允许您选择动态分配的磁盘或固定大小的磁盘。 动态分配的磁盘创建速度更快,并且可以增长到更大的大小。 固定大小的磁盘使用起来可能更快,但是一旦填满就无法再增大。 您可以根据需要在两种格式之间转换并调整磁盘大小。
Before continuing, we recommend shutting down the virtual machine rather than suspending it and saving its state. VirtualBox should say the virtual machine is “Powered Off.”
在继续之前,我们建议关闭虚拟机,而不是挂起虚拟机并保存其状态。 VirtualBox应该说虚拟机已关闭电源。
第一步:找到VBoxManage命令并打开命令提示符 (Step One: Locate the VBoxManage Command and Open a Command Prompt)
VirtualBox allows you to convert a fixed disk to a dynamic disk or a dynamic disk to a fixed disk, but this option isn’t exposed in its graphical interface. Instead, you have to use the VBoxManage.exe
command.
VirtualBox允许您将固定磁盘转换为动态磁盘,或将动态磁盘转换为固定磁盘,但是此选项未在其图形界面中显示。 相反,您必须使用VBoxManage.exe
命令。
Locate this command to continue. On Windows, you’ll find it in the VirtualBox program directory, which is C:\Program Files\Oracle\VirtualBox
by default. If you installed VirtualBox to another directory, look there instead.
找到此命令以继续。 在Windows上,您可以在VirtualBox程序目录中找到它,该目录为C:\Program Files\Oracle\VirtualBox
默认情况下。 如果将VirtualBox安装到另一个目录,请查看那里。
![](https://i-blog.csdnimg.cn/blog_migrate/6af1cc3f2eb0f9eeb7720ae61abdc98e.png)
Open a Command Prompt window. To do this, open the Start menu, type cmd
, and press Enter.
打开命令提示符窗口。 为此,请打开“开始”菜单,键入cmd
,然后按Enter。
![](https://i-blog.csdnimg.cn/blog_migrate/b13da3c2c70b7502afe273716727ee72.png)
Type cd
into the Command Prompt, followed by the path of the folder where the VBoxManage command is. You’ll need to enclose it in quotes.
在命令提示符中键入cd
,然后输入VBoxManage命令所在的文件夹的路径。 您需要将其用引号引起来。
You can quickly do this by typing cd
into the Command Prompt window, and then dragging and dropping the folder icon from the file manager’s address bar into the Command Prompt.
通过在命令提示符窗口中键入cd
,然后将文件夹图标从文件管理器的地址栏中拖放到命令提示符中,可以快速完成此操作。
![](https://i-blog.csdnimg.cn/blog_migrate/ee4684025f15535e2d690ec2dfc92ee7.png)
If you’re using the default path, it should look like the following:
如果您使用的是默认路径,则该路径应如下所示:
cd "C:\Program Files\Oracle\VirtualBox"
![](https://i-blog.csdnimg.cn/blog_migrate/fa7d4f5cbfd5c4fc7d72104546adc274.png)
NOTE: These instructions assume you’re using VirtualBox on Windows. If you’re using VirtualBox on macOS or Linux, you can just open a Terminal window and run the vboxmanage
command normally, as you would any other command.
注意:这些说明假定您在Windows上使用VirtualBox。 如果在macOS或Linux上使用VirtualBox,则可以像打开其他任何命令一样,仅打开Terminal窗口并正常运行vboxmanage
命令。
![](https://i-blog.csdnimg.cn/blog_migrate/acdccd17dd119daca0e50fbf24d4f6d0.png)
第二步:找到要转换的磁盘的路径 (Step Two: Locate the Path to the Disk You Want To Convert)
Run the following command in the command prompt window to view a list of all the virtual hard disks on your computer:
在命令提示符窗口中运行以下命令,以查看计算机上所有虚拟硬盘的列表:
VBoxManage.exe list hdds
![](https://i-blog.csdnimg.cn/blog_migrate/8654f87960d52e8024fac706a1d561ae.png)
Look through the list and identify the file path to the virtual disk you want to convert. Let’s say we want to modify the virtual disk associated with the virtual machine named “Windows”. As we can see in the output below, the path to that virtual disk on our system is C:\Users\chris\VirtualBox VMs\Windows\Windows.vdi
.
浏览列表,并确定要转换的虚拟磁盘的文件路径。 假设我们要修改与名为“ Windows”的虚拟机关联的虚拟磁盘。 从下面的输出中可以看到,系统上该虚拟磁盘的路径为C:\Users\chris\VirtualBox VMs\Windows\Windows.vdi
。
![](https://i-blog.csdnimg.cn/blog_migrate/1ad2c43d16ef7c145d7a37efeaa8a0e2.png)
第三步:转换虚拟磁盘 (Step Three: Convert the Virtual Disk)
You can now use the VBoxManage command to convert the virtual disk from fixed to dynamic, or from dynamic to fixed.
现在,您可以使用VBoxManage命令将虚拟磁盘从固定磁盘转换为动态磁盘,或从动态磁盘转换为固定磁盘。
To convert a virtual disk from fixed to dynamic, run the following command:
要将虚拟磁盘从固定磁盘转换为动态磁盘,请运行以下命令:
VBoxManage.exe clonemedium disk "C:\path\to\source.vdi" "C:\path\to\destination.vdi" –variant Standard
For example, if the source disk is located at C:\Users\chris\VirtualBox VMs\Windows\Windows.vdi
and you want to create a new disk named Windows-dynamic.vdi in the same folder, you’d run:
例如,如果源磁盘位于C:\Users\chris\VirtualBox VMs\Windows\Windows.vdi
并且您想要在同一文件夹中创建一个名为Windows-dynamic.vdi的新磁盘,则可以运行:
VBoxManage.exe clonemedium disk "C:\Users\chris\VirtualBox VMs\Windows\Windows.vdi" "C:\Users\chris\VirtualBox VMs\Windows\Windows-dynamic.vdi" –variant Standard
![](https://i-blog.csdnimg.cn/blog_migrate/9ab70e47a2f796c571b89ec45edc1048.png)
To convert a virtual disk from dynamic to fixed, run the following command:
要将虚拟磁盘从动态磁盘转换为固定磁盘,请运行以下命令:
VBoxManage.exe clonemedium disk "C:\path\to\source.vdi" "C:\path\to\destination.vdi" –variant Fixed
For example, if the source disk is located at C:\Users\chris\VirtualBox VMs\Windows\Windows.vdi
and you want to create a new disk named Windows-fixed.vdi in the same folder, you’d run:
例如,如果源磁盘位于C:\Users\chris\VirtualBox VMs\Windows\Windows.vdi
并且您想在同一文件夹中创建一个名为Windows-fixed.vdi的新磁盘,请运行:
VBoxManage.exe clonemedium disk "C:\Users\chris\VirtualBox VMs\Windows\Windows.vdi" "C:\Users\chris\VirtualBox VMs\Windows\Windows-fixed.vdi" –variant Fixed
![](https://i-blog.csdnimg.cn/blog_migrate/a16267267dffb7d0f47f64efb7eb6956.png)
第四步:删除旧的虚拟磁盘 (Step Four: Remove the Old Virtual Disk)
The above command just clones the existing disk. You end up with both the original disk file and a new disk file.
上面的命令只是克隆现有磁盘。 您最终将获得原始磁盘文件和新磁盘文件。
First, you’ll need to actually remove the existing virtual disk from VirtualBox. In VirtualBox, right-click the virtual machine that uses the virtual disk and select “Settings”.
首先,您实际上需要从VirtualBox中删除现有的虚拟磁盘。 在VirtualBox中,右键单击使用虚拟磁盘的虚拟机,然后选择“设置”。
![](https://i-blog.csdnimg.cn/blog_migrate/5adf32a5840b2a1f30dc8bc1c0b6c13c.png)
Select “Storage” to view connected storage devices. Right-click the original VDI and select “Remove Attachment”. Click “OK” afterwards.
选择“存储”以查看连接的存储设备。 右键单击原始VDI,然后选择“删除附件”。 然后单击“确定”。
![](https://i-blog.csdnimg.cn/blog_migrate/997e6c0aa2b75edbf60c02b9f6533535.png)
The below process will delete the original disk file from your drive. Warning: You may want to back up the original disk file if you haven’t already, just in case anything goes wrong with this process.
以下过程将从驱动器中删除原始磁盘文件。 警告:如果尚未备份原始磁盘文件,则可能需要备份原始磁盘文件,以防万一此过程出现问题。
In the Command Prompt, run the following command to view a list of all virtual disks on your computer:
在命令提示符中,运行以下命令以查看计算机上所有虚拟磁盘的列表:
VBoxManage.exe list hdds
Locate the UUID of the original disk you want to delete. You can copy it to your clipboard by selecting it with your mouse’s left mouse button and then right-clicking it.
找到您要删除的原始磁盘的UUID。 您可以使用鼠标的左键选择它,然后右键单击它,将其复制到剪贴板。
![](https://i-blog.csdnimg.cn/blog_migrate/f0fcae43af7b5f8d3c8f50270b56c0bd.png)
Run the following command to remove the original disk from VirtualBox’s registry and delete it. You can right-click in the Command Prompt window to paste the UUID.
运行以下命令,从VirtualBox的注册表中删除原始磁盘并删除它。 您可以在“命令提示符”窗口中右键单击以粘贴UUID。
VBoxManage.exe closemedium UUID --delete
![](https://i-blog.csdnimg.cn/blog_migrate/e835c693b50bb0e4ecbbfbd785e51334.png)
第五步:重命名新磁盘 (Step Five: Rename the New Disk)
You should now rename the new disk file so that it has the same name as the original one. Just navigate to it in a File Explorer or Windows Explorer window.
现在,您应该重命名新的磁盘文件,使其具有与原始磁盘文件相同的名称。 只需在文件资源管理器或Windows资源管理器窗口中导航到它即可。
![](https://i-blog.csdnimg.cn/blog_migrate/89bd8072be3b09bbff455ac0d5848116.png)
Right-click the VDI file, select “Rename”, and change it to the original name. For example, here we renamed the Windows-fixed.vdi file we created to Windows.vdi.
右键单击VDI文件,选择“重命名”,然后将其更改为原始名称。 例如,在这里我们将创建的Windows-fixed.vdi文件重命名为Windows.vdi。
![](https://i-blog.csdnimg.cn/blog_migrate/03f91cd820ac3a0f65f8155363d8de9f.png)
Once you’ve renamed the disk, remove the old disk name from VirtualBox. Click File > Virtual Media Manager in VirtualBox and locate the renamed disk’s original name—it will have a yellow warning icon to the left of it. Right-click it and select “Remove”. Click “Remove” again to confirm and close “Close”.
重命名磁盘后,从VirtualBox中删除旧磁盘名称。 单击VirtualBox中的“文件”>“虚拟介质管理器”,然后找到重命名的磁盘的原始名称-它的左侧将带有一个黄色警告图标。 右键单击它,然后选择“删除”。 再次单击“删除”以确认并关闭“关闭”。
![](https://i-blog.csdnimg.cn/blog_migrate/91bc9a74c2514d7837e72de806513af6.png)
第六步:将磁盘插入VirtualBox (Step Six: Insert the Disk In VirtualBox)
Head back into VirtualBox, right-click the virtual machine associated with the virtual disk, and select “Settings”. Under Storage, right-click the SATA controller and select “Add Hard Disk”.
返回VirtualBox,右键单击与虚拟磁盘关联的虚拟机,然后选择“设置”。 在“存储”下,右键单击SATA控制器,然后选择“添加硬盘”。
![](https://i-blog.csdnimg.cn/blog_migrate/5f7e9c144fc61527eadff8b4550a6182.png)
Select “Choose Existing Disk” and browse to the file you just renamed.
选择“选择现有磁盘”并浏览到刚刚重命名的文件。
![](https://i-blog.csdnimg.cn/blog_migrate/c9e1de15a2338559a186d7c80bd54552.png)
Click “OK” to close the virtual machine settings window. You should now be able to boot the virtual machine normally. Its disk will be either a fixed or dynamic disk—whichever you converted it to.
单击“确定”关闭虚拟机设置窗口。 现在,您应该能够正常启动虚拟机了。 它的磁盘将是固定磁盘或动态磁盘,无论您将其转换为哪个磁盘。
![](https://i-blog.csdnimg.cn/blog_migrate/73bd2bf958794707b860ae83d51b8fda.png)
翻译自: https://www.howtogeek.com/312456/how-to-convert-between-fixed-and-dynamic-disks-in-virtualbox/