Virtualbox, run at reboot

Discussion in 'The Pub (Off topic discussion)' started by drmike, Aug 25, 2013.

  1. drmike

    drmike 100% Tier-1 Gogent

    8,573
    2,717
    May 13, 2013
    Someone a ways back pointed me at Virtualbox on here.  Using it for a few virtual containers mainly for appliances and VPS-like use locally.

    Little problem I have now is sustaining reboots.   Need Virtualbox to launch the instances on system reboot.

    Anyone know/use/familiar with how to accomplish this even if it a commandline I can fire off via CRON?
     
  2. hcjake

    hcjake New Member

    21
    3
    Aug 11, 2013
    drmike likes this.
  3. drmike

    drmike 100% Tier-1 Gogent

    8,573
    2,717
    May 13, 2013
    Arrgh! VBoxManager likes to vomit and complain at first attempt:

    The fix for that:


    VBoxManage registervm /home/user/VirtualBox\ VMs/deleteme/deleteme.vbox
    Then try again:


    VBoxManage startvm deleteme


    Now we get:

    Hey it works!

    Time to shove that in CRON to spawn at reboot.

    Thanks @hcjake for impressing upon me the commandline tool.  Ran into same bugs before, but knowing right tool made me press on to resolve matter.
     
  4. drmike

    drmike 100% Tier-1 Gogent

    8,573
    2,717
    May 13, 2013
    BTW: same registervm step seems to be need for for every container you have.    A little annoying, but I can deal with it :)
     
  5. peterw

    peterw New Member

    800
    189
    Jun 14, 2013
    I use this script for it

    Code:
    #!/bin/bash
    
    ### BEGIN INIT INFO
    # Provides: virtualboxstarter
    # Required-Start: vboxweb-service
    # Required-Stop: vboxweb-service
    # Default-Start: 2 3 4 5
    # Default-Stop:
    # Short-Description: Starter for virtual box
    ### END INIT INFO
    
    set -e
    
    VBOXMANAGE=/usr/bin/VBoxManage
    FIND=/usr/bin/find
    SU=/bin/su
    PRINTF=/usr/bin/printf
    
    VBOXUSER=vbox
    VMDIR=/export/vbox-vms
    VMS_TO_START=(Windows Debian Test)
    
    export -n DISPLAY
    umask 022
    . /lib/lsb/init-functions
    
    if [[ "$UID" -ne 0 ]]; then
    echo 'Run as root!'
    exit 1
    fi
    
    case "$1" in
      start)
    log_daemon_msg "Starting virtual boxes"
    VMLIST="$($PRINTF " '%s'" "${VMS_TO_START[@]}")"
    $SU "$VBOXUSER" -s /bin/bash <<EOF
    $FIND "$VMDIR" -type f -name '*.vbox' \
    -exec $VBOXMANAGE registervm '{}' ';' > /dev/null 2>&1
    for VM in $VMLIST; do
    $VBOXMANAGE startvm "\$VM" --type headless
    done
    EOF
    log_end_msg 0
    ;;
      stop)
    
    ;;
    
      status)
    ;;
    
      *)
    log_action_msg "Usage: $0 {start|stop|status}"
    exit 1
    esac
    
    exit 0
    
     
    drmike likes this.