Autostart VM on debian 7.7 virtualbox 4.3.20

Discussions related to using VirtualBox on Linux hosts.

Autostart VM on debian 7.7 virtualbox 4.3.20

Postby PavloM » 18. Dec 2014, 12:00

Hello.

I want to autostart virtual machine when system boot (but It seems like autostart possible only after host login. Is it true?). I used manuals:
{oops It is my first post so links not allowed, I left here only virtualbox manual}

9.23.1. Linux: starting the autostart service via init

All of them give same idea. I make all steps, but unfortunately, after reboot and login I do not see my virtual machine started in gnome environment.

I use VirtualBox 4.3.20 r96996 amd64 on Debian 7.7 (64) host. But I work with this machine and cannot reboot it too often. So I create virtual machine with debian 7.7 (its name Java, guest additions installed) and install virtualbox on it. I create vm with name TEST and not install anything on it. Just want to see it started in vm window.

May be I miss somewhere... because I much more comfortable with windows, but the last time I have some tasks, where linux seems good. Now the question how to make it work?
Attachments
Logs.zip
(47.86 KiB) Downloaded 149 times
PavloM
 
Posts: 21
Joined: 18. Dec 2014, 10:56

Re: Autostart VM on debian 7.7 virtualbox 4.3.20

Postby mpack » 18. Dec 2014, 12:17

"Linux Guests" is not an appropriate forum for your question, which is about how to start a host application. Moved to "Linux Hosts".
mpack
Site Moderator
 
Posts: 32281
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Autostart VM on debian 7.7 virtualbox 4.3.20

Postby lnunes_pt » 19. Dec 2014, 02:40

Hi PavloM,

The answer to the first question is, NO, you need not login to host. But also, NO, you need not reboot host to test VMs starts.
The manual section 9.23.1 is not complete. Don't use vbox.cfg for the configuration file name, otherwise setproperty autostartdbpath will lead to command syntax issues later.

Just to be sure you know, the VirtualBox autostart service init script is specially used in cases where you have many users on the host and want to control who can autostart VMs upon boot.
If your the only user on the host its alo just simpler start any headless VM from /etc/rc.local.

Edit /etc/default/virtualbox
Code: Select all   Expand viewCollapse view
VBOXAUTOSTART_DB=/etc/vbox
VBOXAUTOSTART_CONFIG=/etc/vbox/vboxautostart.cfg


Edit vboxautostart.cfg using Bob example how to deny all and allow bob:
Code: Select all   Expand viewCollapse view
default_policy = deny
bob = {
    allow = true
    startup_delay = 10
}


Create the vboxautostart.cfg file. Add vboxusers group to /etc/vbox and sticky bit.
Code: Select all   Expand viewCollapse view
# chgrp vboxusers /etc/vbox
# chmod 1775 /etc/vbox


Add vboxusers group to all users (of course).

Then Execute once as users:
Code: Select all   Expand viewCollapse view
$ VBoxManage setproperty autostartdbpath /etc/vbox


And for every VM to start, then you find under /etc/vbox, user.start file.
But also how it will stop, then you find under /etc/vbox, user.stop file.
Code: Select all   Expand viewCollapse view
$ VBoxManage modifyvm <vmname> --autostart-enabled on
$ VBoxManage modifyvm <vmname> --autostop-type acpishutdown


Then test START and STOP as root without need of host reboot.
Code: Select all   Expand viewCollapse view
# /etc/init.d/vboxautostart-service start

Logon to the VM and test the shutdown next. You should get logged off for system shutdown:
Code: Select all   Expand viewCollapse view
# /etc/init.d/vboxautostart-service stop


Note The Virtualbox autostart script should exist /etc/init.d/vboxautostart-service (it can be downloaded from Source Code Repository: trunk -> src -> VBox -> Installer -> linux -> vboxautostart-service.sh)

Have fun!
lnunes_pt
 
Posts: 22
Joined: 16. Nov 2014, 21:34
Location: Located at the other end of the network line
Primary OS: Linux other
VBox Version: PUEL
Guest OSses: Linux

Re: Autostart VM on debian 7.7 virtualbox 4.3.20

Postby PavloM » 19. Dec 2014, 13:28

Thank you for help.

Yes, I don't mention that I already changed vbox.cfg file name to autostart.conf

And I tried it in different ways e.g.:
Code: Select all   Expand viewCollapse view
default_policy = allow #and comment other lines.


and also reconfigure it in /etc/default/virtualbox. So now it contains this:
Code: Select all   Expand viewCollapse view
# virtualbox defaults file
VBOXAUTOSTART_DB=/etc/vbox
VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.conf


About /etc/rc.local I don't know about this. I never used this file before, though I am one user on my PC, so it could be very useful option. May be I'll try it later, it seems catching.

But for now I would rather prefer to finish with manner I started.

As about all your further instructions, It seems like I done the same.

Just for test:
p@pavel-j:~$ groups p
p : p cdrom floppy audio dip video plugdev scanner bluetooth netdev vboxusers


Also I checked for /etc/init.d/vboxautostart-service. It present in this place. I not remember that install this separately, but it already appear.

Now I tried to
# /etc/init.d/vboxautostart-service start
Starting VirtualBox VMs configured for autostartroot@pavel-j:/#


This I copy from "root" terminal, that I started from Gnome under user "p" ("p" is my login name for short). But nothing appears in gnome. I think this behavior should be because I run

VBoxManage modifyvm <vmname> --autostart-enabled on

Under user p terminal window (Also I start it in gnome environment under p). Am I right here? May be this start VM in headless or just not appear in gnome?

Or may be VM not start at all? Is it possible to see somehow what VMs are running now?
PavloM
 
Posts: 21
Joined: 18. Dec 2014, 10:56

Re: Autostart VM on debian 7.7 virtualbox 4.3.20

Postby lnunes_pt » 20. Dec 2014, 12:43

It won't start as GNOME or any GUI, it will (should) start a headless VM, in background.

I went and did it from my linux host (ols001), at boot it starts ols020 (my DNS server for all VMs).
Small output from my /var/log/boot.log:
Code: Select all   Expand viewCollapse view
Loading autofs4:                                           [  OK  ]
Starting automount:                                        [  OK  ]
Starting VirtualBox VMs configured for autostartStarting mcelog daemon
Starting sshd:                                             [  OK  ]
Starting xinetd:                                           [  OK  ]
Starting abrt daemon:                                      [  OK  ]


You'll find it in background, not in any GUI:
Code: Select all   Expand viewCollapse view
[oracle@ols001 ~]$ ps -eaf|grep VBoxHeadless
oracle    2643  2390 11 10:19 ?        00:00:47 /usr/lib/virtualbox/VBoxHeadless --comment ols020 --startvm f5f57756-c00c-484a-92d1-24f14b04317a --vrde config
My user is oracle (very original :P ) because of my work

Then I can restart it any time, and this simulates what you tried:
Code: Select all   Expand viewCollapse view
Usage: /etc/init.d/vboxautostart-service {start|stop}

[root@ols001]# /etc/init.d/vboxautostart-service stop
[root@ols001]# /etc/init.d/vboxautostart-service start
Starting VirtualBox VMs configured for autostart[root@ols001 oracle]#



I see, you shown "p" short name and its groups, but your autostart doesn't show any user "root@pavel-j <user>"!! Check instructions again.
Code: Select all   Expand viewCollapse view
# /etc/init.d/vboxautostart-service start
Starting VirtualBox VMs configured for autostartroot@pavel-j:/#


Please output what you have below, if there is a "<user>.start". If you had enabled auto stop too, then you should see "<user>.stop".
This is from my user "oracle":
Code: Select all   Expand viewCollapse view
# ls -l /etc/vbox/
total 12
-rw------- 1 oracle oracle   1 Dez 19 00:09 oracle.start
-rw------- 1 oracle oracle   1 Dez 19 00:32 oracle.stop
-rw-r--r-- 1 root   root   180 Dez 18 23:59 vboxautostart.cfg


BTW, my Vbox version is 4.3.18 just to mention yours 4.3.20 should be fine (I'm too chicken to upgrade to 4.3.20 just yet 8)
lnunes_pt
 
Posts: 22
Joined: 16. Nov 2014, 21:34
Location: Located at the other end of the network line
Primary OS: Linux other
VBox Version: PUEL
Guest OSses: Linux

Re: Autostart VM on debian 7.7 virtualbox 4.3.20

Postby PavloM » 23. Dec 2014, 13:40

Here:

Code: Select all   Expand viewCollapse view
root@pavel-j:/home/p#  ps -eaf|grep VBoxHeadless
p         6213  6201  6 Dec19 ?        06:00:01 /usr/lib/virtualbox/VBoxHeadless --comment TEST --startvm a9ea4364-9bdd-4e2a-bc6a-40be7d70e1d5 --vrde config
root     12813  6176  0 09:41 pts/3    00:00:00 grep VBoxHeadless


user p, VM name - TEST. It seems like it running now. Right?

And here p.stop and p.start both exist.

Code: Select all   Expand viewCollapse view
root@pavel-j:/home/p# ls -l /etc/vbox/
total 28
-rw-rw-r-- 1 root vboxusers 238 Dec 18 11:13 autostart.conf
-rw-r--r-- 1 root root      242 Dec 18 09:59 autostart.conf~
-rw------- 1 p    p           1 Dec 16 15:46 p.start
-rw------- 1 p    p           1 Dec 16 16:11 p.stop
-rwxrwxrwx 1 root root      172 Dec 16 15:32 vbox_autostart.cfg
-rwxrwxrwx 1 root root      175 Dec 16 15:31 vbox_autostart.cfg~
-rwxrwxrwx 1 root root      175 Dec 16 15:10 vbox.cfg~


Should I find way to connect headless VM now?
PavloM
 
Posts: 21
Joined: 18. Dec 2014, 10:56

Re: Autostart VM on debian 7.7 virtualbox 4.3.20

Postby PavloM » 25. Dec 2014, 13:40

lnunes_pt

Thank you for help once more!

My TEST VM was already started! I begin to read chapter 7 https://www.virtualbox.org/manual/ch07.html, and surprisingly point my view to Manager Window and see that my TEST VM is "Running". I stopped it and reboot. Open VBox manager - TEST VM is running :) once more. Also I tried RDP client (mstsc) and it works! And you are absolutely right about it starts even before login (I checked it also ;) ).

My most mistake was that I was waiting for some GUI window with VM or any message.

Great thanks to VirtualBox team for VRDP feature!
PavloM
 
Posts: 21
Joined: 18. Dec 2014, 10:56


Return to VirtualBox on Linux Hosts

Who is online

Users browsing this forum: No registered users and 17 guests