Author Topic: How to Auto run Virtual Box VM automatically -SOLVED  (Read 1369 times)

0 Members and 1 Guest are viewing this topic.

Offline rajeev2631007

  • Member
  • ***
  • Posts: 234
  • Karma: 24
  • New Forum User
    • View Profile
How to Auto run Virtual Box VM automatically -SOLVED
« on: September 27, 2017, 08:22:24 am »
Hi,

I want to autorun virtual box VM automatically. I had googled this and found.
Code: [Select]
VBoxManage startvm "Zentyal" -type headless
When I tried this in terminal, It's works there. But When I had added above command in autostart option and restart Linux.
Code: [Select]
Peppermint-Setting-Panel-->System-->LxSession Configuration-->autostart-->Add Manual autostarted application
But it is not working with autostart option.

Please suggest me solution.

Regards,
Rajeev Gautam
« Last Edit: October 11, 2017, 01:00:17 pm by rajeev2631007 »

Offline PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 26452
  • Karma: 65531
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 10
Re: How to Auto run Virtual Box VM automatically
« Reply #1 on: September 27, 2017, 10:44:46 am »
Autostart commands run from there are system wide so VBoxManage wouldn't know where to find the "Zentyal" vbox image.

So you'd think maybe adding the full path to the vbox would work, as in (something like):
Code: [Select]
VBoxManage startvm "/home/rajeev/VirtualBox VMs/Zentyal/Zentyal.vbox" -type headless
would work right ? .. well it doesn't (I'm guessing) because it doesn't know who to run VBoxManage as.

So the best way to autostart the vbox would probably be to autostart it from the "users" autostart folder.

Run:
Code: [Select]
pluma ~/.config/autostart/zentyal-vbox.desktop
When a blank file opens, make it read:-
Code: [Select]
[Desktop Entry]
Type=Application
Version=1.0
Name=Zentyal Virtaulbox
Comment=Autostart the Zentyal Virtualbox
Exec=VBoxManage startvm "Zentyal" -type headless
Icon=virtualbox
Terminal=false
SAVE the file, and exit the text editor.

Now test it by logging off/on again.

Thinking about it, if the vbox is going to rely on a wireless network to come up before the vbox, it might be necessary to build a delay into the autostart command that allows the wireless time to come up first, such as by making the "Exec=" line read say:-
Exec=sleep 10 ; VBoxManage startvm "Zentyal" -type headless



I'm assuming you realise the "-type headless" is going to stop the vbox GUI from being displayed locally ? .. it'll be running, but you won't see the vbox on screen.
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec

Offline rajeev2631007

  • Member
  • ***
  • Posts: 234
  • Karma: 24
  • New Forum User
    • View Profile
Re: How to Auto run Virtual Box VM automatically
« Reply #2 on: September 29, 2017, 01:28:57 pm »
Hi,

PCNetSpecs Thanks.
Quote
Run:
Code: [Select]

pluma ~/.config/autostart/zentyal-vbox.desktop

When a blank file opens, make it read:-
Code: [Select]

[Desktop Entry]
Type=Application
Version=1.0
Name=Zentyal Virtaulbox
Comment=Autostart the Zentyal Virtualbox
Exec=VBoxManage startvm -type headless
Icon=virtualbox
Terminal=false

SAVE the file, and exit the text editor.

Now test it by logging off/on again.

Above instrcutions works for me.I have one more question when I'll shutdown VirtualBox Host OS it will poweroff specifiy running VM before shutdown Host OS.

Code: [Select]
VBoxManage controlvm "Zentyal"  poweroff

Thanks again for your help.

Regards,

Rajeev Gautam


 


Offline PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 26452
  • Karma: 65531
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 10
Re: How to Auto run Virtual Box VM automatically
« Reply #3 on: September 29, 2017, 01:35:16 pm »
Are you asking how to run:
Code: [Select]
VBoxManage controlvm "Zentyal"  poweroff
if you shut down the PC using the normal shutdown procedure of clicking the logout button in the whiskerrmenu ? .. or do you use some other method of powering off your PC
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec

Offline rajeev2631007

  • Member
  • ***
  • Posts: 234
  • Karma: 24
  • New Forum User
    • View Profile
Re: How to Auto run Virtual Box VM automatically
« Reply #4 on: September 29, 2017, 01:57:04 pm »
Hi,

Quote
Are you asking how to run:
Code: [Select]

VBoxManage controlvm "Zentyal"  poweroff

if you shut down the PC using the normal shutdown procedure of clicking the logout button in the whiskerrmenu ? .. or do you use some other method of powering off your PC

I'm asking given below syntax should run automatically and poweroff VM when I shutdown Host OS. I mean given syntax run automatically and poweroff before shutdown Host OS.

Code: [Select]
VBoxManage controlvm "Zentyal"  poweroff

Regards,
Rajeev Gautam

Offline PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 26452
  • Karma: 65531
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 10
Re: How to Auto run Virtual Box VM automatically
« Reply #5 on: September 29, 2017, 02:53:49 pm »
Yeah but how do you normally shut down the host PC ?
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec

Offline rajeev2631007

  • Member
  • ***
  • Posts: 234
  • Karma: 24
  • New Forum User
    • View Profile
Re: How to Auto run Virtual Box VM automatically
« Reply #6 on: September 29, 2017, 03:16:00 pm »
Hi,

Quote
Yeah but how do you normally shut down the host PC ?

Click on Menu-->Logout-->Shutdown

Regards,

Rajeev Gautam

Offline PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 26452
  • Karma: 65531
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 10
Re: How to Auto run Virtual Box VM automatically
« Reply #7 on: September 30, 2017, 02:02:13 pm »
Okay I'll have a look at this tomorrow and see what I can come up with .. it should be easy to enough to create an rc.d init script to run at shutdown, but I need to test it and how:-

a) they work with systemd
and
b) if it somehow needs to be run as the user VBoxManage is running as
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec

Offline rajeev2631007

  • Member
  • ***
  • Posts: 234
  • Karma: 24
  • New Forum User
    • View Profile
Re: How to Auto run Virtual Box VM automatically
« Reply #8 on: October 11, 2017, 12:59:35 pm »
Hi,

Create vmstop.service file \etc\systemd\system\vmstop.service and copy given below code.


Code: [Select]
[Unit]
Description=Do something required
DefaultDependencies=no
Before=shutdown.target reboot.target halt.target
# This works because it is installed in the target and will be
#   executed before the target state is entered
# Also consider kexec.target

[Service]
Type=oneshot
ExecStart=/home/administrator/shutdown.sh  #your path and filename

[Install]
WantedBy=halt.target reboot.target shutdown.target

Enable this Service
Code: [Select]
systemctl enable vmstop.service

Code: [Select]
systemctl start vmstop.service

Code: [Select]
systemctl status vmstop.service

create bash script /home/administrator/shutdown.sh

Code: [Select]
#!/bin/bash
VBoxManage controlvm "Zentyal"  poweroff


Regards,

Rajeev Gautam

Offline PCNetSpec

  • Administrator
  • Hero
  • *****
  • Posts: 26452
  • Karma: 65531
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
  • Peppermint version(s): Peppermint 10
Re: How to Auto run Virtual Box VM automatically -SOLVED
« Reply #9 on: October 11, 2017, 03:46:36 pm »
Thanks for the solution rajeev, I completely lost this topic somewhere in the ether :-[
WARNING: You are logged into reality as 'root' .. logging in as 'insane' is the only safe option.

Team Peppermint
PCNetSpec