Skip to content

VirtualBox pause and resume

February 17, 2009

I have a VirtualBox running ubuntu that is acting as a print server for my HP Officejet J6410 and although that works well it chews a significant amount of CPU resource which given that the printer is not in use most of the time seems a bit of a waste, especially when the Sun Ray server can have 4 active sessions running on it. So now I am running this simple script:

#!/bin/ksh93 -p   logger -p daemon.notice -t ${0##*/}[$$] |&  exec >&p 2>&1  while : do         echo resuming vbox         su – vbox -c "VBoxManage -nologo controlvm ubunto resume"          ssh print-server sudo ntpdate          while ping printer 2 > /dev/null 2>&1         do                 sleep 60         done         echo pausing vbox         su – vbox -c "VBoxManage -nologo controlvm ubunto pause"         until ping printer 2 > /dev/null 2>&1         do                 sleep 1         done done 

After the usual magic to redirect it’s output to syslog this just loops forever pinging the printer. If the printer is alive the VrtualBox is resumed and if the printer is not alive the VirtualBox is paused. So as soon as the printer is turned on the virtual box is ready and then within 60 seconds of the printer being turned off the virtualbox is paused.

So that the clock on the VirtualBox is kept correct (the guest additions are, I am told, supposed to do this for free but in practice they do not for me) after resuming there is the ssh onto the virtual machine to set it’s clock*, so I have a work around in place for VirtualBox which is itself a work around for a defect in Solaris and that work around is also working around another issue with Solaris.

Life on the bleeding edge is always fun!

*) I would normally use the address of my server to sync with but thanks to the issues with build 108 I currently don’t have a working ntp server on the system.


From → Solaris

  1. W. Wayne Liauh permalink

    How long does it usually take to resume your VM?

  2. That is hard to say. I just ran this command:
    : pearson FSS 36 $; time (su – vbox -c "VBoxManage -nologo controlvm ubunto resume" ; ssh print-server uname -a)
    Linux cjg-desktop 2.6.27-11-generic #1 SMP Thu Jan 29 19:24:39 UTC 2009 i686 GNU/Linux
    real 0m0.57s
    user 0m0.05s
    sys 0m0.03s
    : pearson FSS 37 $;
    Which is telling me it takes just over half a second to resume. Plenty fast enough for me. However the virtualbox was only recently paused so it is possible that it could be effected by being paged out if left idle for a long time. I don’t know enough about how VirtualBox handles this to comment accurately.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: