Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
27
rated 0 times [  27] [ 0]  / answers: 1 / hits: 60962  / 2 Years ago, fri, june 3, 2022, 1:44:42

I cannot seem to get my VM to run at startup.



I tried the "startup applications" and update-rc.d with no luck.



sudo update-rc.d startvms defaults 99 10


This created all the appropriate symbolic links for the different run levels but the VM still does not start.



Here's my startvms script:



#!/bin/bash
### BEGIN INIT INFO
# Provides: startvms
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start my VMs at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
case "$1" in
start)
echo "Starting"
nohup VBoxHeadless --startvm "UbuntuServer" &
;;
stop)
echo "Stopping $DESC"
VBoxManage controlvm "UbuntuServer" poweroff
;;

restart|force-reload)
echo "Restarting $DESC"
VBoxManage controlvm "UbuntuServer" poweroff
nohup VBoxHeadless --startvm "UbuntuServer" &
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|force-reload}" >&2
exit 1
;;
esac


What am i doing wrong?


More From » virtualbox

 Answers
4

THIS is what finally worked!



1) Create the startup script file



in /etc/init.d - sudo nano /etc/init.d/StartVM.



Copy Paste the following in the file and replace "My VM Name" for your vm name:



#! /bin/sh
# /etc/init.d/StartVM
#

#Edit these variables!
VMUSER=spode
VMNAME="My VM Name"

case "$1" in
start)
echo "Starting VirtualBox VM..."
sudo -H -b -u $VMUSER /usr/bin/VBoxVRDP -s "$VMNAME"
;;
stop)
echo "Saving state of Virtualbox VM..."
sudo -H -u $VMUSER /usr/bin/VBoxManage controlvm "$VMNAME" savestate
;;
*)
echo "Usage: /etc/init.d/StartVM {start|stop}"
exit 1
;;
esac

exit 0


2) Give the script executable permission



with sudo chmod +x /etc/init.d/StartVM.



3) Tell script to run at startup.



tell the script be the first to shutdown and the last to startup.



sudo update-rc.d StartVM defaults 99 01


[#43848] Friday, June 3, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
deringach

Total Points: 412
Total Questions: 107
Total Answers: 101

Location: Palestine
Member since Tue, Jul 20, 2021
3 Years ago
deringach questions
Sat, Oct 30, 21, 17:38, 3 Years ago
Fri, Oct 21, 22, 16:34, 2 Years ago
Tue, Feb 15, 22, 22:33, 2 Years ago
Tue, Feb 7, 23, 03:57, 1 Year ago
;