Tag Archives: ubuntu-server

Clean up and compact your VDI

Tweet about this on TwitterShare on Google+Share on RedditShare on LinkedInShare on FacebookBuffer this page

TL;DR

Guest OS: sudo sfill -llvz /

Host OS: VBoxManage modifyhd --compact <_.vdi>

Details

My VirtualBox thin server had put on a few pounds over the months of guest OS database imports, static resource creation, temp file creation, log rotation, and a bunch of other stuff I don't need to store indefinitely. Every time more sectors need to be called upon to store something in the guest, VirtualBox will grow the physical VDI image accordingly, up to the maximum size specified. However, when you delete files from the guest system, the VDI doesn't shrink accordingly (and with good reason).

If you have implemented a backup strategy — as I have with Time Machine — you probably don't want to back up a 30 GB VDI file every single time a single bit changes (for example, when you boot the virtual machine). This is particularly true when you have deleted old databases, resources and logs, and the guest OS really only represents about 5 GB of data.

VBoxManage modifyhd allows you to compact a physical VDI, but with one important precondition, it only truncates zeros in the guest from the VDI:

With the --compact option, can be used to compact disk images, i.e. remove blocks that only contains zeros. This will shrink a dynamically allocated image again; it will reduce the physical size of the image without affecting the logical size of the virtual disk. Compaction works both for base images and for diff images created as part of a snapshot.

So simply having deleted a file from your guest will not allow you to reclaim space. You have to zerofill the free space on guest OS's volumes.

In your Guest (in this case, Ubuntu Server 12.04.02 LTS)

sudo apt-get install secure-delete
sudo sfill -llvz /

The -ll option writes only one pass (instead of the default 38) and the -z option replaces the single pass of data from /dev/urandom with zeros, which is what VBoxManage is looking for.

In your host:

VBoxManage modifyhd --compact <virtual_disk_file.vdi>

I shrunk mine from 25 GB to 5 GB in a single step. My SSD allowed me to zerofill about 20 GB in the guest and compact the VDI in less than 90 seconds.

Manpages

 

Compiling xslcache 0.7.1 for PHP 5.4

Tweet about this on TwitterShare on Google+Share on RedditShare on LinkedInShare on FacebookBuffer this page

We make heavy use of xslt at work (parsing xml data generated by php controllers), so the xslcache pecl module is pretty fundamental to our infrastructure. Of course, if you are using PHP 5.4 or above, like many pecl modules, it breaks. Here's how to get it to work.

Currently, trying sudo pecl install xslcache-beta with PHP >= 5.4 throws the following error at make:

/tmp/pear/temp/xslcache/php_xsl.c: In function 'xslcache_objects_new':
/tmp/pear/temp/xslcache/php_xsl.c:211:52: error: 'zend_class_entry' has no member named 'default_properties'
make: *** [php_xsl.lo] Error 1
ERROR: `make' failed

Download xslcache

Download the original source from the pecl svn repository, the 5.4 patch, and patch it manually:

svn checkout http://svn.php.net/repository/pecl/xslcache/trunk xslcache
cd xslcache
wget -O php_xsl.c.patch 'https://bugs.php.net/patch-display.php?bug_id=62856&patch=xslcache-php5.4-compat&revision=1362641549&download=1'
patch < php_xsl.c.patch

Make and install

This is a pretty straightforward make process for most linux software (you may need to adjust the location of xslcache.ini):

phpize
./configure
make
make test
sudo make install
sudo nano /etc/php5/cgi/conf.d/xslcache.ini
#add "extension=xslcache.so"

Note that if you make test the tenth may fail with the following:

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Test 10: EXSLT Support [tests/xslt010.phpt]
=====================================================================

If you're using XSLT 2.0, you probably don't need to worry about it.

Verify that xslcache is installed and enabled

Since we're already in the command line, let's check there:

php -i | grep XSLCACHE

Hopefully, you will see the following line:
XSLCACHE => enabled
Furthermore, you should be able to actually know it's doing its job because your benchmarks should improve.

Compiling xhprof for PHP 5.4

Tweet about this on TwitterShare on Google+Share on RedditShare on LinkedInShare on FacebookBuffer this page

We use xhprof to profile our web application framework. The pecl installer was failing with `[xhprof.lo] Error 1` in the make phase with PHP 5.4. Here's how to fix that.

Currently, trying
sudo pecl install xhprof-beta
throws the following errors in the `make` phase for PHP >= 5.4:

In file included from /usr/include/php5/main/php.h:33:0,
from /tmp/pear/temp/xhprof/extension/xhprof.c:27:
/usr/include/php5/main/php_config.h:2396:0: warning: "_GNU_SOURCE" redefined [enabled by default]
/tmp/pear/temp/xhprof/extension/xhprof.c:24:0: note: this is the location of the previous definition
/tmp/pear/temp/xhprof/extension/xhprof.c:236:1: warning: 'visibility' attribute ignored [-Wattributes]
/tmp/pear/temp/xhprof/extension/xhprof.c:240:28: warning: 'visibility' attribute ignored [-Wattributes]
/tmp/pear/temp/xhprof/extension/xhprof.c: In function 'hp_get_function_name':
/tmp/pear/temp/xhprof/extension/xhprof.c:898:10: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
/tmp/pear/temp/xhprof/extension/xhprof.c:909:13: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
/tmp/pear/temp/xhprof/extension/xhprof.c:911:13: warning: assignment discards 'const' qualifier from pointer target type [enabled by default]
/tmp/pear/temp/xhprof/extension/xhprof.c:930:34: error: 'znode_op' has no member named 'u'
/tmp/pear/temp/xhprof/extension/xhprof.c:963:9: warning: passing argument 1 of 'hp_get_base_filename' discards 'const' qualifier from pointer target type [enabled by default]
/tmp/pear/temp/xhprof/extension/xhprof.c:856:14: note: expected 'char *' but argument is of type 'const char *'
/tmp/pear/temp/xhprof/extension/xhprof.c: In function 'hp_execute_internal':
/tmp/pear/temp/xhprof/extension/xhprof.c:1650:24: error: 'znode_op' has no member named 'u'
/tmp/pear/temp/xhprof/extension/xhprof.c:1651:59: error: 'struct <anonymous>' has no member named 'return_reference'
/tmp/pear/temp/xhprof/extension/xhprof.c:1652:25: error: 'znode_op' has no member named 'u'
/tmp/pear/temp/xhprof/extension/xhprof.c: In function 'hp_compile_file':
/tmp/pear/temp/xhprof/extension/xhprof.c:1683:3: warning: passing argument 1 of 'hp_get_base_filename' discards 'const' qualifier from pointer target type [enabled by default]
/tmp/pear/temp/xhprof/extension/xhprof.c:856:14: note: expected 'char *' but argument is of type 'const char *'
make: *** [xhprof.lo] Error 1
ERROR: `make' failed

According to a PHP bug report, this issue was fixed by Facebook but not made available on pecl, so you will need to install from the xhprof github repo, like so:

wget https://github.com/facebook/xhprof/archive/master.zip
unzip master.zip
cd xhprof-master/extension/
phpize
./configure
make
sudo make install

And enable the module in your php.ini, where `xhprof.output_dir` is the directory into which profiles will be generated.

[xhprof]
extension=xhprof.so
xhprof.output_dir="/var/tmp/xhprof"

And restart apache, with either of the following two:
sudo service apache2 restart or sudo apachectl graceful

Existing users who have upgraded to PHP 5.4 may opt for this xhprof-0.9.2 patch.