0

How should I go about setting up a system where once a user login occurs a Virtual Machine would start seamlessly (or without direct user input).

I run Ubuntu, but I would like to set up a guest account which would go directly into Windows.

I know a dual boot machine is possible but I would like to find a method that doesn't require a full reboot.

I'm still fairly new to the intricacies of linux and VM's.

  • The actual command depends on the VM engine you choose but a VM can certainly be opened from inside a script. – Julie Pelletier Aug 13 '16 at 5:33
  • Out of curiosity - why do you want to do this? – Thorbjørn Ravn Andersen Aug 13 '16 at 7:55
  • I use Ubuntu on a desktop. My girlfriend is Windows only. I was thinking about changing her account so that it would go directly into a windows virtual machine. She mostly uses Google services and firefox so it's unnecessary. But I was curious how to set it that up. – Khonrad Eckert Aug 15 '16 at 20:15
1

If you add the start command for your virtual machine to /home/<username>/.profile, then this command will be executed (once) when the user with name <username> logs in.

For VirtualBox:

VBoxManage startvm "<machinename>"

You can add options to run it full screen (e.g. VBoxSDL -vm "Windows XP" -fullscreen).

If the user exist the VM, she will end up in Linux though.

If you also want to log out the user when VirtualBox ends, do the following in Gnome (or Unity):

Create a file called runvm and make it executable:

$ touch runvm
$ chmod u+x runvm

Open an editor and add the following lines:

VBoxManage startvm "<machinename>"
sleep 1
while pgrep VirtualBox > /dev/null; do sleep 1; done
kill -9 -1

Save the file.

Note: You can get the "" by starting the VM and running:

$ VBoxManage list vms

You can test this by calling runvm & and then shutting down the VM once it has started. The user is forcefully logged off and the system returns to the logon prompt.

When this works, add this as the last line in your .profile file:

nohup $HOME/runvm &

Quick edit of your .profile file:

$ echo "nohup $HOME/runvm &" >> .profile

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.