回收VirtualBox虚拟机磁盘空间方法

您所在的位置:网站首页 虚拟空间最新 回收VirtualBox虚拟机磁盘空间方法

回收VirtualBox虚拟机磁盘空间方法

2024-07-17 09:32:46| 来源: 网络整理| 查看: 265

转自: http://maketecheasier.com/shrink-your-virtualbox-vm/2009/04/06 发现最好启动到用户模式下操作,否则会提示分区正忙,无法重新挂载。 zerofree软件可以在rpmfind.net网站上下载 While using Virtualbox, one thing that I have found is that the size of the VM (a file with .VDI extension) expands over time. If you have selected the “ Dynamically Expanding Storage” option when first creating the VM, you will find that the file size expands whenever you install new applications in the VM. That is perfectly normal. However, when you uninstall or delete applications in the VM, the file size does not shrink or return to its previous size. That is to say, if you are constantly installing and uninstalling applications in your VM, the VDI file could be taking up more space than it is actually using.

If you have a great deal of hard disk space to spare, you can simply ignore this. However, if you find yourself always running short of hard disk space, you might want to consider shrinking the VM and free up unused disk space.

This tutorial will go through the steps to shrink your Virtualbox VM.

It doesn’t matter if you are using Windows/Linux host. The instructions for a Windows and Linux guest are slightly different though. (I have not tried this on a Mac host yet. Theoretically it should work, but do it at your own risk.)

For Windows guest

If you are using Windows guest, do the following:

Uninstall all unnecessary applicationsPerform. a hard disk defragmentation. If you are using WinXP, you You can access the inbuilt disk fragmenter from Start -> All Programs -> Accessories -> System Tools -> Disk Defragmenter.

Download sdelete and extract it to your desktop.

Open a command prompt and cd to the sdelete directory. Type in the following command:

sdelete -c c:/

This will add zeroes to all the free space in your C: drive.

Once it is done, shutdown the VM.

For Linux guest

If you are using Linux guest (this tutorial assumes you are using Ubuntu and is running on ext2/ext3 filesytem. It does not work on ext4), here is what you need to do:

Remove any unused applications.Clean up your Linux VM

Install zerofree

sudo apt-get zerofree

Restart and boot your Linux VM into Recovery mode. (This is generally the second option in the Grub boot up screen.)

In the root shell prompt, type

df

This will display all the available filesystem in your OS. Record down the filesystem where the main directory lies. (it should be in /dev/sdaX or /dev/hdaX format)

vdi-filesystem

Mount the filesystem in read-only mode with the following command:

mount -n -o remount,ro -t ext3 /dev/sda1 /

replacing the /dev/sda1 with the filesytem info that you have recorded just now.

Next, type the following command to zero out all the free space.

zerofree /dev/sda1

Once again, replace the /dev/sda1 with your own filesystem info.

Once you are done, shutdown the Linux VM:

shutdown -h now Shrinking the VM

Now that we are done with clearing up the VM and zero out all the free space, it’s time to shrink the file size using the VboxManage command.

If you are still using the older Virtualbox 2.0.x version, you can easily shrink the hard disk with the following command:

VboxManage modifyvdi /path/to/your/VM.vdi compact

If you have upgraded your Virtualbox to the 2.1.x version, you will find that the above command will no longer work. There is a bug in the software that disable the use of the modifyhd command. An alternative solution is to use the clonehd command to creat a smaller clone copy of the original VM.

In your terminal (or command prompt), type the following:

VboxManage clonehd name-of-original-vm.vdi name-of-clone-vm.vdi

This will create a clone of the original VM with the name that you have specified in the command above.

Result

After shrinking my VM, I manage to shave 45% off the size of the oirginal VM and free up a whopping 4.5GB of hard disk space to store my other stuff.

The original VDI: 10GB

The cloned VDI: 5.5GB

Importing the clone VM into Virtualbox

The whole process is not finished yet. You still need to import the clone VM into Virtualbox and remove/delete the original VM from your system.

In your Virtualbox console, click on the New button.

Follow the instructions to create a new VM. When it reaches the screen to ask you to choose the hard disk, select Existing.

vdi-new-vm

In the Virtual media manager window, click Add to add the newly cloned VM.

Highlight the newly added VM and click Select.

Back to the Hard disk selection window, you should see your new VM in the dropdown selection. Click on Next to finish up the import.

Once everything is in place, run the newly added VM to make sure that it is working fine.

On the main Virtualbox screen, highlight  the original VM and go to Machine -> Delete. This will remove the entry from the console.

Go to File -> Virtual Media Manager. Highlight the original VM and click the Remove button. When prompt if you want to keep the file, select Delete. This will delete the vdi file from your system.

That’s it.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26194851/viewspace-723559/,如需转载,请注明出处,否则将追究法律责任。



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


    图片新闻

    实验室药品柜的特性有哪些
    实验室药品柜是实验室家具的重要组成部分之一,主要
    小学科学实验中有哪些教学
    计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
    实验室各种仪器原理动图讲
    1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
    高中化学常见仪器及实验装
    1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
    微生物操作主要设备和器具
    今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
    浅谈通风柜使用基本常识
     众所周知,通风柜功能中最主要的就是排气功能。在

    专题文章

      CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭