Loading VM script from systemd at startup not working

Discussions related to using VirtualBox on Linux hosts.

Loading VM script from systemd at startup not working

Postby JoseManuelLasJim » 19. Oct 2021, 15:08

Hi all

I have a script on home called startvm.sh:

Code: Select all   Expand viewCollapse view
#!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   Expand viewCollapse view
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
JoseManuelLasJim
 
Posts: 13
Joined: 27. Mar 2020, 12:37

Re: Loading VM script from systemd at startup not working

Postby scottgus1 » 19. Oct 2021, 16:40

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.
scottgus1
Site Moderator
 
Posts: 13831
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

Postby JoseManuelLasJim » 20. Oct 2021, 10:17

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   Expand viewCollapse view
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: 13
Joined: 27. Mar 2020, 12:37

Re: Loading VM script from systemd at startup not working

Postby JoseManuelLasJim » 20. Oct 2021, 11:23

I managed to do it following this little guide i found

https://www.pragmaticlinux.com/2020/10/ ... h-systemd/
JoseManuelLasJim
 
Posts: 13
Joined: 27. Mar 2020, 12:37

Re: Loading VM script from systemd at startup not working

Postby scottgus1 » 20. Oct 2021, 17:20

Great! Glad you're up and running.
scottgus1
Site Moderator
 
Posts: 13831
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux


Return to VirtualBox on Linux Hosts

Who is online

Users browsing this forum: No registered users and 27 guests