Link to home
Start Free TrialLog in
Avatar of rmstrnglaw
rmstrnglawFlag for United States of America

asked on

How to load a virtual machine on boot?

Hey folks,

I'm having a bit of a hard time finding reference to how a virtual machine would be loaded on boot in Linux. I'm running Ubuntu 8.04, the latest beta, as that is what will be current by the time this hardware goes live.

The problem is that I need a script that will load up the virtual machine(s) on boot with no login.

I'm hoping someone here can point me in the right direction. Solve the problem and I'll add extra points to the question.

Thanks much!
Avatar of LinuxNtwrkng
LinuxNtwrkng
Flag of United States of America image

1. Start VMWare.
2. Select virtual host.
3. Click : Edit virtual machine settings.
4. Click : Tab Options.
5. Click : Startup/Shutdown
6. Select : On host startup -> Power on virtual machine.
ASKER CERTIFIED SOLUTION
Avatar of LinuxNtwrkng
LinuxNtwrkng
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rmstrnglaw

ASKER

It's a small enough operation that security isn't a massive concern but I still don't like the idea that a maintenance or cleaning guy could walk in, flip a breaker, and have network access 45 seconds later. On principle, I'd love to find a way to do this without an auto-login script - at the very least I'd want an instant lock desktop after the command was executed.

Is there really no way that anyone knows of to run a pre-boot script that loads the virtual machine into memory? That seems unlikely.

Also, VMWare Workstation 6 only has the option to "power on when selected" - worth noting.
I've got my own problem half solved at this point.

The easy answer is this - buy VMWare Server, it simply creates a startup option. If you don't have Server but do have a copy of Workstation (not uncommon given the price difference), auto-starting a program without login credentials is as simple as editing it into the .xinitrc file.

.xinitrc executes startup scripts when the X Windows environment boots up, so that the program is waiting when you log into Ubuntu, KDE, Suise - whatever.

There is a solid tutorial here:
http://suseroot.com/suse-linux-tweaks/load-startup.php

Now, I know there are scripting calls that can be made from Workstation or the Player - I've seen them mentioned but hadn't ever given them much thought until now.

So if someone can tell me what switches would go on the end of a VMWare Player execution in .xintrc, I'll probably have my problem solved. The virtual machine should, in theory, boot up with X before logging in as a user - admin or otherwise.

So can someone answer me part two? I'm sure I'll figure this out eventually, to the benefit of the community at large, but you know I'd love a shortcut =)
Okay, we're working within the VMRUN command in the console.

I should be able to get it working from here, if I do, I'll write back a proper tutorial. If I don't, I'll come back with more questions.
Moving forward and backwards here.

To run a virtual machine from the console, the path to the machine or team is used as follows:
vmrun start /media/disk-2/vmware/indexer/indexer.vmx

In this case, my machine is named indexer.vmx (part of a Worldox setup)

Now to take two steps forward and one back - Ubuntu does not read .xinitrc, as it boots the Gnome environment, and we don't want to wait for GNU or X to load in anyway.

Back to square one on where to write in the script. C'mon, this should be basics - where is the file folks?
What's wrong with the crontab entry I supplied?
There's nothing wrong with the cronjob and, actually, if I want to use VMware Workstation - it's the best way to handle things from a command-line perspective.

Given that security demands a locked desktop though, I'd also add this line:
gnome-screensaver-command --lock

Given that the average Ubuntu user is pretty GUI-centric though, and VMWare Workstation is a bit of a beast to load up when VMPlayer installs along side it - what I'd recommend to future browsers on this thread is the following.

1. Installing VMWare Workstation on Ubuntu 8.04
Currently, this isn't supported. There is a very simple tutorial here:
http://igordevlog.blogspot.com/2008/03/vmware-603-in-ubuntu-hardy-804-kernel.html

2. Once you have created a virtual machine in Workstation, you will probably want to run it through the VMWare Player. In this case, we want to run it on boot.

Go to System-->Preferences-->Sessions
Add the following job to load on boot:
vmplayer /path/to/machine/machine-name.vmx

3. For security purposes, we want to lock the desktop after an auto-login. In Sessions, add another entry with the following:

gnome-screensaver-command --lock

4. Finally, we need an auto-login, because for security purposes you cannot generate an X-environment without one. If this is a problem, you will need to use VMWare Server - and at the time of this message, you will need to forget about 8.04 unless you are a very advanced linux user. There is a lot of hacking involved (trust me, I just did it) and a lot more that can go wrong.

Go to: System-->Administration-->Login Window
Click on the "Security" tab
Select "Enable Auto-Login"
Choose the appropriate user (the one with the jobs on boot)
Go to: System-->Preferences-->Screensaver
Ensure that "Lock screen when screensaver is active" is checked


Reboot your computer. It should auto-login and immediately lock the desktop into your default screensaver.

Wait 40 seconds or so, just for fun, then enter your password. Your VMware Workstation should be booted.

As a final note, if you prefer VMWare Workstation to the VMWare Player, the launch command would be:
vmrun start /path/to/machine/machine-name.vmx

Cheers, and thanks for all the help LinuxNtwrkng. I just wanted the easiest possible GUI solution in here for future readers.
Be sure to scroll to the bottom of this message for full GUI based Ubuntu 8.04 instructions on this question. I went out of my way to follow LinuxNtwrkng's suggestion to its logical conclusion.
I completely understand and applaud your wanting to document your procedure for others to be able to follow.  However, I think you missed the whole point of why I posted the crontab entry.  By adding that entry to whatever user's crontab that you want VMWare to run under you negate the entire process of having to setup an auto-login, locking screensaver, etc.  You get the functionality you wanted, without the security compromise that you didn't want, in other words.

There are GUI tools out there to edit a user's crontab, but quite honestly, in this instance, I think it's more trouble to download, install and use one of those than to simply open a terminal window (Accessories>Terminal) while logged in under the user you want VMWare to start as, type "crontab -e", enter "@reboot  /usr/bin/vmware-cmd "/path/to/my.vmx" start", save and exit the file.

Regardless of which way you choose to use, I'm glad I was able to help you get to the destination you desired.
Hmm, interesting. I didn't know a crontab could do that. I was definitely under the impression that you couldn't start a windowed process in the X environment without a login - and thus would need VMware Server, which runs the process as a script.

I'll try it on my dev machine when I get a free minute. Right now I'm having fun with fakeraid/sata raid and Ubuntu... ugh... headache.