Showing posts with label virtualization. Show all posts
Showing posts with label virtualization. Show all posts

Wednesday, October 7, 2009

Save VM State During Logout

I run multiple VM's using VirtualBox on my laptop.  Few time I forgot to shutdown the VM's prior to logging off, which caused me to loose my work.  So, I decided to write a little script to save the state prior to logoff.

Add the following to your ~/.bash_logout


for vm in `/usr/bin/VBoxManage list runningvms | grep -E "^\"" | awk -F "\"" '{print $2}'`;
do
   /usr/bin/logger -p local0.info -t VirtualBox "Saving state: $vm"
   /usr/bin/VBoxManage controlvm $vm savestate | grep % | logger -p local0.info -t VirtualBox
done

Sample /var/log/messages output:

Oct 7 00:43:46 moonshine VirtualBox: Saving state: lamp32
Oct 7 00:43:48 moonshine VirtualBox: 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

Cheers,
VVK

Tuesday, October 6, 2009

Linux VM Kernel Tweaks

Based on "Oracle 10g Server on Red Hat Enterprise Linux 5 - Deployment Recommendations", I updated my VirtualBox Linux VM's to use the following kernel parameters:

64bit RHEL/CentOS VM: divider=10 notsc iommu=soft elevator=noop
32bit RHEL/CentOS VM: divider=10 clocksource=acpi_pm iommu=soft elevator=noop

Consult /usr/share/doc/kernel-doc-2.6.18/Documentation (kernel-doc-2.6.18-164.el5 rpm) for more info on these parameters.  The above mentioned Oracle document does a good job of explaining the parameters as well.

Although, I did not do any scientific measurements, just from the CPU usage live graph and pidstat (sysstat), I can confirm that my CPU usage dropped drastically.

Pre-tweak:

$ pidstat -u -p 22414 5 10  
Linux 2.6.30.8-64.fc11.i586 (moonshine) 10/06/2009

01:49:27 PM PID %user %system %CPU CPU Command
01:49:32 PM 22414 39.20 28.00 67.20 1 VBoxHeadless
01:49:37 PM 22414 40.80 27.60 68.40 1 VBoxHeadless
01:49:42 PM 22414 37.80 28.40 66.20 1 VBoxHeadless
01:49:47 PM 22414 38.40 27.80 66.20 1 VBoxHeadless
01:49:52 PM 22414 38.60 28.20 66.80 1 VBoxHeadless
01:49:57 PM 22414 36.40 28.20 64.60 1 VBoxHeadless
01:50:02 PM 22414 38.80 26.20 65.00 1 VBoxHeadless
01:50:07 PM 22414 38.40 28.80 67.20 1 VBoxHeadless
01:50:12 PM 22414 38.40 29.00 67.40 1 VBoxHeadless
01:50:17 PM 22414 38.00 27.80 65.80 1 VBoxHeadless
Average: 22414 38.48 28.00 66.48 - VBoxHeadless

Post-tweak:

$ pidstat -u -p 22414 5 10
Linux 2.6.30.8-64.fc11.i586 (moonshine) 10/06/2009

01:53:55 PM PID %user %system %CPU CPU Command
01:54:00 PM 22414 3.20 3.60 6.80 1 VBoxHeadless
01:54:05 PM 22414 3.20 3.60 6.80 1 VBoxHeadless
01:54:10 PM 22414 2.80 3.40 6.20 1 VBoxHeadless
01:54:15 PM 22414 2.80 2.80 5.60 1 VBoxHeadless
01:54:20 PM 22414 3.00 3.20 6.20 1 VBoxHeadless
01:54:25 PM 22414 3.60 3.80 7.40 1 VBoxHeadless
01:54:30 PM 22414 4.00 4.40 8.40 1 VBoxHeadless
01:54:35 PM 22414 3.20 3.00 6.20 1 VBoxHeadless
01:54:40 PM 22414 5.00 5.80 10.80 1 VBoxHeadless
01:54:45 PM 22414 6.40 4.00 10.40 1 VBoxHeadless
Average: 22414 3.72 3.76 7.48 - VBoxHeadless

Cheers,
VVK