2009年2月12日

Linux in VMWare with auto Start-up and Shutdown setup

Thanks for the powerful machine and Virtualization, we can simply setup the Linux server on top of Windows platform. The installation is pretty simple but how can we make it start up automatically? In addition, as Linux requires shutdown properly. There is no out-of-the-box feature to take care of this.

I am going to share some method and scripts here to solve this out.

Software (I assume the software, virtual machine are setup properly):
  • Windows XP SP3, with auto login enabled
  • VMWare Workstation 6.5
  • Bitvise Tunnelier
Note: This method is design for auto login. I may post another solution for running the VM as a Windows service later.

Note: Change the text in RED according to your case

STEP 1 - Auto Start
  1. Enable Auto login (It can be done by using Windows' Free Tweak UI application. Please search the web for further setup.
  2. In VM workstation, In [Edit]-[Preference] setting, select "Workspace" tab. Check "Keep VMs running after Workstation closes"
  3. Create a new text file named something like autostart_vms.bat with below LINE:
    "C:\Program Files\VMware\VMware VIX\vmrun.exe" -T ws start "D:\VirtualMachines\homeserver.vmx" nogui
  4. Save this batch file in startup folder. In general, it should be:
    C:\Documents and Settings\All Users\Start Menu\Programs\Startup\"
  5. Reboot and check the VM can be started automatically.
STEP 2 - Graceful shutdown script
  1. Since I cannot let vmrun.exe to send a poweroff command to Linux, I need to send remote command thru SSH. Please setup NAT in Virtual Network correctly
  2. Start Group policy editor: (Start Menu)->Run-> Type gpedit.msc
  3. Locate Script-shutdown like this:


    (Ref.: http://vlaurie.com/computers2/Articles/group_policy_editor.htm)

  4. Create a new text file named something like shutdown_vms.bat with below LINES:
    "C:\Program Files\Bitvise Tunnelier\sexec.exe" yourusername@localhost:22 -pw=yourpasswd -cmd="sudo poweroff"

    sleep 30

    "C:\Program Files\VMware\VMware VIX\vmrun.exe" -T ws poweroff "D:\VirtualMachines\homeserver.vmx"
  5. Note that, the sleep time may variate due to the time taken by linux shutdown. Adjust this value according to your needs.
  6. Save this batch file in policy shutdown folder. In general, it should be:
    C:\WINDOWS\System32\GroupPolicy\Machine\Scripts\Shutdown
  7. Shutdown and check it is functioning.

沒有留言:

發佈留言