Autostart does not work on boot Ubuntu 16.04 VirtualBox 5.1

Discussions related to using VirtualBox on Linux hosts.
Post Reply
Oddly Vague
Posts: 12
Joined: 7. Sep 2016, 19:59

Autostart does not work on boot Ubuntu 16.04 VirtualBox 5.1

Post by Oddly Vague »

I have a fresh install of Ubuntu 16.04 Server and VirtualBox 5.1. I have an Ubuntu guest created on an NFS mount with the storage attached to an iSCSI LUN on my NAS. Starting and stopping it manually works fine.

Manually starting the guest works via any one of these commands:
  • VBoxHeadless --startvm "Ubuntu Server"
    sudo service vboxautostart-service restart
    vboxautostart --start --config /etc/vbox/autostart.cfg
It does not start up at boot. I believe the issue is the VirtualBox services are starting prior to dependent services. In particular, NFS mounting and iSCSI initiator daemon. The /etc/init.d does not have the vboxdrv and vboxautostart-service files, but the rc.d folders do have S02vboxdrv and S03vboxautostart-service in the appropriate places.

I'm guessing here... do I need to rename them to S04 and S05 respectively? At the least, I think S03vboxautostart-service needs to start much later. Thoughts on this?

Snippets of the syslog

Code: Select all

Sep  7 15:12:03 MyHost systemd[1]: Starting Authenticate and Authorize Users to Run Privileged Tasks...
Sep  7 15:12:03 MyHost vboxdrv.sh[2811]: vboxdrv.sh: Starting VirtualBox services.
...
Sep  7 15:12:03 MyHost vboxdrv.sh: Starting VirtualBox services.
...
Sep  7 15:12:03 MyHost kernel: [   14.354340] vboxdrv: module verification failed: signature and/or required key missing - tainting kernel
Sep  7 15:12:03 MyHost kernel: [   14.359014] vboxdrv: Found 4 processor cores
...
Sep  7 15:12:03 MyHost kernel: [   14.378254] vboxdrv: TSC mode is Invariant, tentative frequency 1596300487 Hz
Sep  7 15:12:03 MyHost kernel: [   14.378258] vboxdrv: Successfully loaded version 5.1.4 (interface 0x00260000)
...
Sep  7 15:12:04 MyHost kernel: [   14.582075] VBoxNetFlt: Successfully started.
Sep  7 15:12:04 MyHost kernel: [   14.583189] VBoxNetAdp: Successfully started.
Sep  7 15:12:04 MyHost kernel: [   14.584579] VBoxPciLinuxInit
Sep  7 15:12:04 MyHost vboxdrv.sh: VirtualBox services started.
Sep  7 15:12:04 MyHost kernel: [   14.586318] vboxpci: IOMMU not found (not registered)
Sep  7 15:12:04 MyHost systemd[1]: Started VirtualBox Linux kernel module.
Sep  7 15:12:04 MyHost systemd[1]: Starting vboxautostart-service.service...
Sep  7 15:12:04 MyHost systemd[1]: Starting vboxballoonctrl-service.service...
Sep  7 15:12:04 MyHost vboxautostart-service.sh[3023]: vboxautostart-service.sh: Starting VirtualBox VMs configured for autostart.
Sep  7 15:12:04 MyHost vboxautostart-service.sh: Starting VirtualBox VMs configured for autostart.
Sep  7 15:12:04 MyHost systemd[1]: Starting vboxweb-service.service...
Sep  7 15:12:04 MyHost systemd[1]: Started vboxballoonctrl-service.service.
Sep  7 15:12:04 MyHost systemd[1]: Started vboxweb-service.service.
Sep  7 15:12:04 MyHost systemd[1]: Started vboxautostart-service.service.
...
Sep  7 15:12:10 MyHost systemd[1]: Starting iSCSI initiator daemon (iscsid)...
Sep  7 15:12:10 MyHost systemd[1]: Starting OpenBSD Secure Shell server...
Sep  7 15:12:10 MyHost systemd[1]: Started /etc/rc.local Compatibility.
Sep  7 15:12:10 MyHost iscsid: iSCSI logger with pid=3172 started!
Sep  7 15:12:10 MyHost systemd[1]: Started iSCSI initiator daemon (iscsid).
Sep  7 15:12:10 MyHost systemd[1]: Starting Login to default iSCSI targets...
Sep  7 15:12:10 MyHost iscsiadm[3180]: iscsiadm: No records found
Sep  7 15:12:10 MyHost systemd[1]: Started OpenBSD Secure Shell server.
Sep  7 15:12:10 MyHost systemd[1]: Started Login to default iSCSI targets.
Sep  7 15:12:10 MyHost systemd[1]: Reached target Remote File Systems (Pre).
Sep  7 15:12:10 MyHost systemd[1]: Mounting /mnt/nfs/myNas...
Sep  7 15:12:10 MyHost kernel: [   21.235486] FS-Cache: Loaded
Sep  7 15:12:10 MyHost kernel: [   21.247575] FS-Cache: Netfs 'nfs' registered for caching
Sep  7 15:12:10 MyHost kernel: [   21.258497] NFS: Registering the id_resolver key type
Sep  7 15:12:10 MyHost kernel: [   21.258505] Key type id_resolver registered
Sep  7 15:12:10 MyHost kernel: [   21.258506] Key type id_legacy registered
Sep  7 15:12:10 MyHost systemd[1]: Mounted /mnt/nfs/myNas.

--- potentially useful information ----
I moved the default machine folder to a mount:

Code: Select all

vboxmanage list systemproperties | grep "machine folder"
Default machine folder:          /mnt/nfs/myNas/virtualbox/vm-user
/etc/default/virtualbox

Code: Select all

# virtualbox defaults file
VBOXAUTOSTART_DB=/etc/vbox
VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg

SHUTDOWN_USERS="vm-user"
SHUTDOWN=acpibutton
/etc/vbox

Code: Select all

sudo chgrp vboxusers /etc/vbox
sudo chmod 1775 /etc/vbox

ls -ld /etc/vbox/
drwxrwxr-t 2 root vboxusers 4096 Sep  7 10:43 /etc/vbox/

VBoxManage modifyvm "Ubuntu Server" --autostart-enabled on
VBoxManage modifyvm "Ubuntu Server" --autostop-type acpishutdown

ls -l /etc/vbox/
total 12
-rw-r--r-- 1 root  root  176 Sep  7 09:45 autostart.cfg
-rw------- 1 vm-user vm-user   1 Sep  7 10:43 vm-user.start
-rw------- 1 vm-user vm-user   1 Sep  7 10:43 vm-user.stop
/etc/vbox/autostart.cfg

Code: Select all

# Default policy is to deny starting a VM, the other option is "allow".
Default_policy = deny
# Create an entry for each user allowed to run autostart
vm-user = {
allow = true
}
systemctl -l status vboxautostart-service.service

Code: Select all

● vboxautostart-service.service
   Loaded: loaded (/usr/lib/virtualbox/vboxautostart-service.sh; enabled; vendor preset: enabled)
   Active: active (exited) since Wed 2016-09-07 15:12:04 EDT; 1min 6s ago
  Process: 3023 ExecStart=/usr/lib/virtualbox/vboxautostart-service.sh start (code=exited, status=0/SUCCESS)
    Tasks: 0
   Memory: 0B
      CPU: 0

Sep 07 15:12:04 MyHost systemd[1]: Starting vboxautostart-service.service...
Sep 07 15:12:04 MyHost vboxautostart-service.sh[3023]: vboxautostart-service.sh: Starting VirtualBox VMs configured for autostart.
Sep 07 15:12:04 MyHost vboxautostart-service.sh[3028]: Starting VirtualBox VMs configured for autostart.
Sep 07 15:12:04 MyHost systemd[1]: Started vboxautostart-service.service.
Last edited by Oddly Vague on 8. Sep 2016, 02:09, edited 1 time in total.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Autostart does not work on boot Ubuntu 16.04 VirtualBox 5.1

Post by Perryg »

You can test if this is a timing issue by adding a pause statement to the /etc/default/virtualbox at the top and see if it allows it to proceed ( I believe a pause of 10 should be enough ). If so then perhaps it is time to raise a ticket at bugtracker.
Oddly Vague
Posts: 12
Joined: 7. Sep 2016, 19:59

Re: Autostart does not work on boot Ubuntu 16.04 VirtualBox 5.1

Post by Oddly Vague »

Thanks Perryg for the quick response. I wanted to research before I asked how to do that, but the answer didn't bite me. I tried the manual, forums, and, not extensively, the source.

I believe I saw that an option existed at one time for VBOXAUTOSTART_STOP_DELAY, so I tried
  • VBOXAUTOSTART_START_DELAY=10
    VBOXAUTOSTART_DELAY=10
    START_DELAY=10
    DELAY=10
I'm assuming I got it wrong since the VM didn't start and I didn't see any error messages. How do I put a pause in the /etc/default/virtualbox?

Thank you!
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Autostart does not work on boot Ubuntu 16.04 VirtualBox 5.1

Post by Perryg »

Put "sleep 10" at the top. Remember this is just a test not a fix. It will give you and us a starting point.
Oddly Vague
Posts: 12
Joined: 7. Sep 2016, 19:59

Re: Autostart does not work on boot Ubuntu 16.04 VirtualBox 5.1

Post by Oddly Vague »

Boom! I have a running VM at startup.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Autostart does not work on boot Ubuntu 16.04 VirtualBox 5.1

Post by Perryg »

OK so now you need to post a ticket at bugtracker posting what you needed to do to allow it to boot.
Oddly Vague
Posts: 12
Joined: 7. Sep 2016, 19:59

Re: Autostart does not work on boot Ubuntu 16.04 VirtualBox 5.1

Post by Oddly Vague »

Sure. I didn't have time last night. I created one today: Ticket 15908

Thank you for your help Perryg.
Last edited by Perryg on 8. Sep 2016, 15:09, edited 1 time in total.
Reason: Added link to ticket number
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Autostart does not work on boot Ubuntu 16.04 VirtualBox 5.1

Post by Perryg »

You're welcome.
With all of the Linux distros trying to get a faster boot time then the other it happens from time to time. I usually find it easier to just deal with it myself with manually working around these timing issues because its just too hard for the DEVs to keep track of the bouncing ball, if you know what I mean.
Oddly Vague
Posts: 12
Joined: 7. Sep 2016, 19:59

Re: Autostart does not work on boot Ubuntu 16.04 VirtualBox 5.1

Post by Oddly Vague »

I've had time to tinker again today and found that the NFS umounting and iSCSI stopping is happening before the VirtualBox shutdown. I'm assuming the VM guest is left without a virtual disk while attempting to shutdown.

Any advice to work around this issue?
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Autostart does not work on boot Ubuntu 16.04 VirtualBox 5.1

Post by Perryg »

Not sure. I would think that you could look at the mount statement you use and see if a script would work better or change the mount in some way.
Oddly Vague
Posts: 12
Joined: 7. Sep 2016, 19:59

Re: Autostart does not work on boot Ubuntu 16.04 VirtualBox 5.1

Post by Oddly Vague »

Whoa! A huge, gigantic, monstrous fact I didn't realize until investigating this boot order issue. Ubuntu defaults to systemd starting at 15.04. My last version experience prior to 16, was 14. Systemd blew my mind for a while which is why my init.d sh had no affect and somewhere along the line I magically installed the S0# files in the rc#.d folders. I think I know enough about systemd now to be dangerous as well as fix my problem.

I had the luxury of wiping my install and starting over. So now with systemd in mind, I can say that VirtualBox installs the appropriate .service files in the /lib/systemd/system folder and it starts as it should if the vbox configuration is local and the VM is using a locally stored virtual disk. However, if like me, the vbox configuration is stored on an NFS mount and the VM is using an iSCSI LUN, then the vboxdrv.service does not now that the NFS mount and iscsid services are required. I created vboxdrv.service override for the Required and After directives and everything seems to be peachy keen so far.

I posted more detailed steps on a blog.

http://geekthingsathome.blogspot.com/20 ... y-and.html

It would be nice that these dependencies are set as default, but I do not know the affects on the community. I updated the ticket.
Post Reply