Loading VM script from systemd at startup not working

Discussions related to using VirtualBox on Linux hosts.
Post Reply
JoseManuelLasJim
Posts: 14
Joined: 27. Mar 2020, 12:37

Loading VM script from systemd at startup not working

Post by JoseManuelLasJim »

Hi all

I have a script on home called startvm.sh:

Code: Select all

#!bin/bash
#Inciamos el primer paso de la VM
echo "startvm";
VBoxManage startvm OmnitecOsaccess --type headless &
sleep 10;
#Iniciamos la VM encrpytada con la clave
echo "initencrypt";
VBoxManage controlvm "OmnitecOsaccess" addencpassword "OmnitecOsaccessDisc" /home/omnitec/claveDiscoRetama &
this script works well if i execute it manually with sh startvm.sh

But when i use my systemd service startvm.service:

Code: Select all

User=omnitec
Group=omnitec
# Type=simple
# PIDFile=/run/my-service.pid
RemainAfterExit=yes
ExecStart=/home/omnitec/startvm.sh
# ExecReload=/home/transang/startup.sh reload
# ExecStop=/home/transang/startup.sh stop
# TimeoutSec=30
# Restart=on-failure
# RestartSec=30
# StartLimitInterval=350
# StartLimitBurst=10

[Install]
WantedBy=multi-user.target
The logs gives me this -> journalctl -u startvm.service:

-- Logs begin at Tue 2021-10-19 12:55:47 UTC, end at Tue 2021-10-19 13:05:01 UTC. --
Oct 19 12:56:28 ubuntumvhost systemd[1]: Started Starts VPN.
Oct 19 12:56:28 ubuntumvhost startvm.sh[762]: startvm
Oct 19 12:56:28 ubuntumvhost startvm.sh[772]: WARNING: The character device /dev/vboxdrv does not exist.
Oct 19 12:56:28 ubuntumvhost startvm.sh[772]: Please install the virtualbox-dkms package and the appropriate
Oct 19 12:56:28 ubuntumvhost startvm.sh[772]: headers, most likely linux-headers-generic.
Oct 19 12:56:28 ubuntumvhost startvm.sh[772]: You will not be able to start VMs until this problem is fixed.
Oct 19 12:56:29 ubuntumvhost startvm.sh[764]: VBoxManage: error: The virtual machine 'OmnitecOsaccess' has terminated >
Oct 19 12:56:29 ubuntumvhost startvm.sh[764]: VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), componen>
Oct 19 12:56:29 ubuntumvhost startvm.sh[764]: Waiting for VM "OmnitecOsaccess" to power on...
Oct 19 12:56:38 ubuntumvhost startvm.sh[762]: initencrypt
Oct 19 12:56:39 ubuntumvhost startvm.sh[940]: VBoxManage: error: Machine 'OmnitecOsaccess' is not currently running

What am i doing wrong?

Thankyou
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Loading VM script from systemd at startup not working

Post by scottgus1 »

I'm not a Linux guru, but the error seems to say that Virtualbox may not be installed correctly for the account/permissions that the automatic-start script execution runs under.

Mention of dkms also seems to imply you're running a fork of Virtualbox, which we don't support here, instead of official Virtualbox from https://www.virtualbox.org/wiki/Linux_Downloads. Official Virtualbox does not use dkms.
JoseManuelLasJim
Posts: 14
Joined: 27. Mar 2020, 12:37

Re: Loading VM script from systemd at startup not working

Post by JoseManuelLasJim »

Hello scott, thank you for the fast reply

I uninstalled and installed again VBox from the link you sended

Now the logs gives me this -> journalctl -u startvm.service:

Code: Select all

Oct 20 08:07:27 ubuntumvhost startvm.sh[794]: 6.1.26r145957
Oct 20 08:07:27 ubuntumvhost startvm.sh[788]: startvm
Oct 20 08:07:27 ubuntumvhost startvm.sh[837]: WARNING: The vboxdrv kernel module is not loaded. Either there is no module
Oct 20 08:07:27 ubuntumvhost startvm.sh[837]:          available for the current kernel (5.4.0-88-generic) or it failed to
Oct 20 08:07:27 ubuntumvhost startvm.sh[837]:          load. Please recompile the kernel module and install it by
Oct 20 08:07:27 ubuntumvhost startvm.sh[837]:            sudo /sbin/vboxconfig
Oct 20 08:07:27 ubuntumvhost startvm.sh[837]:          You will not be able to start VMs until this problem is fixed.
Oct 20 08:07:28 ubuntumvhost startvm.sh[831]: VBoxManage: error: The virtual machine 'OmnitecOsaccess' has terminated unexpectedly during startup with exi>
Oct 20 08:07:28 ubuntumvhost startvm.sh[831]: VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine
Oct 20 08:07:28 ubuntumvhost startvm.sh[831]: Waiting for VM "OmnitecOsaccess" to power on...
Oct 20 08:07:57 ubuntumvhost startvm.sh[788]: initencrypt
Oct 20 08:07:57 ubuntumvhost startvm.sh[6020]: WARNING: The vboxdrv kernel module is not loaded. Either there is no module
Oct 20 08:07:57 ubuntumvhost startvm.sh[6020]:          available for the current kernel (5.4.0-88-generic) or it failed to
Oct 20 08:07:57 ubuntumvhost startvm.sh[6020]:          load. Please recompile the kernel module and install it by
Oct 20 08:07:57 ubuntumvhost startvm.sh[6020]:            sudo /sbin/vboxconfig
Oct 20 08:07:57 ubuntumvhost startvm.sh[6020]:          You will not be able to start VMs until this problem is fixed.
Oct 20 08:07:57 ubuntumvhost startvm.sh[6015]: VBoxManage: error: Machine 'OmnitecOsaccess' is not currently running
JoseManuelLasJim
Posts: 14
Joined: 27. Mar 2020, 12:37

Re: Loading VM script from systemd at startup not working

Post by JoseManuelLasJim »

I managed to do it following this little guide i found

https://www.pragmaticlinux.com/2020/10/ ... h-systemd/
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Loading VM script from systemd at startup not working

Post by scottgus1 »

Great! Glad you're up and running.
Post Reply