vmware 收缩硬盘大小(compat,shrink,vmware-vdiskmanager)

背景:

前段时间装了一个虚拟机,准备装一个好几百g大小的软件,首先我把安装介质传到了虚拟机里面,用了100GB空间,然而我的安装介质明明只有50g,怎么回事呢?经过我用du -sh命令查询到底那里占了空间,最后锁定了

[root@lyg VMwareDnD]# pwd
/tmp/VMwareDnD

这个目录下有一个跟我的安装介质相同大小的文件,但是问题是,系统没有自动删除,最后我把这个目录下所有文件都手动删除了。

接着上面的问题,虽然虚拟机里已经删除了,也有了剩余空间。但是,我安装软件的时候,一直使用的是我宿主机的硬盘的空间,也就是说,我虚拟机里面的空闲的空间一直是那么多,就是不使用。。。这下麻烦了。。随着宿主机空间越来越小,一会宿主机就没磁盘了,还有就是我建虚拟机的时候给虚拟硬盘的空间是200G,没想到的是,虚拟机自己会扩张这个硬盘的大小,最后比200G还大很多。。

最后,我决定想办法收缩一下硬盘。。。

Compact a Virtual Disk

Compacting a virtual disk reclaims(回收再利用) unused space in the virtual disk. If a disk has empty space, this process reduces the amount of space the virtual disk occupies on the host drive(这个进程操作降低了虚拟磁盘占用宿主机磁盘的空间)

Make sure the following prerequisites are met:




The virtual machine is powered off.(先关机)



The virtual disk is not mapped (on Windows guests) or mounted (on Linux guests). You cannot compact a virtual disk while it is mapped or mounted.(没被挂载)



The disk space is not preallocated (被预先分配)for the virtual hard disk. Use the virtual machine settings editor to view the disk information for this virtual hard disk. If the disk space was preallocated, you cannot compact the disk.



If the virtual hard disk is an independent disk, it is in persistent mode.

To change the mode, see Exclude a Virtual Disk from Snapshots for a description of independent disks.

To compact a virtual disk


1

Select VM > Settings.

2

On the Hardware tab, select Hard Disk for the virtual hard disk you
want to compact.

3

Select Utilities > Compact

4

Click OK after the disk compacting process is complete. 

我按照上面的步骤进行了compact,很遗憾,不知道为什么,花了好几个小时,进行了compact,竟然硬盘没有任何的变化,这个时候我都快崩溃了。。。。

从网上找到了这个连接,貌似这个网友与我碰到了一样的问题:

http://zhidao.baidu.com/link?url=a4_b3ujJ9D2YnIj_1-Mz8dJ2H7-oYQjgbi_wjZ3VBg_rBsc6GohRmJ9v5NGLUxu81cmbhvHZKKd47kVYyvfPnq

在这个问题的答案下面,有网友说,shrink应该管用,于是,我去找了shrink的相关资料:

http://www.vmware.com/support/ws5/doc/ws_disk_shrink.html(这是官方的文档)

Shrinking Virtual Disks

If you have a virtual disk that grows as data is added, you can shrink it as described in this section.If you allocated all the space for your virtual disk at the time you created it, you
cannot shrink it.(就是说,如果你选择了在建立虚拟机的时候一次性分配硬盘空间,那就不能收缩了)

Note: The maximum benefit occurs when you defragment
a virtual disk before you shrink it. See Defragmenting
Virtual Disks
.(最好碎片整理一下)

Shrinking a virtual disk reclaims unused space in the virtual disk. If there is empty space in the disk, this process reduces the amount of space the virtual disk occupies on the host drive.(这就是我要的目的啊啊啊啊)

Shrinking a virtual disk is a convenient way to convert a virtual disk to the format supported by Workstation. Virtual disks created in the new format can be recognized only by VMware Workstation 3.0 and higher.

This section describes the following topics:

Restrictions
and Requirements

The
Shrinking Process

Unsupported
and Disabled Partitions

Restrictions and Requirements

Shrinking requires free disk space on the host equal to the size of the virtual disk you are shrinking.(收缩空间时,必须硬盘空间有和虚拟机磁盘一样大的空间,当时我就泪奔了。。。尼玛。。我收缩就是因为硬盘没空间了啊。。不过我在绝望的时候又做了一次defragment,然后compatc了一下,这次没报希望的动作居然成功的把物理硬盘空间腾出来30G,这样一来,我的磁盘空余空间就大于虚拟磁盘空间了)

Shrinking applies only to virtual disks. You cannot shrink physical disks or CD-ROMs.

The shrink feature is not enabled if the virtual machine

Contains a snapshot(有快照存在的时候不能shrink)

Is a parent of a linked clone

Is a linked clone

The shrink feature is not enabled for a virtual machine if any of its virtual disks are

Preallocated when created(建虚拟机时分配 好了的磁盘不能收缩)

Not used in independent-persistent mode(意思是 只有independent-persistent模式的才可以收缩)

Legacy disks that are not in persistent mode

Booted as independent disks

Note: You can
change the mode of a virtual disk before the virtual machine is powered on. See Excluding
Disks from Snapshots
 for a discussion of independent disks.

The Shrinking Process

Shrinking a disk is a two-step process:

In the first step, called wiping, VMware Tools reclaims all unused portions of disk partitions (such as deleted files) and prepares them for shrinking. Wiping takes place in the guest operating system.(第一步,被称为清理,VMware
Tools要求收回所有磁盘分区中未使用的部分(诸如删除的文件)并为收缩作好准备。清理工作在客户机操作系统中进行。 )

The second step is the shrinking process itself, which takes place on the host. Workstation reduces the size of the disk's files by the amount of disk space reclaimed in the wipe process.(第二步,收缩虚拟磁盘,它在宿主机中进行。Workstation通过清理程序回收磁盘空间来减少虚拟磁盘文件的大小。

When a virtual machine is powered on, you shrink its virtual disks from the VMware Tools control panel. You cannot shrink virtual disks if a snapshot exists. To remove the snapshot if one exists, choose VM
> Snapshot > Snapshot Manager > Delete. See Unsupported
and Disabled Partitions
.

In a Linux or FreeBSD guest operating system, to prepare virtual disks for shrinking, you should run VMware Tools as the root user. This way, you ensure the whole virtual disk is shrunk. Otherwise, if you shrink disks as a nonroot user you cannot wipe the parts
of the virtual disk that require root-level permissions.

To shrink a virtual disk:

1. Launch the control panel.

Windows guest — double-click the VMware Tools icon in the system tray,
or choose Start > Settings > Control Panel, then double-click VMware
Tools.

Linux or FreeBSD
guest — become root (su -), then run vmware-toolbox

.#/usr/bin/vmware-toolbox

2. Click the Shrink tab.

3. Select the virtual disks you want to shrink, then click Prepare to Shrink.

A dialog box tracks the progress of the wiping process.

Note: If you deselect some partitions, the whole disk is still shrunk.
However, those partitions are not wiped for shrinking, and the shrink process does not reduce the size of the virtual disk as much as it could with all partitions selected.

4. Click Yes when VMware Tools finishes wiping the selected disk partitions.

A dialog box tracks the progress of the shrinking process. Shrinking disks may take considerable time.

5. Click OK to finish.

Unsupported and Disabled Partitions

In some configurations, it is not possible to shrink virtual disks. If your virtual machine uses such a configuration, the Shrink tab displays information explaining why you cannot shrink your virtual disks.

For example, you cannot shrink a virtual disk if

You preallocated disk space when you created the disk. Preallocating disk space is the default option for both typical and custom virtual machine creation paths.

The virtual machine has any snapshots. To delete a snapshot, choose VM >
Snapshot >Snapshot Manager > Delete.

The virtual machine contains physical disks.

The virtual disk is not an independent disk in persistent mode.

The virtual disk is stored on a CD-ROM
执行完shrink之后,我的host主机的硬盘可用空间从190G增加到了240G,可见,容量收缩了50多个个G。。。

3、vmware-vdiskmanager

虚拟机在使用过程中,虚拟磁盘的大小会不断变大。即使你删除了磁盘中的文件,虚拟磁盘的大小仍然不会缩小。VMWare在VMWare Tools中推出了Shrink这个功能。在安装VMWare Tools后,在没有Snapshot的情况下,在Guest操作系统为Windows的情况下,能有效缩小虚拟磁盘大小。但如果在Guest操作系统为Linux时,此方法效果就不好了,而且有些挂载点无法Shrink。

     VMWare还推出了vmware-vdiskmanager工具,也能Shrink虚拟磁盘。在Guest操作系统为Linux时,单独用此工具没有什么效果。需要先在Guest系统中把未使用的 空间清零,在使用vmware-vdiskmanager,效果比较好。可以通过以下步骤有些缩小虚拟磁盘。

    1、cat /dev/zero > zero.fill;sync;sleep 1;sync;rm -f zero.fill

         在Shell中运行以上命令,能对未使用空间清零,需要较大的空闲空间(跳过这步也可以,只是压缩效果没有这样好)

    2、关闭Guest操作系统,进入VMWare安装目录运行:

         vmware-vdiskmanager.exe -k "f:/vmware/Fedora11/Fedora11.vmdk"

         就可以有效缩小虚拟磁盘的大小,基本达到你用了多少占用多少的效果。

    用此方法分别对Guest系统为Fedora11和OpenSolaris10的VMDK文件进行Shrink,效果明显。

时间: 2024-09-20 06:39:03

vmware 收缩硬盘大小(compat,shrink,vmware-vdiskmanager)的相关文章

Oracle的在线段收缩(Online Segment Shrink)

Oracle的在线段收缩(Online Segment Shrink)是指在线整理段空间里的碎片,它有以下几个特点 : 在线,即在段压缩过程中,DML几乎不受影响(只有在结束前很短的时间内,DML会被阻塞) in-place的操作,不需要额外的空间 收缩完成后索引依然可用 它不但能够收回高水位线以上未使用的空间,还可以收回高水位线下为使用的空间,它的主要步骤 是: 压缩段空间 调整高水位线 释放收回的空间 使用Shrink有两个前提条件: 表必须启用row movement 表段所在表空间的段空

linux 如何查看硬盘大小

  linux 如何查看硬盘大小,内存大小等系统信息及硬件信息 top 可以看到不少信息 fdisk & disk - l & df 查看系统硬盘信息和使用情况 lspci 查看主板信息等 cat /proc/cpuinfo CPU信息 cat /proc/meminfo 内存信息

linux查看目录大小及硬盘大小

  linux查看目录大小及硬盘大小的命令: # du -ks ---in all # du -k ---every last du和df命令都被用于获得文件系统大小的信息:df用于报告文件系统的总块数及剩余块数,du -s /用于报告文件系统使用的块数.但是,我们可以发现从df命令算出的文件系统使用块数的值与通过du命令得出的值是不一致的.如下例: # du -s /tmp 返回如下值: ---12920 /tmp 而 df /tmp返回如下值: Filesystem --512-blocks

计算机硬盘大小转换(B,KB,MB,GB,TB,PB之间的大小转换)

程序员都很懒,你懂的! java程序员在实际的开发中会遇到很多的单位换算问题.今天我给大家带来的是关于计算机硬盘大小的换算.多数情况下,一般要求b,kb,mb,gb,tb,pb之间的大小转换,我们都知道他们之间的换算是乘以1024或者除以1024.但是具体怎么用java代码来实现呢?请看下面的代码: package com.herman.utils; /*** * @see 存储大小(单位)转换器. * @author Herman.Xiong * @date 2014年5月27日 13:27:

c++-用C++怎样获取处理器信息、硬盘大小、内存大小等信息

问题描述 用C++怎样获取处理器信息.硬盘大小.内存大小等信息 处理器信息是这样的:Intel(R) Core(TM) i3 cpu M 380 @2.53GHz 有没有api直接获取的(求大神解答,谢谢) 解决方案 最简单的是直接去注册表中读,在HKEY_LOCAL_MACHINEHARDWAREDESCRIPTIONSystemCentralProcessorProcessorNameString 也可以用wim接口或者用嵌入式汇编调用cpuid直接获取.还可以调用systeminfo,从它

VMware EXSI为虚拟机centos安装VMware Tools_VMware

VMware EXSI 为虚拟机centos安装VMware Tools 1.首先查看虚拟机是否安装VMware Tools 2.打开虚拟机控制台 3.选择虚拟机--客户机--安装/升级VMware tools 4.建立一个挂载点挂载并拷贝解压 5.进入vmware-tools-distrib目录执行 ./vmware-install.pl 开始安装 因为该centos是最小化安装,会报一个错误 可以执行 yum -y groupinstall "Perl Support" 继续执行

VMware发布新版桌面虚拟化软件VMware View 3

VMWare是一个"虚拟PC"软件.它使你可以在一台机器上同时运行二个或更多Windows.DOS.LINUX系统.与"多启动"系统相比,VMWare采用了完全不同的概念.多启动系统在一个时刻只能运行一个系统,在系统切换时需要重新启动机器.VMWare是真正"同时"运行,多个操作系统在主系统的平台上,就象标准Windows应用程序那样切换.而且每个操作系统你都可以进行虚拟的分区.配置而不影响真实硬盘的数据,你甚至可以通过网卡将几台虚拟机用网卡连接

VMware虚拟化环境无法重命名VMware ESXi/ESX 中的虚拟机及其文件的问题解决

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://dgd2010.blog.51cto.com/1539422/1417534 在使用 vSphere Client 登录到VMware ESXi/ESX或vCenter在清单中重命名虚拟机时默认只会更改显示名称,而不会更改数据存储中的对应文件(或者只能重命名文件夹名称,不能重命名其中的文件).但只有同时重命名存储中的虚拟机的目录名称(文件夹名称)和文件后才能保持与清单中虚拟机的名

如何查看Win8系统电脑硬盘大小?

  1.首先我们需要找到"这台电脑"-"管理"具体如下. 2.接下来就会进入到计算机管理面板,"磁盘管理"双击它打开进入. 3.然后就会进入到磁盘管理控制面板,在这个面板的左下角我们就可以看到硬盘的容量是多大了. 好了这样你会看到你电脑中硬盘的空间大小了,如果有多个硬盘我们在此可以看到硬盘0,硬盘1这种符号了,在此即可准确的查看硬盘空间了.