Sam*_*mir 79 windows-7 virtualbox vdi
我想弄清楚如何更改 VDI 文件的大小。我是 VirtualBox 的新手,我有很多东西要学。但我想我掌握了基础知识。我已经安装了 Windows 7 作为我的第一个来宾。主机也是 Windows 7。我不确定要分配多少磁盘空间,所以我选择了 40 GB 的 VDI 大小和固定大小以提高性能。但是我现在改变了主意,我想再添加 10 GB。我一直在点击程序并阅读帮助菜单内容,但它没有帮助。它解释了磁盘控制器、SAS、SATA、SCSI、yada、yada,但不是我正在寻找的。
我在万维网上搜索了答案,VirtualBox 论坛说如果你想要最简单的方法,你应该使用 Gparted(一些 mod 发布了一个粘性)。一些用户讨论使用dd
命令。但这就是所有 Linux 的东西。此外,SU 有很多关于增加和减少 VDI 文件大小的问题,但它们都是关于使用 Linux 作为主机和 Windows 作为来宾。
我找到了这篇关于如何使用VBoxManage的命令进行操作的不错的博客文章modifyhd
。这家伙也在 Linux 上作为主机操作系统这样做。他甚至希望他的 VDI 文件和我的一样大小(50 GB),真是巧合。所以我想无论如何我都会尝试一下,要么成功要么打破它。可能会出什么问题?......嗯?好吧,这就是我得到的丑陋的惊喜。
C:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd "%userprofile%\virtua
lbox vms\sg2_win7_x64_lab\sg2_win7_x64_lab.vdi" --resize 51200
0%...
Progress state: VBOX_E_NOT_SUPPORTED
VBoxManage.exe: error: Resize hard disk operation for this format is not impleme
nted yet!
C:\Program Files\Oracle\VirtualBox>
Run Code Online (Sandbox Code Playgroud)
现在说什么?!...无法调整VDI格式的虚拟硬盘大小?你不说?不支持自己的格式?现在怎么样...
真的没有简单的方法可以更改 VDI 文件的大小,最好在 VirtualBox 中单击几下?有什么进展吗?
Sam*_*mir 136
概括:
VBoxManage.exe modifyhd --resize
可以增加(但不减少)磁盘映像的逻辑大小(来宾操作系统看到的大小)。VBoxManage.exe modifyhd inputfile.vdi --compact
可以减小物理磁盘映像大小(主机操作系统看到的磁盘上映像文件的大小)。但是,这不会更改逻辑磁盘大小。请注意,这仅在来宾操作系统中的可用空间已被清零的情况下才有效。modifyhd
仅适用于动态格式变体(“动态分配的图像”)。modifyhd
仅适用于 VDI 和 VHD 图像格式。有关详细信息,请参阅第8.23节。VBoxManage 修改手册中的hd。
尚未实施减小 VDI 的逻辑磁盘大小的原因是为了防止可能发生的数据损坏,并因此导致无法启动 VM。因此,使用该--resize
选项时,新磁盘大小必须大于当前大小。不允许小于或等于当前大小。换句话说,一个 40 GB 的磁盘只能调整到 41 GB 或更大,不能调整到 40 GB(这只是愚蠢的)或 39 GB 或更少。
旧版本的 VirtualBox 将 VDI 文件创建为“固定”格式变体。现在,新的默认设置是在创建新的 VDI(虚拟磁盘映像)文件时创建“动态”格式变体。(我猜这是自引入动态格式变体以来的情况,无论引入哪个版本。)
那么错误消息“尚未实现此格式的操作”意味着您的 VDI 文件使用“固定”格式变体。要解决此问题,您必须使用该clonehd
命令克隆 VDI 文件。要查看您的 VDI 文件当前的格式变体,您可以使用该showhdinfo
命令。
显示有关当前磁盘的 VDI 信息。
输入命令: vboxmanage.exe showhdinfo path\inputfile.vdi
C:\Program Files\Oracle\VirtualBox>VBoxManage.exe showhdinfo "%userprofile%\virt
ualbox vms\sg2_win7_x64_lab\sg2_win7_x64_lab.vdi"
UUID: 132e9af1-0428-49f4-bc45-4d84680e17f5
Parent UUID: base
State: created
Type: normal (base)
Location: C:\Users\Name\VirtualBox VMs\sg2_win7_x64_lab\sg2_win7_x64_lab.
vdi
Storage format: VDI
Format variant: fixed default
Capacity: 40960 MBytes
Size on disk: 40962 MBytes
In use by VMs: sg2_win7_x64_lab (UUID: dcd106b3-7ed6-4f19-ad94-820ab4dc10d3)
C:\Program Files\Oracle\VirtualBox>
Run Code Online (Sandbox Code Playgroud)
See where it says "fixed default"? That's why it spits out the error above when you try to resize it.
Clone the old VDI file to a new VDI file.
Input command: vboxmanage.exe clonehd path\inputfile.vdi path\outputfile.vdi
C:\Program Files\Oracle\VirtualBox>VBoxManage.exe clonehd "%userprofile%\virtual
box vms\sg2_win7_x64_lab\sg2_win7_x64_lab.vdi" "%userprofile%\virtualbox vms\sg2
_win7_x64_lab\sg2_win7_x64_lab_clone.vdi"
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'VDI'. UUID: 34dafa68-3093-4946-926a-8237ea263
e5c
C:\Program Files\Oracle\VirtualBox>
Run Code Online (Sandbox Code Playgroud)
Voilà! The old file has now been cloned to a new file. Since the default setting in new versions of VirtualBox is to use "dynamic" format variant, you don't have to define that explicitly. Although, if you are working with an older version of VirtualBox, then you might want to set the option to "dynamic" (if at all available) to ensure better compatibility and/or flexibility with future versions of VirtualBox.
Show VDI information about the cloned disk.
Input command: vboxmanage.exe showhdinfo path\inputfile_clone.vdi
C:\Program Files\Oracle\VirtualBox>VBoxManage.exe showhdinfo "%userprofile%\virt
ualbox vms\sg2_win7_x64_lab\sg2_win7_x64_lab_clone.vdi"
UUID: 34dafa68-3093-4946-926a-8237ea263e5c
Parent UUID: base
State: created
Type: normal (base)
Location: C:\Users\Name\virtualbox vms\sg2_win7_x64_lab\sg2_win7_x64_lab_
clone.vdi
Storage format: VDI
Format variant: dynamic default
Capacity: 40960 MBytes
Size on disk: 7806 MBytes
C:\Program Files\Oracle\VirtualBox>
Run Code Online (Sandbox Code Playgroud)
See how it now says "dynamic default"? How nice!
(On the side note! The reason it says 7806 MB as physical size here is because I had used the --compact
option on the original VDI file in an attempt to enforce conversion to dynamic format variant. Just something I read on the VirtualBox forum, it supposedly would have worked with older versions, so I thought I might as well give that a try. It didn't work.)
Resizing the cloned disk.
Input command: vboxmanage.exe modifyhd path\inputfile.vdi --resize 51200
C:\Program Files\Oracle\VirtualBox>VBoxManage.exe modifyhd "%userprofile%\virtua
lbox vms\sg2_win7_x64_lab\sg2_win7_x64_lab_clone.vdi" --resize 51200
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
C:\Program Files\Oracle\VirtualBox>
Run Code Online (Sandbox Code Playgroud)
Success! No format bullshitting no more. Just remember to resize the new, cloned disk, and not the original one. Keep in mind that the size is expressed in MB. I believe you can use e.g. 51200
as well as 50G
(or possibly "GB"). There is also the option --resizebyte
which can be used to express the size in bytes.
Show VDI information about the resized clone disk.
Input command: vboxmanage.exe showhdinfo path\inputfile_clone.vdi
C:\Program Files\Oracle\VirtualBox>VBoxManage.exe showhdinfo "%userprofile%\virt
ualbox vms\sg2_win7_x64_lab\sg2_win7_x64_lab_clone.vdi"
UUID: 34dafa68-3093-4946-926a-8237ea263e5c
Parent UUID: base
State: created
Type: normal (base)
Location: C:\Users\Name\virtualbox vms\sg2_win7_x64_lab\sg2_win7_x64_lab_
clone.vdi
Storage format: VDI
Format variant: dynamic default
Capacity: 51200 MBytes
Size on disk: 7806 MBytes
C:\Program Files\Oracle\VirtualBox>
Run Code Online (Sandbox Code Playgroud)
That's it! From here what you have to do is add this cloned drive as your new VDI for the VM. You do that inside VirtualBox. I won't go into that. If you have been able to read and understand this so far then you probably don't need no further guiding. You can either delete the old "fixed" file, or leave it as a backup. Make sure you test the new VDI file before you delete the original source file.
Note! You will not immediately see the new size of the cloned disk. You have to boot the VM with it, and then you have to use your partition management tool to expand your partition to fill the virtual disk (or create more partitions). For Windows, just run diskmgmt.msc
and you'll be able to expand the partition in there.
小智 15
这是一个相当简单的过程,它对我有用,可以在我的 Mac(OS X 10.9.4)上将 VirtualBox(v. 4.3.16)固定大小磁盘调整为 60GB 动态磁盘,Linux(Ubuntu 14.04)作为来宾操作系统运行:
在 Mac 上的终端中,将 CD 放入包含 VDI 文件的目录中并键入以下内容:
VBoxManage showhdinfo mydisk.vdi
VBoxManage clonehd mydisk.vdi mydiskClone.vdi
VBoxManage modifyhd mydiskClone.vdi --resize 61440
VBoxManage showhdinfo mydiskClone.vdi
Run Code Online (Sandbox Code Playgroud)
在VirtualBox应用存储部分,添加mydiskClone.vdi作为第二块硬盘,然后正常启动VM。
在来宾操作系统的 shell 中,键入:
sudo fdisk /dev/sdb
- delete all partitions
- create new partition on full disk
Run Code Online (Sandbox Code Playgroud)
重新启动来宾。当它恢复时,再次进入 shell 并键入:
sudo resize2fs /dev/sdb1
Run Code Online (Sandbox Code Playgroud)
关闭来宾操作系统。
再次在 VirtualBox 应用程序存储部分,将 mydiskClone.vdi 设置为启动盘。然后启动来宾操作系统并使用文件浏览器中的“计算机”属性验证新磁盘大小。
小智 6
克隆实际上是一个更好的解决方案,并且有一种更简单的方法来做到这一点。
从文件菜单中,选择虚拟媒体管理器,然后单击复制。源将是您原来的固定大小的 vdi 硬盘,而您的目的地将是您选择的新硬盘(包括新的选项)。
小智 5
好的,所以我在没有克隆的情况下实现了它。
我有一个带有 Ubuntu 的 100GB VDI 文件(固定格式)。工作正常。我想通过缩小 VM 来释放主机中的一些空间。
脚步:
删除了不需要的文件。45GB 免费。我只需要释放 30GB。
我只有一个分区,所以不能在来宾 Ubuntu 内部做任何事情。在 VM 中安装 Ubuntu Live 并从中启动。
用于gparted
将分区缩小到 70GB。在未使用的空间中创建了一个新分区ext4
。
新分区中的可用空间 (30GB)。
遵循本指南:使用 zerofree 将 Ubuntu 上的虚拟硬盘缩小为来宾和主机操作系统
我的新分区是/dev/sda3
.
$ sudo apt-get install zerofree
$ sudo init 1
...
# mkdir /tmp3
# mount -o ro -t ext4 /dev/sda3 /tmp3
# zerofree -v /dev/sda3
Run Code Online (Sandbox Code Playgroud)
压缩 VDI
VBoxManage 修改hd "ubuntu.vdi" 压缩
花了一段时间,但它奏效了!
归档时间: |
|
查看次数: |
171408 次 |
最近记录: |