Friday Oct 18, 2013

Shrinking a Linux OEL 6 virtual Box image (vdi) hosted on Windows 7

Recently for a customer demonstration there was a requirement to build a virtual box image with Oracle Enterprise Manager Cloud Control 12c. This meant installing OEL Linux 6 as well as creating an 11gr2 database and Oracle Enterprise Manager Cloud Control 12c on a single virtual box. Storage was sized at 300Gb using dynamically allocated storage for the virtual box and about 10Gb was used for Linux and the initial build.

After copying over all the binaries and performing all the installations the virtual box became in the region of 80Gb used size on the host operating system, however internally it only really needed around 20Gb. This meant 60Gb had been used when copying over all the binaries and although now free was not returned to the host operating system due to the growth of the virtual box storage '.vdi' file.  Once the ‘vdi’ storage had grown it is not shrunk automatically afterwards.

Space is always tight on the laptop so it was desirable to shrink the virtual box back to a minimal size and here is the process that was followed.

Install 'zerofree' Linux package into the OEL6 virtual box

The RPM was downloaded and installed from a site similar to below;

http://rpm.pbone.net/index.php3/stat/4/idpl/12548724/com/zerofree-1.0.1-5.el5.i386.rpm.html

A simple internet search for ’zerofree Linux rpm’ was easy to perform and find the required rpm.

Execute 'zerofree' package on the desired Linux file system

To execute this package the desired file system needs to be mounted read only. The following steps outline this process.

As root: # umount /u01

As root:# mount –o ro –t ext4 /u01


NOTE: The –o is options and the –t is the file system type found in the /etc/fstab.

Next run zerofree against the required storage, this is located by a simple ‘df –h’ command to see the device associated with the mount.

As root:# zerofree –v /dev/sda11

 

NOTE: This takes a while to run but the ‘-v’ option gives feedback on the process.

What does Zerofree do?

Zerofree’s purpose is to go through the file system and zero out any unused sectors on the volume so that the later stages can shrink the virtual box storage obtaining the free space back.

When zerofree has completed the virtual box can be shutdown as the last stage is performed on the physical host where the virtual box vdi files are located.

Compact the virtual box ‘.vdi’ files

The final stage is to get virtual box to shrink back the storage that has been correctly flagged as free space after executing zerofree.

On the physical host in this case a windows 7 laptop a DOS window was opened.

At the prompt the first step is to put the virtual box binaries onto the PATH.

C:\ >echo %PATH%


 

The above shows the current value of the PATH environment variable.

C:\ >set PATH=%PATH%;c:\program files\Oracle\Virtual Box;

 

The above adds onto the existing path the virtual box binary location.

C:\>cd c:\Users\xxxx\OEL6.1

 

The above changes directory to where the VDI files are located for the required virtual box machine.

C:\Users\xxxxx\OEL6.1>VBoxManage.exe modifyhd zzzzzz.vdi compact

 

NOTE: The zzzzzz.vdi is the name of the required vdi file to shrink.

Finally the above command is executed to perform the compact operation on the ‘.vdi’ file(s). This also takes a long time to complete but shrinks the VDI file back to a minimum size. In the case of the demonstration virtual box OEM12c this reduced the virtual box to 20Gb from 80Gb which was a great outcome to achieve.

About

About Me Image
Andy Baker, Senior Principal Consultant for Oracle Consulting Services (@Bakers_byte), shares his news, views and ideas about the Oracle Database with a focus on innovation and emerging technologies.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today