Escolar Documentos
Profissional Documentos
Cultura Documentos
CDT - Dica Técnica - Compactar HDs de VMs
CDT - Dica Técnica - Compactar HDs de VMs
Cadastro
Título deste CDT- Dica Técnica - Compactar HDs de VMs.docx (*) Deve ser definido no próprio Alfresco, complementando-
se apenas o assunto. (OBS:o título à esquerda será
documento (*): automaticamente atualizado no próximo download).
Autor: Charles
Com o uso, é relativamente comum que os HDs de VMs (tanto VirtualBox quanto
VMWare) comecem a aumentar o espaço ocupado no HD físico. O mecanismo
para eliminar o espaço ocupado desnecessariamente envolve sempre:
NetBalancer
Página original:
https://www.howtogeek.com/312883/how-to-shrink-a-virtualbox-virtual-machine-and-free-
up-disk-space/
Reprodução da página:
RELATED ARTICLE
Remember that this will only shrink the disk if it’s grown in size and you’ve since removed
data. So, if you just created a dynamic disk, this won’t shrink it. But, if you’ve created a
dynamic disk, downloaded 10 GB of data into it, and then deleted that 10 GB of data
afterwards, you should be able to shrink the disk by about 10 GB.
RELATED ARTICLE
To check whether a disk is dynamic or fixed size in VirtualBox, right-click the virtual
machine that uses the disk and select “Settings”. Click the “Storage” tab and select the
disk. You’ll see what type of disk it is displayed next to “Details”. For example, in the
screenshot below, “Dynamically allocated storage” indicates that this is a dynamic disk.
If you have Windows installed inside the virtual machine, you should now boot the virtual
machine up and defragment its disks. Inside the virtual machine, search the Start menu for
“Defragment” and launch the “Disk Defragmenter” or “Defragment and Optimize Drives”
tool. Select the disk you want to compact and click “Defragment disk”.
MODELO deste documento (Coleção de Dicas Técnicas) http://181.192.160.65:8080/share/page/site/verisys---base-de-conhecimento/document-
details?nodeRef=workspace://SpacesStore/8535474d-703a-4cf6-8882-2067b2d2a8fa#page=1
After the defragmentation process is finished, you will need to write zeros to the empty space
inside the virtual machine. When you delete files, the deleted data is still stored on the disk so
VirtualBox can’t automatically shrink the drive. But, when you write zeros over the deleted
files, VirtualBox will see a large amount of zeroes—empty space, in other words—and be
able to compact the disk.
To do this, download the SDelete utility from Microsoft. Extract the sdelete.exe file to a
folder on your computer.
Change to the directory containing the sdelete.exe file by typing cd , pressing Space,
entering the path to the directory, and pressing Enter. Be sure to enclose the path in quotation
marks if it contains a space character. It should look like this:
cd "C:\path\to\folder"
For example, if you extracted the sdelete.exe file to your user account’s download folder
and your Windows username is Bob, you’d run the following command:
cd "C:\Users\bob\Downloads"
To quickly fill in the directory path, simply type cd into the Command Prompt window, press
Space, and then drag and drop the folder icon from the file manager’s address bar.
sdelete.exe c: -z
This will write zeros to all the free disk space on drive C:. If you want to shrink a secondary
drive located at a different drive letter in the virtual machine, type its drive letter instead of c:.
This is what the tool was designed for. As the SDelete page on Microsoft’s website notes, the
-z option is “good for virtual disk optimization”.
You’ll be asked to agree to the tool’s license agreement before continuing. Just click
“Agree”.
Wait for the process to complete. When it’s done, shut down your virtual machine using the
“Shut Down” option in its Start menu. You’re now ready to compact it.
If you have Linux installed in the virtual machine—a Linux guest operating system instead of
a Windows guest operating system, in other words—you can skip the defragmentation
process and use built-in commands to zero the free space on the drive. We’ll use Ubuntu as
the example here, but the process will be similar on other Linux distributions.
To do this, you’ll first need to install the zerofree utility inside the virtual machine. It should
be available in your Linux distribution’s software repositories. For example, you can install it
on Ubuntu by running the following command at the terminal inside your virtual machine:
You can’t actually use zerofree on your / partition while you’re booted into the standard
Linux environment. Instead, you’ll want to boot into a special recovery mode where your
normal root partition isn’t mounted. On Ubuntu, restart your virtual machine, and repeatedly
press the “Esc” key while it’s booting to access the Grub menu. When the Grub menu
appears, select “*Advanced options for Ubuntu” and press Enter.
Select the “(recovery mode)” option associated with the most recent Linux kernel—that is,
the option with the highest version number near the top of the list—and press Enter.
Press “Enter” afterwards when “Press Enter for maintenance” appears on your screen. You’ll
be given a terminal prompt.
At the command line, determine which virtual disk you want to zero by running the following
command:
df
Assuming your virtual machine was created with the default settings, it will only
have /dev/sda1 , which is the first partition on the first hard drive. If you’ve set things up
differently with multiple disks or multiple partitions, you may need to zero another partition
or zero multiple partitions.
You’re now ready to zero the disk. Run the following command, replacing /dev/sda1 with
the device name of the partition you want to write zeros to. Most people will just have
a /dev/sda1 device to zero.
zerofree -v /dev/sda1
When the zero process is finished, run the following command to shut down the virtual
machine:
halt
This option isn’t exposed in VirtualBox’s graphical interface. Instead, you have to use
the VBoxManage.exe command.
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.
Open a Command Prompt window. To do this, open the Start menu, type cmd and press Enter.
MODELO deste documento (Coleção de Dicas Técnicas) http://181.192.160.65:8080/share/page/site/verisys---base-de-conhecimento/document-
details?nodeRef=workspace://SpacesStore/8535474d-703a-4cf6-8882-2067b2d2a8fa#page=1
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.
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.
If you’re using the default path, it should look like the following:
cd "C:\Program Files\Oracle\VirtualBox"
Step Four: Locate the Path to the Disk You Want To Compact
Run the following command in the command prompt window to view a list of all the virtual
hard disks on your computer:
Look through the list and identify the file path to the virtual disk you want to compact. Let’s
say we want to modify the virtual disk associated with the virtual machine named “Windows
7”. As we can see in the output below, the path to that virtual disk on our system
is C:\Users\chris\VirtualBox VMs\Windows 7\Windows 7.vdi .
VirtualBox will compact the disk and you can immediately boot up the virtual machine
afterwards, if you like. How much space you end up saving depends on how much empty
space there was to recover.
VirtualBox allows you to create snapshotsfor each virtual machine. These contain a full
image of the virtual machine when you created the snapshot, allowing you to restore it to a
previous state. These can take a lot of space.
To free up more space, delete snapshots you don’t use. To view the snapshots you have saved
for a virtual machine, select it in the main VirtualBox window and click the “Snapshots”
button to the right of Details on the toolbar. If you no longer need a snapshot, right-click it in
the list and select “Delete Snapshot” to free up space.