LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   VirtualBox autostart guest at boot (https://www.linuxquestions.org/questions/linux-newbie-8/virtualbox-autostart-guest-at-boot-4175596061/)

ddenial 12-24-2016 09:41 AM

VirtualBox autostart guest at boot
 
Hi

My host OS is Ubuntu 16.10, and I want to auto-start CentOS Virtualbox guest at boot and auto-shutdown at poweroff. The guest OS is called cent.

I followed this tutorial Autostarting VirtualBox Virtual Machines

The only change I made from above tutorial is that I created a service unit file against initd startup method as mentioned in tutorial.

This is my service unit file:
Code:

$ ls -l /etc/systemd/system/vbox.service
lrwxrwxrwx 1 root root 34 Dec 24 19:46 /etc/systemd/system/vbox.service -> /usr/lib/systemd/user/vbox.service

$ cat /etc/systemd/system/vbox.service
[Unit]
Description=VBox Virtual Machine cent Service

[Service]
Type=simple
User=ddenial
Group=vboxusers
ExecStart=/usr/bin/VBoxManage startvm cent --type headless
ExecStop=/usr/bin/VBoxManage controlvm cent acpipowerbutton

[Install]
WantedBy=multi-user.target

When I start the service, cent virtualbox guest start correctly. This is status of service.
Code:

$ sudo systemctl start vbox.service
$ sudo systemctl status vbox.service
● vbox.service - VBox Virtual Machine cent Service
  Loaded: loaded (/usr/lib/systemd/user/vbox.service; enabled; vendor preset: enabled)
  Active: inactive (dead) since Sat 2016-12-24 20:51:40 IST; 3min 55s ago
  Process: 3060 ExecStop=/usr/bin/VBoxManage controlvm cent acpipowerbutton (code=exited, status=0/SUCCESS)
  Process: 3013 ExecStart=/usr/bin/VBoxManage startvm cent --type headless (code=exited, status=0/SUCCESS)
 Main PID: 3013 (code=exited, status=0/SUCCESS)

Dec 24 20:51:39 ubu systemd[1]: Started VBox Virtual Machine cent Service.

If I try to stop the service though, the guest wont shutdown. The following is status after service is stopped.
Code:

$ sudo systemctl stop vbox.service
$ sudo systemctl status vbox.service
● vbox.service - VBox Virtual Machine cent Service
  Loaded: loaded (/usr/lib/systemd/user/vbox.service; enabled; vendor preset: enabled)
  Active: inactive (dead) since Sat 2016-12-24 20:51:40 IST; 11min ago
  Process: 3060 ExecStop=/usr/bin/VBoxManage controlvm cent acpipowerbutton (code=exited, status=0/SUCCESS)
  Process: 3013 ExecStart=/usr/bin/VBoxManage startvm cent --type headless (code=exited, status=0/SUCCESS)
 Main PID: 3013 (code=exited, status=0/SUCCESS)

Dec 24 20:51:39 ubu systemd[1]: Started VBox Virtual Machine cent Service.

I have also enabled the service to start at boot. It wont work either, ie., guest cent Os wont start at Ubuntu host boot.
Code:

$ sudo systemctl enable vbox.service
What I'm doing wrong? Please help.

Thanks

Ztcoracat 12-24-2016 01:53 PM

I'm honestly not sure what's wrong nor am I good with systemd; but these links might help.

https://www.marki-online.net/myblog/...s-for-systemd/

http://www.ericerfanian.com/automati...using-systemd/

Systemd Tips and Tricks
https://www.google.com/search?biw=13...k1.2hB01YdBwg0

ddenial 12-25-2016 03:54 AM

Quote:

Originally Posted by Ztcoracat (Post 5645958)

The solution from the second link worked out very well.

Thanks

Ztcoracat 12-25-2016 09:44 AM

Quote:

Originally Posted by ddenial (Post 5646096)
The solution from the second link worked out very well.

Thanks

That's great! Glad to hear the good news!

Merry Christmas:)

(if you celebrate it)

ddenial 12-25-2016 09:56 AM

Quote:

Originally Posted by Ztcoracat (Post 5646142)
That's great! Glad to hear the good news!

Merry Christmas:)

(if you celebrate it)

I'm a Hindu married to a Christian girl. Yes I'm celebrating Christmas. Merry Christmas to you too. 🎄

Thanks

Ztcoracat 12-25-2016 10:12 AM

Quote:

Originally Posted by ddenial (Post 5646148)
I'm a Hindu married to a Christian girl. Yes I'm celebrating Christmas. Merry Christmas to you too. 🎄

Thanks

You're Welcome!
Thanks and have a great day!


All times are GMT -5. The time now is 01:09 AM.