Thursday, November 18, 2010

How to compact VirtualBox VDI drive

While working with dynamically expanding virtual drives you might notice that it actually virtual drive takes more space than it actually use by the virtual machine, e.g. you removed a bunch of files, defragmented volume, etc. Here is how you can compact VDI drive:
VBoxManage modifyhd --compact my-virtual-drive.vdi
Please note, that you can compact only drives that are registered with VirtualBox Media Manager.

Wednesday, November 17, 2010

How to change VirtualBox VDI drive UUID

While working with virtual machines you often need to copy an existing virtual machine and go from there, however once you try add it to VirtualBox you will get a message like this:
A hard disk with UUID ... is already registered.
In this case what you need is re-generate UUID for the VDI image. Here is how you can do that:
VBoxManage internalcommands setvdiuuid my-virtual-drive.vdi
This way the virtual drive my-virtual-drive.vdi will be assigned a new UUID so it can be registered in VirtualBox Media Manager.

Timing disk read/write performance with dd

There is easy way to measure your partition performance with dd. Here is how to measure write performance by simply coping a file of length 1 Gb:
deby:~# time dd if=/dev/zero of=file bs=1024 count=1000000
1000000+0 records in
1000000+0 records out
1024000000 bytes (1.0 GB) copied, 13.454 s, 76.1 MB/s

real 0m13.696s
user 0m0.240s
sys 0m5.924s
Same way we can read that file back into a memory (/dev/shm):
deby:~# time dd if=file of=/dev/shm/file
2000000+0 records in
2000000+0 records out
1024000000 bytes (1.0 GB) copied, 4.19182 s, 244 MB/s

real 0m4.334s
user 0m0.592s
sys 0m3.740s
Read more about dd command here.

Tuesday, November 16, 2010

How to defragment XFS

There is an easy way to find out if your XFS partition needs defragmentation. Here is the command (it is part of package xfsprogs):
deby:~# xfs_db -c frag -r /dev/sda10
actual 2903, ideal 2418, fragmentation factor 16.71%
Once you see it is pretty high, e.g. above 40% you would need to issue the following command that defragment the drive:
deby:~# xfs_fsr -v /dev/sda10
/home start inode=0