jezaustin Tux's lil' helper
Joined: 22 Sep 2006 Posts: 96 Location: england
|
Posted: Fri Oct 25, 2013 11:43 am Post subject: virtualbox: savestate and resume guest, renew IP address |
|
|
Hi
just wanted to share a technique I developed to solve a minor problem on my virtualbox guests: DHCP leases would expire while the guest was hibernated, causing IP address clashes. I want to renew the IP address automatically after resumption.
The solution is to savestate from a script run on the guest. This interrupts the script before it is finished, so when the guest is resumed, the script continues with its next instructions, which are to renew the IP address.
My guest is windows, so the script is a batch file: Code: | plink.exe <puttySession> VBoxManage controlvm """<vboxGuest>""" savestate
ipconfig /release
ipconfig /renew |
plink (from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html) opens an SSH session and runs the VBoxManage command remotely on the host.
I can launch this from the guest (I have a shortcut on the desktop), but I tend to hibernate my guests from the host. From my fluxbox menu Code: | [submenu] (VMs)
[exec] (start <vboxGuest>) {VBoxManage startvm "<vboxGuest>"}
[exec] (hibernate <vboxGuest>) {VBoxManage guestcontrol "<vboxGuest>" exec --image "C:\\path\\to\\savestate.bat" --username <guestUserName> --password <guestUserPasswd> --wait-stderr} |
This might be of use to someone, and/or you might be amused by the control passing back and forth between host and guest!
NB: I find "guestcontrol exec" to be a bit flakey -- my first idea was to run a script on the host to "startvm" the guest, then "guestcontrol exec" the ip renewal, but it wasn't reliable. The hibernate command above is not completely reliable, but I prefer failure to hibernate (obvious and harmless) to failure to renew the IP address (silent and perhaps dangerous). |
|