FedoraForum.org - Fedora Support Forums and Community
Page 1 of 7 1 2 3 ... LastLast
Results 1 to 15 of 96
  1. #1
    Join Date
    Mar 2004
    Location
    In your closet
    Posts
    15,643

    Oracle VirtualBox installation script

    There are many threads here detailing the troubles that Fedora users have installing VirtualBox. It shouldn't be that difficult, and it really isn't.

    My personal preference is to use the RPM from Oracle. It has worked extremely well for me for several years now.

    In an effort to help Fedora users install Oracle VirtualBox and the Oracle VirtualBox Extension Pack under Fedora 20 and 21, i686 and x86_64, I've written a bash script.

    I've spent about a week on this, testing and tweaking until the output and the results were just so. I've test run this script probably 100 times under Fedora 20 and 21 virtual machines and am completely confident in the results.

    Truth be told, the script will work for releases older than 20 too with a small change in the code.

    Give it a try if you wish. If you do, please let me know how it worked for you.

    Comments and suggestions always welcome. Just be nice

    PHP Code:
    #!/bin/bash
    # 21_oracle_virtualbox.sh
    # Install and configure the Oracle version of VirtualBox for Fedora 20 and later.
    # Install the Oracle VirtualBox Extension Pack.

    # Glenn A. Johnson
    # Started January 18, 2015
    # Updated January 24, 2015

    << COMMENT
    DNF 
    for Fedora 21 and upyum for earlier releases
    What 
    if Fedora version of VirtualBox is already installedfailed or notVirtualBox-4.3.20-3.fc20.x86_64 kmod-VirtualBox-3.17.7-200.fc20.x86_64-4.3.20-1.fc20.4.x86_64
    COMMENT

    # Variables
    # Additional packages usually needed for a successful install of VirtualBox
    packfiles="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 dkms wget SDL"

    # At some point, when Oracle releases an updated RPM, these variables will need to be changed.
    vbox_source_file="VirtualBox-4.3-4.3.20_96996_fedora18-1."`uname -m`".rpm"
    vbox_ext_source="Oracle_VM_VirtualBox_Extension_Pack-4.3.20-96996.vbox-extpack"

    # Need root permissions at some point, might as well do it now.
    if [[ $EUID -ne 0 ]] ; then
        clear
       
    echo -$(tput bold)$(tput setaf 7)"You're going to need root permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\""$(tput sgr0)
       exit 
    0
    fi

    # Release 20 and later only
    function get_release()
    {
        
    printf $(tput setaf 2)"Checking Fedora release version... "$(tput sgr0)
        
    rel_num=$(rpm -qa --queryformat '%{version}\n' fedora-release)
        if [[ 
    $rel_num "20" ]] ; then
            printf 
    $(tput setaf 1)"\nThis script is for Fedora release 20 and later only.\nThis appears to be Fedora $rel_num.\n"$(tput sgr0)
           exit 
    0
        
    else printf $(tput bold)$(tput setaf 2)" ✓"$(tput sgr0)
    fi
    echo
    }

    # Clear screen and print a banner
    function banner()
    {
        
    clear
        printf 
    $(tput bold)$(tput setaf 2)"VirtualBox installation script for Fedora 20 and up\n"$(tput sgr0)
        
    printf $(tput bold)$(tput setaf 2)"Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"$(tput sgr0)
    }

    # Remove Oracle source files if they exist
    function remove_source()
    {
        for 
    i in $vbox_source_file $vbox_ext_source ; do
            
    rm -f $i
        done
    }

    # Remove Fedora VirtualBox. This will remove kmod-VirtualBox also.
    function remove_fed_vbox()
    {
    vbox_installed=$(rpm -qa grep VirtualBox)
    if [[ 
    $vbox_installed ]] ; then
        printf 
    $(tput bold)$(tput setaf 2)"Removing Fedora version of VirtualBox. Please wait..."$(tput sgr0)
        
    yum --q erase VirtualBox
        printf 
    $(tput setaf 2)"\nDone.\n"$(tput sgr0)
    fi
    }

    # Install the downloaded source RPM from Oracle
    function install_source()
    {
        if [[ -
    f $vbox_source_file ]] ; then
            printf 
    $(tput setaf 2)"Installing Oracle VirtualBox\n"$(tput sgr0)
            
    rpm -Uvh $vbox_source_file
        
    else
            echo $(
    tput bold)$(tput setaf 1)"Source file missing."$(tput sgr0)
            exit 
    0
        fi
    }

    # Get any necessary packages needed to complete the VirtualBox installation without errors
    function get_packages()
    {
    echo -
    -$(tput setaf 2)"Checking for necessary packages..."$(tput sgr0)
    echo
    newpkgs=""
    for i in $packfiles ; do
       echo -
    -$(tput setaf 2)"==> $i: "
       
    rpm -q $i > /dev/null
        
    if [ $? -eq 0 ] ; then
            
    echo $(tput bold)$(tput setaf 2)"✓"$(tput sgr0)
        else
            echo $(
    tput bold)$(tput setaf 1)"✗"$(tput sgr0)
            
    newpkgs="${newpkgs} $i"
        
    fi
    done
    if [ -"${newpkgs}]; then
       
    echo --$(tput setaf 2)"==> Installing ${newpkgs}... "$(tput sgr0)
       
    yum --q install ${newpkgs}
       echo -
    $(tput setaf 2)"\nDone installing packages.\n"$(tput sgr0)
    else
       echo $(
    tput setaf 2)"==> $(tput bold)Nothing new to install."$(tput sgr0)
    fi
    }

    # Get the VirtualBox source RPM from Oracle
    function get_source()
    {
        echo -
    -$(tput setaf 2)"Getting VirtualBox source from the Oracle download site..."$(tput sgr0)
        case `
    uname -min
            i386
    vbox_source="http://download.virtualbox.org/virtualbox/4.3.20/VirtualBox-4.3-4.3.20_96996_fedora18-1.i686.rpm" ;;
            
    i686vbox_source="http://download.virtualbox.org/virtualbox/4.3.20/VirtualBox-4.3-4.3.20_96996_fedora18-1.i686.rpm" ;;
            
    x86_64vbox_source="http://download.virtualbox.org/virtualbox/4.3.20/VirtualBox-4.3-4.3.20_96996_fedora18-1.x86_64.rpm" ;;
        
    esac
            remove_source
            wget 
    -q $vbox_source
            
    echo -$(tput bold)$(tput setaf 2)" ✓"$(tput sgr0)
            echo -
    -$(tput setaf 2)"Getting the VirtualBox Extension Pack source file..."$(tput sgr0)
        
            
    wget -q http://download.virtualbox.org/virtualbox/4.3.20/$vbox_ext_source
            
    echo -$(tput bold)$(tput setaf 2)" ✓"$(tput sgr0)
    echo
    }

    function 
    install_extpack()
    {
        if [[ -
    f $vbox_ext_source ]] ; then
            
    echo $(tput setaf 2)"Installing Oracle VirtualBox extension pack"$(tput sgr0)
            
    VBoxManage extpack install --replace $vbox_ext_source
        
    else
            echo $(
    tput setaf 2)"Trying to install the Oracle VirtualBox extension pack but can't find the source file!"$(tput sgr0)
        
    fi
    }
        
    function 
    script_complete()
    {
            
    remove_source
            printf 
    $(tput bold)$(tput setaf 2)"Script run complete.\n"$(tput sgr0)
    }

    function 
    script_cancel()
    {
        
    tput cuu1
        tput el
        printf 
    $(tput setaf 2)"Script cancelled.\n"$(tput sgr0)
    }

    function 
    query_user()
    {
    clear
    banner
    printf 
    $(tput setaf 2)"\nFor this script to succeed you need to be running the newest available and installed kernel.\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system.\n"$(tput sgr0)
    printf $(tput bold)$(tput setaf 2)"Shall we continue? <y/n> "$(tput sgr0)
    read yn
    case $yn in
        y
    get_release
           remove_source
           
    #remove_fed_vbox
           
    get_packages
           get_source
           install_source
           install_extpack
           script_complete
           
    ;;

        
    n) echo $(tput setaf 2)"Update your system and reboot into the newest kernel. Then revisit this script."$(tput sgr0)
           exit 
    0
           
    ;;
        *) 
    script_cancel
            
    exit 0
           
    ;;
    esac
    }
    query_user 
    Glenn
    The Bassinator

  2. #2
    Join Date
    May 2011
    Location
    Confoederatio Helvetica (Swissh)
    Age
    37
    Posts
    4,277

    Re: Oracle VirtualBox installation script

    Heya Glennzo

    Cant try your script atm, for obvious reasons, but will do tomorrow or monday

    For easier maintainance of the script, i'd recomend to set some values as variables:
    Code:
    VB_REL_VER="4.3-4.3.20_96996"
    VB_REL_DIST="fedora18-1."
    So your code (this example) would look like:
    Code:
    # At some point, when Oracle releases an updated RPM, these variables will need to be changed.
    vbox_source_file="VirtualBox-${VB_REL_VER}_${VB_REL_DIST}."`uname -m`".rpm" 
    vbox_ext_source="Oracle_VM_VirtualBox_Extension_Pack-${VB_REL_VER}.vbox-extpack"
    NOTE: Those { brackets are required, specialy for the first one, otherwise it would take the 'connecting' underscore as part of the Name, this way it knows the variablename had ended.

    You have reused the hardcoded version number of VB and release distro version of fedora quite a few times.
    If you set them as a variable, you just need to change this, and not all XY occourences in the script.
    Once done, its simpler to do than using sed for each version change.

    Hope this helps
    EFI Cheatsheet :: http://forums.fedoraforum.org/showthread.php?t=298546
    Video Handler Script (VHS) (mass re-encode videos, screenrecorder, console music/webradio player, ...) :: http://forums.fedoraforum.org/showthread.php?t=299182
    Windows 8+ & Fedora 20+ Dualboot :: http://forums.fedoraforum.org/showthread.php?t=298161

  3. #3
    Join Date
    Mar 2004
    Location
    In your closet
    Posts
    15,643

    Re: Oracle VirtualBox installation script

    Thanks for the tips Sea. They make a lot of sense. I'll incorporate them into the script.
    Glenn
    The Bassinator

  4. #4
    Join Date
    Aug 2007
    Location
    London Postbox (the red one)
    Age
    52
    Posts
    3,868

    Re: Oracle VirtualBox installation script

    Hi Glenn,

    had a quick look, does it work for a PAE kernel as well (not that its used much now)

  5. #5
    Join Date
    Jun 2004
    Location
    Laurel, MD USA
    Posts
    7,194

    Re: Oracle VirtualBox installation script

    I use code like this to get fancy so I don't have to edit the script as the user updates by putting a new source file in with the script, I assume the usage mode is that the new file(s) are put in the directory with the script and only the new files. They should remove the previous one. The count test detects that the filename isn't single valued and echoes an error.
    I use a glob to get the current exact filename by using find with the glob pattern. The goal is that the 'glob' is a
    pattern that's going to be sticked to, you try to make it selective enough so it's very unlikely a file will be in the directory that
    would match by accident.
    Code:
    #!/bin/bash
    .... other code...
    
    # change this for format changes if needed
    VBOX_SRC_GLOB="VirtualBox-*."`uname -m`".rpm"
    
    
    vbox_source_file=`/usr/bin/find . -mindepth 1 -maxdepth 1 -type f -name "$VBOX_SRC_GLOB"`
    source_words=( $vbox_source_file )
    source_count=${#source_words[@]}
    
    if [ "$source_count" -ne 1 ]; then
        echo "ERROR multiple source files in install directory"
        echo "remove previous file(s) and re-run"
        exit 1
    fi
    Another comment, be careful with the 'tput' fanciness, I have a customer I have to deal with, their programmers went crazy with tput in one of their
    scripts. It messes up the terminal when I try to use their script. I suspect it's a bad reaction with the TERM setting we use and they didn't save off the terminal settings at the beginning of the script to set it back to the way it was at the end.

    The terminal is corrupted after the script exits and it's not back to normal until I manually do a "clear". What I did to work around that (I don't want to edit their script the many dozens of tput's every time I update their file), is to set my terminal to ansi-mono which blocks all tput color settings, then I run their script:

    export TERM='ansi-mono'
    run script...
    Last edited by marko; 24th January 2015 at 10:33 PM. Reason: code fix

  6. #6
    Join Date
    Mar 2004
    Location
    In your closet
    Posts
    15,643

    Re: Oracle VirtualBox installation script

    @Dangermouse. Not sure about the PAE thing. Don't have a virtual machine running that kernel, at least not at the moment. Good point though.

    @ marko. I'm all about how the script looks. The least important factor.

    Let's try this with no color changes at all and I'll incorporate some of the other suggestions here too. Later though, not enough time right now.
    Glenn
    The Bassinator

  7. #7
    Join Date
    Jan 2011
    Posts
    186

    Re: Oracle VirtualBox installation script

    As a coincidence, I only decided to install VirtualBox this morning. I have no prior experience with virtual machines. Installed from the Fedora repos and it took several tries to get it running, but it seemed ok with one virtual machine installed.

    After finding this post, copied the script above and glad to say it ran perfectly replacing repo version with latest from oracle. My system is F21_64 bit with KDE.

    Thanks for that.

  8. #8
    Join Date
    Mar 2004
    Location
    In your closet
    Posts
    15,643

    Re: Oracle VirtualBox installation script

    Updated code, better variables (not perfect), no color. Still needs work but it still works.

    PHP Code:
    #!/bin/bash
    # 2_oracle_virtualbox.sh

    # Glenn A. Johnson
    # Started January 24, 2015
    # Updated January 24, 2015

    # Variables
    # Additional packages usually needed for a successful install of VirtualBox
    PACKFILES="kernel-devel-$(uname -r) gcc qt qt-x11 libpng15 dkms wget SDL"

    # At some point, when Oracle releases an updated RPM, these variables will need to be changed.
    VBOX_SOURCE_FILE="VirtualBox-4.3-4.3.20_96996_fedora18-1.`uname -m`.rpm"
    VBOX_EXT_SOURCE="Oracle_VM_VirtualBox_Extension_Pack-4.3.20-96996.vbox-extpack"

    # Need root permissions at some point, might as well do it now.
    if [[ $EUID -ne 0 ]] ; then
        clear
       
    echo -"You're going to need root permissions at some point. Let's get that out of the way now.\nUse \"sudo\" or \"su -c\""
       
    exit 0
    fi

    # Release 20 and later only
    function get_release()
    {
        
    clear
        printf 
    "Checking Fedora release version... "
        
    REL_NUM=$(rpm -qa --queryformat '%{version}\n' fedora-release)
        if [[ 
    $REL_NUM "20" ]] ; then
            printf 
    "\nThis script is for Fedora release 20 and later only.\nThis appears to be Fedora $REL_NUM.\n"
           
    exit 0
        
    else printf " ✓"
    fi
    echo
    }

    # Clear screen and print a banner
    function banner()
    {
        
    clear
        printf 
    "VirtualBox installation script for Fedora 20 and up\n"
        
    printf "Oracle VirtualBox and Oracle VirtualBox Extension Pack will be installed.\n"
    }

    # Remove Oracle source files if they exist
    function remove_source()
    {
        for 
    i in $VBOX_SOURCE_FILE $VBOX_EXT_SOURCE ; do
            
    rm -f $i
        done
    }

    # Remove Fedora VirtualBox. This will remove kmod-VirtualBox also.
    function remove_fed_vbox()
    {
    vbox_installed=$(rpm -qa grep VirtualBox)
    if [[ 
    $vbox_installed ]] ; then
        printf 
    "Removing Fedora version of VirtualBox. Please wait..."
        
    yum --q erase VirtualBox
        printf 
    "\nDone.\n"
    fi
    }

    # Get any necessary packages needed to complete the VirtualBox installation without errors
    function get_packages()
    {
    echo -
    -"Checking for necessary packages..."
    echo
    newpkgs=""
    for i in $PACKFILES ; do
       echo -
    -"==> $i: "
       
    rpm -q $i > /dev/null
        
    if [ $? -eq 0 ] ; then
            
    echo "✓"
        
    else
            echo 
    "✗"
            
    newpkgs="${newpkgs} $i"
        
    fi
    done
    if [ -"${newpkgs}]; then
       
    echo --"==> Installing ${newpkgs}... "
       
    yum --q install ${newpkgs}
       echo -
    "\nDone installing packages.\n"
    else
       echo 
    "==> Nothing new to install."
    fi
    }

    # Get the VirtualBox source RPM from Oracle
    function get_source()
    {
        echo -
    -"Getting VirtualBox source from the Oracle download site..."
        
    remove_source
        wget 
    -q http://download.virtualbox.org/virtualbox/4.3.20/$VBOX_SOURCE_FILE
        
    echo -" ✓"
        
    echo --"Getting the VirtualBox Extension Pack source file..."    
        
    wget -q http://download.virtualbox.org/virtualbox/4.3.20/$VBOX_EXT_SOURCE
        
    echo -" ✓"
    echo
    }

    # Install the downloaded source RPM from Oracle
    function install_source()
    {
        if [[ -
    f $VBOX_SOURCE_FILE ]] ; then
            printf 
    "Installing Oracle VirtualBox\n"
            
    rpm -Uvh $VBOX_SOURCE_FILE
        
    else
            echo 
    "Source file missing."
            
    exit 0
        fi
    }

    function 
    install_extpack()
    {
        if [[ -
    f $VBOX_EXT_SOURCE ]] ; then
            
    echo "Installing Oracle VirtualBox extension pack"
            
    VBoxManage extpack install --replace $VBOX_EXT_SOURCE
        
    else
            echo 
    "Trying to install the Oracle VirtualBox extension pack but can't find the source file!"
        
    fi
    }

    function 
    script_complete()
    {
            
    remove_source
            printf 
    "Script run complete.\n"
    }

    function 
    script_cancel()
    {
        
    tput cuu1
        tput el
        printf 
    "Script cancelled.\n"
    }

    function 
    query_user()
    {
    clear
    banner
    printf 
    "\nFor this script to succeed you need to be running the newest available and installed kernel.\nIf you aren't running the newest available and installed kernel please exit this script\nand update your system.\n"
    printf "Shall we continue? <y/n> "
    read yn
    case $yn in
        y
    get_release
           remove_source
           
    #remove_fed_vbox
           
    get_packages
           get_source
           install_source
           install_extpack
           script_complete
           
    ;;

        
    nscript_cancel
            
    exit 0
           
    ;;
        *) 
    script_cancel
            
    exit 0
           
    ;;
    esac
    }
    query_user 
    Glenn
    The Bassinator

  9. #9
    Join Date
    Mar 2004
    Location
    In your closet
    Posts
    15,643

    Re: Oracle VirtualBox installation script

    Quote Originally Posted by zuser
    As a coincidence, I only decided to install VirtualBox this morning. I have no prior experience with virtual machines. Installed from the Fedora repos and it took several tries to get it running, but it seemed ok with one virtual machine installed.

    After finding this post, copied the script above and glad to say it ran perfectly replacing repo version with latest from oracle. My system is F21_64 bit with KDE.

    Thanks for that.
    That's good news! I happy to hear that the script was a useful tool for someone.
    Glenn
    The Bassinator

  10. #10
    Join Date
    Jun 2010
    Location
    Lost...
    Posts
    1,300

    Re: Oracle VirtualBox installation script

    Since you can assign the 'tput' output to variables, you can easily remove the colors as an option. Here an example (example.sh):
    Code:
    #!/bin/bash
    
    # Color definitions; the variables are null it the option NOCOLOR is set
    if [ -z "$NOCOLOR" ]; then
            OK=$(tput bold;tput setaf 2)
            ERR=$(tput bold;tput setaf 1)
            RST=$(tput sgr0)
    else
            OK=
            ERR=
            RST=
    fi
    # end of color definitions
    
    echo -en "[ ${ERR}Error${RST} ]"
    echo -e "[ ${OK}OK${RST} ]"
    Usage with colors:
    example.sh
    and without:
    NOCOLOR=1 example.sh
    :confused:

  11. #11
    Join Date
    Mar 2004
    Location
    In your closet
    Posts
    15,643

    Re: Oracle VirtualBox installation script

    Quote Originally Posted by Skull One
    Since you can assign the 'tput' output to variables, you can easily remove the colors as an option. Here an example (example.sh):
    Code:
    #!/bin/bash
    
    # Color definitions; the variables are null it the option NOCOLOR is set
    if [ -z "$NOCOLOR" ]; then
            OK=$(tput bold;tput setaf 2)
            ERR=$(tput bold;tput setaf 1)
            RST=$(tput sgr0)
    else
            OK=
            ERR=
            RST=
    fi
    # end of color definitions
    
    echo -en "[ ${ERR}Error${RST} ]"
    echo -e "[ ${OK}OK${RST} ]"
    Usage with colors:
    example.sh
    and without:
    NOCOLOR=1 example.sh
    Interesting. I like that and might just try adding it to my script. Thanks Skull One.
    Glenn
    The Bassinator

  12. #12
    Join Date
    Feb 2012
    Location
    romania
    Posts
    76

    Re: Oracle VirtualBox installation script

    thanx man.....great job!
    i just installed virtual box. previously i have had virtual box from fedora and i had to remove it since my first attempt to install, over fedora version, has failed.
    thanx again!

  13. #13
    Join Date
    Mar 2004
    Location
    In your closet
    Posts
    15,643

    Re: Oracle VirtualBox installation script

    Quote Originally Posted by rich1974
    thanx man.....great job!
    i just installed virtual box. previously i have had virtual box from fedora and i had to remove it since my first attempt to install, over fedora version, has failed.
    thanx again!
    Sweet! 2 for 2! Glad the script worked as expected.
    Glenn
    The Bassinator

  14. #14
    Join Date
    Mar 2004
    Location
    In your closet
    Posts
    15,643

    Re: Oracle VirtualBox installation script

    Just as info, seems that there is a problem with forum attachments so I can't upload a tar file, hence the full script.
    Glenn
    The Bassinator

  15. #15
    Join Date
    May 2013
    Location
    Places
    Posts
    215

    Re: Oracle VirtualBox installation script

    Just seems odd that virtualbox is this hard to install, sure we have gnome boxes but boxes isnt that good IMHO
    Insane in the membrane

Page 1 of 7 1 2 3 ... LastLast

Similar Threads

  1. oracle virtualbox not working
    By pythonkr11 in forum Wibble
    Replies: 1
    Last Post: 7th September 2012, 07:48 PM
  2. oracle virtualbox not working
    By pythonkr11 in forum Fedora Focus
    Replies: 1
    Last Post: 7th September 2012, 07:20 PM
  3. Oracle Virtualbox
    By clueless in forum Using Fedora
    Replies: 5
    Last Post: 17th May 2011, 10:39 AM
  4. [SOLVED] oracle vm virtualbox
    By postmanpat in forum Using Fedora
    Replies: 5
    Last Post: 24th November 2010, 12:51 PM
  5. Update Oracle VM VirtualBox error
    By JValeck in forum Using Fedora
    Replies: 2
    Last Post: 12th October 2010, 05:42 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •