How To: Migrate a VirtualBox Windows 7 client to VMware Player

Step 0 – [Linux-specific instruction] When installing VMware Player, let it use /etc/init.d/ even if your system uses Systemd. After install you can create a service for vmware like this:

/etc/systemd/system/vmware.service

[Unit]
Description=VMware daemon
 
[Service]
ExecStart=/etc/init.d/vmware start
ExecStop=/etc/init.d/vmware stop
PIDFile=/var/lock/subsys/vmware
TimeoutSec=0
RemainAfterExit=yes
 
[Install]
WantedBy=multi-user.target

Start the service with systemctl start vmware to make sure it kicks off. If you want it to start automatically at boot use systemctl enable vmware.

Step 1 – Disable any devices in the virtual machine that run on VirtualBox/Oracle drivers.

Step 2 – Convert the VirtualBox.vdi hard drive to VMDK format via “vboxmanage clonehd source.vdi target.vmdk –format VMDK”

Step 3 – Launch vmplayer and create a new virtual machine. Say that you’ll add the operating system later and let it use a ‘single large drive’ or such.

Step 4 – Replace the default created .vmdk drive with the one you converted in step 2.

Step 5 – You can try booting your VM at this point – if it works, GREAT! But it’s likely to bluescreen with a 0x000007b error, if so you’ll need to follow the rest of the steps below:

Mount the Win7 DVD in VMware Player (or Workstation) and boot to it.
At the first screen (Language Selection), hit Shift-F10 for a command prompt.
Run Regedit.
Load the system hive from the VM's disk:

1. Highlight HKEY_LOCAL_MACHINE
2. File > Load Hive
3. Select < c: > \Windows\System32\config\system
4. Regedit will ask for a Key name: Name it something like "p2v"
5. Expand HKEY_LOCAL_MACHINE\asdf\ControlSet001\Services\intelide
6. Change the data for value "Start" from "3" to "0".

Note: I did not do step 6a - but I did do step 6 (immediately above).
6a. Also repeat for: HKLM/System/CurrentControlSet001/Services/ and edit the "Start" parameter to the corresponding value from the list:

Aliide = 3
Amdide =3
Atapi = 0
Cmdide = 3
iaStorV = 3
intelide = 0
msahci = 3
pciide = 3
viaide = 3

7. Then find the key: HKLM\p2v\ControlSet001\services\LSI_SAS and set the start type to REG_DWORD 0
9. Navigate up from the key to the hive (''p2v''), then hit 'File > Unload Hive'.  In other words, select HKLM\p2v and click Menu > File > Unload Hive.
10.Exit regedit and reboot the VM.

With all that done, the Windows 7 client should boot in vmware player and start installing the VMware specific drivers.

Twiddles / Housekeeping

VM audio crackling? Live with it – it crackles for a few seconds then sorts itself out. Fixing it as per the below causes VM crashes with “vcpu-0 unexpected signal 11” errors.
In Windows client go: Control Panel | Hardware and Audio | Sound | Speakers | Properties | set it to 24-bit @ 44.1KHz or higher.
Source: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2012007

VM suspends and stops Linux host from suspending? Shut down the VM, then edit the .VMX file it and add the line suspend.disabled = “TRUE” then restart.

VM generating “spurius APIC interrupt on #CPU X, should never happen”? Edit /etc/vmware/config and add the line monitor_control.disable_hostedIPI = TRUE then restart VM.

VMware tools won’t install? Either try to find the ISO to mount and install from or install ncurses5-compat-libs – on Arch this is in the AUR at: https://aur.archlinux.org/packages/ncurses5-compat-libs/

A simple C++/SDL_net chat server & client rewritten

Back in January this year I was due to be teaching some diploma level programming (roughly equivalent to the UK A/S level for any Brits), and part of that had to deal with network programming with sockets and stuff, so I duly did my research and put together a simple chat server and client in SDL_net. And then my classes changed and I got moved on to teach other stuff. I wasn’t too upset though – I’d learnt a lot, and I’d put up the code to help people out who might be in a similar situation, so it was all good.

But now in November I’m back on programming duty, so I dug up my code, looked it over, and thought Naah – I can’t use that, it’s unweildy, and complex, and it would be a real pain to try to re-use the code. So I’ve gone back to the drawing board and refactored it all into something I hope is a lot more palletable and both easy to use and re-purpose. In effect, I’ve refactored it into two wrappers which now consist of a ServerSocket class and a ClientSocket class.

Check it out…

Cross Platform Socket Server and Clients
Cross platform socket connectivity? That'll be a yes, then...

Socket Server

The old chat server was 250 lines, it’s now down to 77:

  1. // Re-written simple SDL_net socket server example | Nov 2011 | r3dux
  2. // Library dependencies: libSDL, libSDL_net
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <SDL/SDL_net.h>
  7. #include "ServerSocket.h"
  8.  
  9. int main(int argc, char *argv[])
  10. {
  11. 	// Initialise SDL_net
  12. 	if (SDLNet_Init() == -1)
  13. 	{
  14. 		std::cerr << "Failed to intialise SDL_net: " << SDLNet_GetError() << std::endl;
  15. 		exit(-1);
  16. 	}
  17.  
  18. 	// Create a pointer to a ServerSocket object
  19. 	ServerSocket *ss;
  20.  
  21. 	try
  22. 	{
  23. 		// Try to instantiate the server socket
  24. 		// Parameters: port number, buffer size (i.e. max message size), max sockets
  25. 		ss = new ServerSocket(1234, 512, 3);
  26. 	}
  27. 	catch (SocketException e)
  28. 	{
  29. 		std::cerr << "Something went wrong creating a SocketServer object." << std::endl;
  30. 		std::cerr << "Error is: " << e.what()   << std::endl;
  31. 		std::cerr << "Terminating application." << std::endl;
  32. 		exit(-1);
  33. 	}
  34.  
  35. 	try
  36. 	{
  37. 		// Specify which client is active, -1 means "no client is active"
  38. 		int activeClient = -1;
  39.  
  40. 		// Main loop...
  41. 		do
  42. 		{
  43. 			// Check for any incoming connections to the server socket
  44. 			ss->checkForConnections();
  45.  
  46. 			// At least once, but as many times as necessary to process all active clients...
  47. 			do
  48. 			{
  49. 				// ...get the client number of any clients with unprocessed activity (returns -1 if none)
  50. 				activeClient = ss->checkForActivity();
  51.  
  52. 				// If there's a client with unprocessed activity...
  53. 				if (activeClient != -1)
  54. 				{
  55. 					// ...then process that client!
  56. 					ss->dealWithActivity(activeClient);
  57. 				}
  58.  
  59. 			// When there are no more clients with activity to process, continue...
  60. 			} while (activeClient != -1);
  61.  
  62. 		// ...until we've been asked to shut down.
  63. 		} while (ss->getShutdownStatus() == false);
  64.  
  65. 	}
  66. 	catch (SocketException e)
  67. 	{
  68. 		cerr << "Caught an exception in the main loop..." << endl;
  69. 		cerr << e.what() << endl;
  70. 		cerr << "Terminating application." << endl;
  71. 	}
  72.  
  73. 	// Shutdown SDLNet - our ServerSocket will clean up after itself on destruction
  74. 	SDLNet_Quit();
  75.  
  76. 	return 0;
  77. }

Socket Client

And the old chat client was 313 lines, which is now down to 83:

  1. // Re-written simple SDL_net socket client example | Nov 2011 | r3dux
  2. // Library dependencies: libSDL, libSDL_net
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <SDL/SDL_net.h>
  7.  
  8. #include "ClientSocket.h"
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12. 	// Initialise SDL_net (Note: We don't initialise or use normal SDL at all - only the SDL_net library!)
  13. 	if (SDLNet_Init() == -1)
  14. 	{
  15. 		std::cerr << "Failed to intialise SDL_net: " << SDLNet_GetError() << std::endl;
  16. 		exit(-1);
  17. 	}
  18.  
  19. 	// Create a pointer to a ClientSocket object
  20. 	ClientSocket *cs;
  21.  
  22. 	try
  23. 	{
  24. 		// Try to instantiate the client socket
  25. 		// Parameters: server address, port number, buffer size (i.e. max message size)
  26. 		// Note: You can provide the serverURL as a dot-quad ("1.2.3.4") or a hostname ("server.foo.com")
  27. 		cs = new ClientSocket("127.0.0.1", 1234, 512);
  28. 	}
  29. 	catch (SocketException e)
  30. 	{
  31. 		std::cerr << "Something went wrong creating a ClientSocket object." << std::endl;
  32. 		std::cerr << "Error is: " << e.what()   << std::endl;
  33. 		std::cerr << "Terminating application." << std::endl;
  34. 		exit(-1);
  35. 	}
  36.  
  37. 	try
  38. 	{
  39. 		// Attempt to connect to the server at the provided address and port
  40. 		cs->connectToServer();
  41.  
  42. 		string receivedMessage = "";
  43.  
  44. 		cout << "Use /quit to disconnect or /shutdown to shutdown the server." << endl;
  45.  
  46. 		// Display the initial prompt
  47. 		cs->displayPrompt();
  48.  
  49. 		// Run the main loop...
  50. 		do
  51. 		{
  52. 			// Check if we've received a message
  53. 			receivedMessage = cs->checkForIncomingMessages();
  54.  
  55. 			// If so then...
  56. 			if (receivedMessage != "")
  57. 			{
  58. 				// Display the message and then blank it...
  59. 				cs->displayMessage(receivedMessage);
  60.  
  61. 				// ...and then re-display the prompt along with any typed-but-not-yet-sent input
  62. 				cs->displayPrompt();
  63. 			}
  64.  
  65. 			// Get and deal with input from the user in a non-blocking manner
  66. 			cs->getUserInput();
  67.  
  68. 		// ... until we decide to quit or the server is shut down
  69. 		} while ( (cs->getShutdownStatus() == false));
  70.  
  71. 	}
  72. 	catch (SocketException e)
  73. 	{
  74. 		cerr << "Caught an exception in the main loop..." << endl;
  75. 		cerr << e.what() << endl;
  76. 		cerr << "Terminating application." << endl;
  77. 	}
  78.  
  79. 	// Shutdown SDLNet - our ClientSocket will clean up after itself on destruction
  80. 	SDLNet_Quit();
  81.  
  82. 	return 0;
  83. }

On top of all this we have try/catch exception handling, a nice encapsulated & easy to work-with/modify/extend design and debug flags to control whether the client/server should be verbose or run silently. Obviously the chat client itself can’t run completely silently – you wouldn’t be able to read the messages being sent back and forth! – but when debug is off it only ever outputs anything when it receives a message or when the user enters messages to send, so it’s pretty darn quiet.

Oh, and it now comes in Linux and Windows flavours =D

Overall I’m really happy with it – it’s taken a few days to properly redesign and test (not to mention the issues involved with porting to Windows) – but I think the next time I need to do some socket stuff with C++ I’d be able to grab this code, make whatever modifications I need and get something up and running in no time.

Awthome! =P

Download links

Notes on Building for Windows

The windows client and server projects have some important tweaks made for them to compile, and it’s worth mentioning what they are:

  • The solution (which contains two projects) comes comes with a copy of the SDL and SDL_net libs and headers all merged together in the SDL folder (well, there are separate libs and include folders, but all the headers from both are in the include folder and all the libs from both are in the libs folder).
  • Each project has the following libraries linked in: SDL.lib, SDLmain.lib and SDL_net.lib, these libraries point to…
  • SDL.dll and SDL_net.dll which are in the solution’s Debug folder, so you can compile and build from Visual Studio, BUT you’lll need to copy these two dll files into the same folder as the SocketServer-Rewritten.exe or SocketClient-Rewritten.exe folders to run the executables “standalone” in other locations as opposed to build-and-run-from-visual-studio style!
  • The projects are defined as console applications, and because SDLmain.lib defines the main function as int main(int argc, char *argv[]) and not just int main() you MUST keep the definition of main in-line with the SDLmain.lib definition.
  • Finally, the projects will only build successfully in debug mode. Why? I’ve no idea. If you know how to fix it then go for it!