LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud
User Name
Password
Linux - Virtualization and Cloud This forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.

Notices

Reply
 
Search this Thread
Old 10-20-2009, 08:22 AM   #31
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Original Poster
Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176

Quote:
Originally Posted by catkin View Post
Presumably the fstab line overrides the udev rules. Time for another modification to the script.
Script updated to suit
Code:
#! /bin/bash

# ck_vbox_USB.sh, a quick-and-dirty script to sanity-check host config for VirtualBox USB.

# Usage: no arguments or options

# Change history
# 18oct9 Charles
#    * Added RPM enquiry (and skeleton dpkg enquiry).
# 20oct9 Charles
#    * Added udev rules detection (fstab usbfs line no longer mandatory).
#    * Added vboxdrv kernel module detection.
#    * Added temporary file removal.
# 20oct9 Charles
#    * Changed to check fstab when udev rules exist (fstab usbfs line seems to override udev rules)

# Set up environment
PATH="/usr/bin:/bin:/usr/sbin:/sbin"
set -o nounset
unset IFS
tmp_afn="$(mktemp "/tmp/$0.XXXXXX")"
[[ $? -ne 0 ]] && \echo "ERROR: unable to create temporary file (this is not a VirtualBox USB problem)" >&2 && \exit 1
trap "rm -f $tmp_afn" EXIT

# Set up line feed
lf=$'\n'

function ck_PUEL {

    typeset msg OK_flag ERROR_flag
    OK_flag='NO'
    ERROR_flag='NO'

    # Default (?) VBox config file
    if [[ -r '/etc/vbox/vbox.cfg' ]]; then
        . /etc/vbox/vbox.cfg
        license_afn="$INSTALL_DIR/LICENSE"
        if [[ -r "$license_afn" ]]; then
            if grep 'PUEL' "$license_afn" > /dev/null ; then
                OK_flag='YES'
            else
                ERROR_flag='YES'
            fi
        else
            echo "WARNING: Could not read '$license_afn' identified by /etc/vbox/vbox.cfg" >&2
        fi
    fi

    # RPM
    if type rpm > /dev/null 2>&1 ; then
        case "$( rpm -qi VirtualBox 2>&1 )" in
            *PUEL* )
                OK_flag='YES'
                ;;
            *'is not installed'* )
                ;;
            * )
                ERROR_flag='YES'
        esac
    fi

    # .deb
    if type dpkg > /dev/null 2>&1 ; then
       \echo 'WARNING: this script is not programmed for .deb package systems'
    fi

    # Report findings
    if [[ "$OK_flag" = 'YES' ]]; then
        \echo 'VirtualBox PUEL version found.  OK.'
        if [[ "$ERROR_flag" = 'YES' ]]; then
            \echo 'WARNING: VirtualBox non-PUEL version also found.  ???' >&2
        fi
    elif [[ "$ERROR_flag" = 'YES' ]]; then
        \echo 'ERROR: Installed VirtualBox is not the PUEL version so USB not supported.' >&2 && \exit 1
    else
        \echo 'WARNING: unable to determine which version of VirtualBox, if any, is installed.'
    fi

} # ck_PUEL

# Check for VirtualBox PUEL version
ck_PUEL

# Get user name
while true
do
    \echo -n 'Name of user used to run VirtualBox: '
    read user
    grep "^$user:" /etc/passwd > /dev/null && break
    echo "User $user not found in /etc/passwd. Try again (or Ctrl+C to exit)"
done

# Is VirtualBox using udev rules?
udev_rules_flag='NO'
vbox_udev_rules_afn='/etc/udev/rules.d/10-vboxdrv.rules'
if [[ -e "$vbox_udev_rules_afn" ]]; then
    \echo "This computer has udev rules file for VirtualBox, $vbox_udev_rules_afn.  OK."
    udev_rules_flag='YES'

    # Get group and access mode
    [[ ! -r "$vbox_udev_rules_afn" ]] && \echo "ERROR: $vbox_udev_rules_afn not readable by this script (OK for VirtualBox USB if readable by root)." >&2 && \exit 1
    grep -E '^SUBSYSTEM=="(usb")|(usb_device")' "$vbox_udev_rules_afn" > "$tmp_afn"
    while read line
    do
        IFS=','; array=($line); unset IFS
        for ((i=1; i<${#array[*]}; i++))
        do
            field="${array[$i]}"
            case "$field" in
                *'GROUP="'* )
                    buf="${field#*GROUP=\"}"
                    buf="${buf%\"*}"
                    if [[ "${group:-}" = '' ]];then
                        group="$buf"
                    elif [[ "$buf" != "$group" ]]; then
                        \echo "WARNING: different groups ('$group' and '$buf') in $vbox_udev_rules_afn. Ignoring '$buf'."
                    fi
                    ;;
                *'MODE="'* )
                    buf="${field#*MODE=\"}"
                    buf="${buf%\"*}"
                    if [[ "${mode:-}" = '' ]];then
                        mode="$buf"
                    elif [[ "$buf" != "$mode" ]]; then
                        \echo "WARNING: different modes ('$mode' and '$buf') in $vbox_udev_rules_afn. Ignoring '$buf'."
                    fi
                    ;;
            esac
        done
    done < "$tmp_afn"
    [[ "${group:-}" = '' ]] && \echo "ERROR: No group found for 'usb' or 'usb_device' in $vbox_udev_rules_afn." >&2 && \exit 1
    [[ "${mode:-}" = '' ]] && \echo "ERROR: No mode found for 'usb' or 'usb_device' in $vbox_udev_rules_afn." >&2 && \exit 1
fi

# fstab with usbfs line(s)?
fstab_usbfs_flag='NO'
grep -v '^#' /etc/fstab | grep usbfs > /"$tmp_afn"
while read line
do
    [[ "$fstab_usbfs_flag" = 'YES' ]] && echo "WARNING: More than one usbfs line in /etc/fstab. Effect on VirtualBox unknown${lf}Here is fstab:$lf$(cat /etc/fstab)" >&2 && break
    \echo "usbfs line found in /etc/fstab.  OK."
    fstab_usbfs_flag='YES'
    \echo "Here is the usbfs line from /etc/fstab:$lf"$line

    # Get Group ID and access mode
    array=($line)
    options="${array[3]}"
    IFS=','; array=($options); unset IFS
    for ((i=0; i<${#array[*]}; i++))
    do
        option="${array[$i]}"
        case "$option" in
            'devgid='* )
                gid="${option#devgid=}"
                ;;
            'devmode='* )
                mode="${option#devmode=}"
                ;;
        esac
    done
    [[ "${gid:-}" = '' ]] && \echo "ERROR: No devgid option on usbfs line in /etc/fstab." >&2 && \exit 1
    [[ "${mode:-}" = '' ]] && \echo "ERROR: No devmode option on usbfs line in /etc/fstab." >&2 && \exit 1
done < "$tmp_afn"

# Report udev rules and fstab usbfs combined results
case "$udev_rules_flag$fstab_usbfs_flag" in
    'YESNO' )
        \echo 'No fstab usbfs line found. udev rules are effective.'
        ;;
    'YESYES' )
        \echo 'WARNING: fstab usbfs line found. This script assumes (!) the fstab usbfs line overrides udev rules.'
        group=''
        ;;
     'NONO' )
        \echo "ERROR: found neither udev rules nor /etc/fstab with usbfs line." >&2 && \exit 1
esac

# Get group from /etc/group by name or ID
if [[ "${group:-}" != '' ]]; then
    \echo "Group name used for VirtualBox USB access is $group."
    group_line="$(grep "^$group:" /etc/group)"
    [[ "$group_line" = '' ]] && \echo "ERROR: group '$group' does not exist in /etc/group." >&2 && \exit 1
    \echo "Group $group found in /etc/group.  OK."
else
    \echo "Group ID used for VirtualBox USB access is $gid."
    group_line="$(grep "^[^:]*:[^:]*:$gid:" /etc/group)"
    [[ "$group_line" = '' ]] && \echo "ERROR: Group ID $gid does not exist in /etc/group." >&2 && \exit 1
    \echo "Group ID $gid found in /etc/group.  OK."
fi
IFS=':'; array=($group_line)
group="${array[0]}"; gid="${array[2]}"
\echo "Here is the group line from /etc/group:$lf$group_line"

# Ensure the user is a member of the group
IFS=','; array=(${array[3]}); unset IFS
OK='no'
for ((i=0; i<${#array[*]}; i++))
do
    user_in_group="${array[$i]}"
    case "$user_in_group" in
        "$user" )
            OK='yes'
            break
            ;;
    esac
done
[[ "$OK" = 'no' ]] && \echo "ERROR: User '$user' is not in group $group/$gid." >&2 && \exit 1
\echo "User $user is in group $group/$gid.  OK."

# Check access mode
# udev rules usually has 4 digits, fstab 3 digits.  Assume it's OK for either to have 3-4 ...
\echo "Access mode used for VirtualBox USB access is $mode."
[[ "${#mode}" -lt 3 ||  "${#mode}" -gt 4 || "${mode//[0-9]/}" != '' ]] && \echo "ERROR: access mode ($mode) is not 3 to 4 integers" >&2 && \exit 1
group_mode="${mode:((${#mode} - 2)):1}"
let group_write=group_mode-4
[[ $group_write -lt 2 ]] && \echo "ERROR: access mode ($mode) does not include 'group write'" >&2 && \exit 1
\echo "Access mode ($mode) includes 'group write'.  OK."

# Check kernel module vboxdrv loaded
if ! lsmod | grep '^vboxdrv' > /dev/null ; then
    \echo "ERROR: kernel module vboxdrv not loaded." >&2 && \exit 1
else
    \echo "Kernel module vboxdrv loaded.  OK."
fi

\echo "All tests passed.  OK.  :-)"

exit 0
 
Old 10-20-2009, 09:36 AM   #32
New2Linux2
Member
 
Registered: Jan 2004
Location: Arizona
Distribution: Debian
Posts: 147

Rep: Reputation: 43
And here's the latest from my Ubuntu JJ install:
Code:
dave@dave-laptop:~$ ./usbtest3
WARNING: this script is not programmed for .deb package systems
WARNING: unable to determine which version of VirtualBox, if any, is installed
Name of user used to run VirtualBox: dave
This computer has udev rules file for VirtualBox, /etc/udev/rules.d/10-vboxdrv.rules.  OK
Group used for VirtualBox USB access is vboxusers.
Group vboxusers found in /etc/group.  OK.
Here is group vboxusers from /etc/group: vboxusers:x:124:dave
User dave is in group vboxusers with GID 124.  OK.
Access mode used for VirtualBox USB access is 0664.
Access mode (0664) includes 'group write'.  OK
Kernel module vboxdrv loaded.  OK
All tests passed.  OK.  :-)
dave@dave-laptop:~$
So even though it's not written to check .deb package systems, it still checks everything else of importance.
 
Old 10-20-2009, 10:24 AM   #33
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Original Poster
Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by New2Linux2 View Post
So even though it's not written to check .deb package systems, it still checks everything else of importance.
Yes, that seemed the most constructive approach pending information on how to identify a VirtualBox PUEL version (or not) on .deb-based systems.
 
Old 10-21-2009, 10:53 AM   #34
New2Linux2
Member
 
Registered: Jan 2004
Location: Arizona
Distribution: Debian
Posts: 147

Rep: Reputation: 43
I love this place. You ask a simple question, you get a simple answer.
Code:
apt-cache show <package>
will show quite a bit of detail about a package, but it doesn't list the license. You can determine that from the package name, though. Here is what each package shows on my system:
Code:
dave@dave-laptop:~$ apt-cache show virtualbox-3.0
Package: virtualbox-3.0
Status: install ok installed
Priority: optional
Section: non-free/misc
Installed-Size: 85640
Maintainer: Sun Microsystems, Inc. <info@virtualbox.org>
Architecture: i386
Version: 3.0.8-53138_Ubuntu_jaunty
Replaces: virtualbox
Provides: virtualbox
Depends: libc6 (>= 2.7), libcurl3 (>= 7.16.2-1), libgcc1 (>= 1:4.1.1), libpython2.6 (>= 2.6), libqt4-network (>= 4.5.0~+rc1), libqtcore4 (>= 4.5.0~+rc1), libqtgui4 (>= 4.5.0~+rc1), libsdl1.2debian (>= 1.2.10-1), libssl0.9.8 (>= 0.9.8f-5), libstdc++6 (>= 4.2.1), libx11-6, libxcursor1 (>> 1.1.2), libxext6, libxml2 (>= 2.6.27), libxmu6, libxslt1.1 (>= 1.1.18), libxt6, zlib1g (>= 1:1.1.4), psmisc, adduser
Pre-Depends: debconf (>= 1.1) | debconf-2.0
Recommends: libasound2, libpulse0, libsdl-ttf2.0-0, dkms, linux-headers, gcc, make, binutils, libhal1 (>= 0.5), pdf-viewer, libgl1, python-central
Conflicts: virtualbox
Conffiles:
 /etc/init.d/vboxdrv 4804eb18a6417a47244eec9025337ad8
Description: Sun VirtualBox
 VirtualBox is a powerful PC virtualization solution allowing you to run a
 wide range of PC operating systems on your Linux system. This includes
 Windows, Linux, FreeBSD, DOS, OpenBSD and others. VirtualBox comes with a broad
 feature set and excellent performance, making it the premier virtualization
 software solution on the market.
Python-Version: >= 2.4

dave@dave-laptop:~$
Code:
dave@dave-laptop:~$ apt-cache show virtualbox-ose
Package: virtualbox-ose
Priority: optional
Section: universe/misc
Installed-Size: 31164
Maintainer: Ubuntu MOTU Developers <ubuntu-motu@lists.ubuntu.com>
Original-Maintainer: Debian Virtualbox Team <pkg-virtualbox-devel@lists.alioth.debian.org>
Architecture: i386
Version: 2.1.4-dfsg-1ubuntu3
Replaces: virtualbox
Provides: virtualbox
Depends: libc6 (>= 2.4), libgcc1 (>= 1:4.1.1), libpython2.6 (>= 2.6), libqt4-network (>= 4.5.0~+rc1), libqtcore4 (>= 4.5.0~+rc1), libqtgui4 (>= 4.5.0~+rc1), libsdl1.2debian (>= 1.2.10-1), libstdc++6 (>= 4.2.1), libx11-6, libxcursor1 (>> 1.1.2), libxext6, libxml2 (>= 2.6.27), libxmu6, libxslt1.1 (>= 1.1.18), libxt6, adduser, python
Pre-Depends: debconf | debconf-2.0
Recommends: virtualbox-ose-source, libgl1
Suggests: bridge-utils
Conflicts: virtualbox
Filename: pool/universe/v/virtualbox-ose/virtualbox-ose_2.1.4-dfsg-1ubuntu3_i386.deb
Size: 8782822
MD5sum: b49984b114ac7d957bc7c222225befc1
SHA1: 05c5140b3155653ede01a3e25fa4f2ce475654cb
SHA256: 2e907043aae936850a9e117874f0ed5b0475da8326e2ec821535bd59486e18a9
Description: x86 virtualization solution - binaries
 VirtualBox is a free x86 virtualization solution allowing a wide range
 of x86 operating systems such as Windows, DOS, BSD or Linux to run on a
 Linux system.
 .
 This package provides the binaries for the Open Source Edition of
 VirtualBox. The virtualbox-ose-source package is also required in order to
 compile the kernel modules needed for virtualbox-ose.
Homepage: http://www.virtualbox.org/
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Origin: Ubuntu

dave@dave-laptop:~$
The PUEL version shows its status as installed. The OSE version does not show any status (presumable because it is not installed.) Let me know if I can help more with this.
 
Old 10-21-2009, 11:56 AM   #35
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Original Poster
Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Thanks New2Linux2

Here's the script updated to use the information you gathered. Not tested. Would be helpful if you test it.
Code:
#! /bin/bash

# ck_vbox_USB.sh, a quick-and-dirty script to sanity-check host config for VirtualBox USB.

# Usage: no arguments or options

# Change history
# 18oct9 Charles
#    * Added RPM enquiry (and skeleton dpkg enquiry).
# 20oct9 Charles
#    * Added udev rules detection (fstab usbfs line no longer mandatory).
#    * Added vboxdrv kernel module detection.
#    * Added temporary file removal.
# 20oct9 Charles
#    * Changed to check fstab when udev rules exist (fstab usbfs line seems to override udev rules)
# 21oct9 Charles
#    * Added VirtualBox 3.0 PUEL detection for .deb systems by apt-cache

# Set up environment
PATH="/usr/bin:/bin:/usr/sbin:/sbin"
set -o nounset
unset IFS
tmp_afn="$(mktemp "/tmp/$0.XXXXXX")"
[[ $? -ne 0 ]] && \echo "ERROR: unable to create temporary file (this is not a VirtualBox USB problem)" >&2 && \exit 1
trap "rm -f $tmp_afn" EXIT

# Set up line feed
lf=$'\n'

function ck_PUEL {

    typeset msg OK_flag ERROR_flag
    OK_flag='NO'
    ERROR_flag='NO'

    # Default (?) VBox config file
    if [[ -r '/etc/vbox/vbox.cfg' ]]; then
        . /etc/vbox/vbox.cfg
        license_afn="$INSTALL_DIR/LICENSE"
        if [[ -r "$license_afn" ]]; then
            if grep 'PUEL' "$license_afn" > /dev/null ; then
                OK_flag='YES'
            else
                ERROR_flag='YES'
            fi
        else
            echo "WARNING: Could not read '$license_afn' identified by /etc/vbox/vbox.cfg" >&2
        fi
    fi

    # RPM
    if type rpm > /dev/null 2>&1 ; then
        case "$( rpm -qi VirtualBox 2>&1 )" in
            *PUEL* )
                OK_flag='YES'
                ;;
            *'is not installed'* )
                ;;
            * )
                ERROR_flag='YES'
        esac
    fi

    # .deb
    if type apt-cache > /dev/null 2>&1 ; then
        case "$( apt-cache show 'virtualbox-3.0' 2>&1 )" in
            *'Status: install ok installed'*'Open Source Edition'* )
                ERROR_flag='YES'
                ;;
            *'Status: install ok installed'* )
                OK_flag='YES'
                ;;
        esac
    fi

    # Report findings
    if [[ "$OK_flag" = 'YES' ]]; then
        \echo 'VirtualBox PUEL version found.  OK.'
        if [[ "$ERROR_flag" = 'YES' ]]; then
            \echo 'WARNING: VirtualBox non-PUEL version also found.  ???' >&2
        fi
    elif [[ "$ERROR_flag" = 'YES' ]]; then
        \echo 'ERROR: Installed VirtualBox is not the PUEL version so USB not supported.' >&2 && \exit 1
    else
        \echo 'WARNING: unable to determine which version of VirtualBox, if any, is installed.'
    fi

} # ck_PUEL

# Check for VirtualBox PUEL version
ck_PUEL

# Get user name
while true
do
    \echo -n 'Name of user used to run VirtualBox: '
    read user
    grep "^$user:" /etc/passwd > /dev/null && break
    echo "User $user not found in /etc/passwd. Try again (or Ctrl+C to exit)"
done

# Is VirtualBox using udev rules?
udev_rules_flag='NO'
vbox_udev_rules_afn='/etc/udev/rules.d/10-vboxdrv.rules'
if [[ -e "$vbox_udev_rules_afn" ]]; then
    \echo "This computer has udev rules file for VirtualBox, $vbox_udev_rules_afn.  OK."
    udev_rules_flag='YES'

    # Get group and access mode
    [[ ! -r "$vbox_udev_rules_afn" ]] && \echo "ERROR: $vbox_udev_rules_afn not readable by this script (OK for VirtualBox USB if readable by root)." >&2 && \exit 1
    grep -E '^SUBSYSTEM=="(usb")|(usb_device")' "$vbox_udev_rules_afn" > "$tmp_afn"
    while read line
    do
        IFS=','; array=($line); unset IFS
        for ((i=1; i<${#array[*]}; i++))
        do
            field="${array[$i]}"
            case "$field" in
                *'GROUP="'* )
                    buf="${field#*GROUP=\"}"
                    buf="${buf%\"*}"
                    if [[ "${group:-}" = '' ]];then
                        group="$buf"
                    elif [[ "$buf" != "$group" ]]; then
                        \echo "WARNING: different groups ('$group' and '$buf') in $vbox_udev_rules_afn. Ignoring '$buf'."
                    fi
                    ;;
                *'MODE="'* )
                    buf="${field#*MODE=\"}"
                    buf="${buf%\"*}"
                    if [[ "${mode:-}" = '' ]];then
                        mode="$buf"
                    elif [[ "$buf" != "$mode" ]]; then
                        \echo "WARNING: different modes ('$mode' and '$buf') in $vbox_udev_rules_afn. Ignoring '$buf'."
                    fi
                    ;;
            esac
        done
    done < "$tmp_afn"
    [[ "${group:-}" = '' ]] && \echo "ERROR: No group found for 'usb' or 'usb_device' in $vbox_udev_rules_afn." >&2 && \exit 1
    [[ "${mode:-}" = '' ]] && \echo "ERROR: No mode found for 'usb' or 'usb_device' in $vbox_udev_rules_afn." >&2 && \exit 1
fi

# fstab with usbfs line(s)?
fstab_usbfs_flag='NO'
grep -v '^#' /etc/fstab | grep usbfs > /"$tmp_afn"
while read line
do
    [[ "$fstab_usbfs_flag" = 'YES' ]] && echo "WARNING: More than one usbfs line in /etc/fstab. Effect on VirtualBox unknown${lf}Here is fstab:$lf$(cat /etc/fstab)" >&2 && break
    \echo "usbfs line found in /etc/fstab.  OK."
    fstab_usbfs_flag='YES'
    \echo "Here is the usbfs line from /etc/fstab:$lf"$line

    # Get Group ID and access mode
    array=($line)
    options="${array[3]}"
    IFS=','; array=($options); unset IFS
    for ((i=0; i<${#array[*]}; i++))
    do
        option="${array[$i]}"
        case "$option" in
            'devgid='* )
                gid="${option#devgid=}"
                ;;
            'devmode='* )
                mode="${option#devmode=}"
                ;;
        esac
    done
    [[ "${gid:-}" = '' ]] && \echo "ERROR: No devgid option on usbfs line in /etc/fstab." >&2 && \exit 1
    [[ "${mode:-}" = '' ]] && \echo "ERROR: No devmode option on usbfs line in /etc/fstab." >&2 && \exit 1
done < "$tmp_afn"

# Report udev rules and fstab usbfs combined results
case "$udev_rules_flag$fstab_usbfs_flag" in
    'YESNO' )
        \echo 'No fstab usbfs line found. udev rules are effective.'
        ;;
    'YESYES' )
        \echo 'WARNING: fstab usbfs line found. This script assumes (!) the fstab usbfs line overrides udev rules.'
        group=''
        ;;
     'NONO' )
        \echo "ERROR: found neither udev rules nor /etc/fstab with usbfs line." >&2 && \exit 1
esac

# Get group from /etc/group by name or ID
if [[ "${group:-}" != '' ]]; then
    \echo "Group name used for VirtualBox USB access is $group."
    group_line="$(grep "^$group:" /etc/group)"
    [[ "$group_line" = '' ]] && \echo "ERROR: group '$group' does not exist in /etc/group." >&2 && \exit 1
    \echo "Group $group found in /etc/group.  OK."
else
    \echo "Group ID used for VirtualBox USB access is $gid."
    group_line="$(grep "^[^:]*:[^:]*:$gid:" /etc/group)"
    [[ "$group_line" = '' ]] && \echo "ERROR: Group ID $gid does not exist in /etc/group." >&2 && \exit 1
    \echo "Group ID $gid found in /etc/group.  OK."
fi
IFS=':'; array=($group_line)
group="${array[0]}"; gid="${array[2]}"
\echo "Here is the group line from /etc/group:$lf$group_line"

# Ensure the user is a member of the group
IFS=','; array=(${array[3]}); unset IFS
OK='no'
for ((i=0; i<${#array[*]}; i++))
do
    user_in_group="${array[$i]}"
    case "$user_in_group" in
        "$user" )
            OK='yes'
            break
            ;;
    esac
done
[[ "$OK" = 'no' ]] && \echo "ERROR: User '$user' is not in group $group/$gid." >&2 && \exit 1
\echo "User $user is in group $group/$gid.  OK."

# Check access mode
# udev rules usually has 4 digits, fstab 3 digits.  Assume it's OK for either to have 3-4 ...
\echo "Access mode used for VirtualBox USB access is $mode."
[[ "${#mode}" -lt 3 ||  "${#mode}" -gt 4 || "${mode//[0-9]/}" != '' ]] && \echo "ERROR: access mode ($mode) is not 3 to 4 integers" >&2 && \exit 1
group_mode="${mode:((${#mode} - 2)):1}"
let group_write=group_mode-4
[[ $group_write -lt 2 ]] && \echo "ERROR: access mode ($mode) does not include 'group write'" >&2 && \exit 1
\echo "Access mode ($mode) includes 'group write'.  OK."

# Check kernel module vboxdrv loaded
if ! lsmod | grep '^vboxdrv' > /dev/null ; then
    \echo "ERROR: kernel module vboxdrv not loaded." >&2 && \exit 1
else
    \echo "Kernel module vboxdrv loaded.  OK."
fi

\echo "All tests passed.  OK.  :-)"

exit 0
 
Old 10-21-2009, 12:33 PM   #36
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,042

Rep: Reputation: 761Reputation: 761Reputation: 761Reputation: 761Reputation: 761Reputation: 761Reputation: 761
Hey, Charles,

Here's the output from the just-published shell program:
Code:
testvb
VirtualBox PUEL version found.  OK.
Name of user used to run VirtualBox: trona
This computer has udev rules file for VirtualBox, /etc/udev/rules.d/10-vboxdrv.rules.  OK.
No fstab usbfs line found. udev rules are effective.
Group name used for VirtualBox USB access is vboxusers.
Group vboxusers found in /etc/group.  OK.
Here is the group line from /etc/group:
vboxusers:x:102:trona,dronayne
User trona is in group vboxusers/102.  OK.
Access mode used for VirtualBox USB access is 0664.
Access mode (0664) includes 'group write'.  OK.
Kernel module vboxdrv loaded.  OK.
All tests passed.  OK.  :-)
Hope this helps some.
 
Old 10-21-2009, 01:53 PM   #37
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Original Poster
Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by tronayne View Post
Hey, Charles,

Here's the output from the just-published shell program:
Code:
testvb
VirtualBox PUEL version found.  OK.
Name of user used to run VirtualBox: trona
This computer has udev rules file for VirtualBox, /etc/udev/rules.d/10-vboxdrv.rules.  OK.
No fstab usbfs line found. udev rules are effective.
Group name used for VirtualBox USB access is vboxusers.
Group vboxusers found in /etc/group.  OK.
Here is the group line from /etc/group:
vboxusers:x:102:trona,dronayne
User trona is in group vboxusers/102.  OK.
Access mode used for VirtualBox USB access is 0664.
Access mode (0664) includes 'group write'.  OK.
Kernel module vboxdrv loaded.  OK.
All tests passed.  OK.  :-)
Hope this helps some.
Thanks for the feedback tronayne

If understand correctly, you initially had udev rules and no fstab usbfs line (the default VBox configuration on systems that support udev) but USB wasn't working until you added an fstab usbfs line. From what you posted it looks as if you went back to the original configuration and presumably that's working. Have I got that right? If so, what changed?
 
Old 10-21-2009, 02:34 PM   #38
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,042

Rep: Reputation: 761Reputation: 761Reputation: 761Reputation: 761Reputation: 761Reputation: 761Reputation: 761
Quote:
If understand correctly, you initially had udev rules and no fstab usbfs line (the default VBox configuration on systems that support udev) but USB wasn't working until you added an fstab usbfs line. From what you posted it looks as if you went back to the original configuration and presumably that's working. Have I got that right? If so, what changed?
I have absolutely no idea whatsoever -- blasted thing did not work on the initial go-round (with reboot and all that), I went to the VirtualBox web site, looked at the discussions of the problem (and I think with some input from you), stuck that line in /etc/fstab, thing worked, ran your shell program a few times, commented-out the line in /etc/fstab, thing works on both the Linux side of the world and on the guest OS side of the world (that would be XP).

It's magic, that's all tis.

Thomas
 
Old 10-22-2009, 10:18 AM   #39
New2Linux2
Member
 
Registered: Jan 2004
Location: Arizona
Distribution: Debian
Posts: 147

Rep: Reputation: 43
And here's mine:
Code:
dave@dave-laptop:~$ ./usbtest
VirtualBox PUEL version found.  OK.
Name of user used to run VirtualBox: dave
This computer has udev rules file for VirtualBox, /etc/udev/rules.d/10-vboxdrv.rules.  OK.
No fstab usbfs line found. udev rules are effective.
Group name used for VirtualBox USB access is vboxusers.
Group vboxusers found in /etc/group.  OK.
Here is the group line from /etc/group:
vboxusers:x:124:dave
User dave is in group vboxusers/124.  OK.
Access mode used for VirtualBox USB access is 0664.
Access mode (0664) includes 'group write'.  OK.
Kernel module vboxdrv loaded.  OK.
All tests passed.  OK.  :-)
dave@dave-laptop:~$
I never bothered messing with the /etc/fstab. The only change I made after installing the PUEL version was to (finally) add my user account to the vboxusers group manually. That's what got it working on my system.

Let me know if I can be of more help.
 
Old 10-22-2009, 11:06 AM   #40
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Original Poster
Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by tronayne View Post
It's magic, that's all tis.
 
Old 10-22-2009, 11:08 AM   #41
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Original Poster
Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by New2Linux2 View Post
Let me know if I can be of more help.
Thanks for testing. It's good to know that the script would have identified the problem in your case. Nothing more to do until people test on other systems ...
 
Old 10-22-2009, 03:53 PM   #42
{BBI}Nexus{BBI}
Senior Member
 
Registered: Jan 2005
Location: Nottingham, UK
Distribution: Mageia 4
Posts: 4,297

Rep: Reputation: 205Reputation: 205Reputation: 205
Your script now works correctly under Mandriva 2009.1

Code:
 ./usbtest
VirtualBox PUEL version found.  OK.
Name of user used to run VirtualBox: xxx
This computer has udev rules file for VirtualBox, /etc/udev/rules.d/10-vboxdrv.rules.  OK.
No fstab usbfs line found. udev rules are effective.
Group name used for VirtualBox USB access is vboxusers.
Group vboxusers found in /etc/group.  OK.
Here is the group line from /etc/group:
vboxusers:x:501:xxx
User xxx is in group vboxusers/501.  OK.
Access mode used for VirtualBox USB access is 0664.
Access mode (0664) includes 'group write'.  OK.
Kernel module vboxdrv loaded.  OK.
All tests passed.  OK.  :-)
 
Old 10-23-2009, 05:22 AM   #43
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware & Slackware64 14.1
Posts: 7,030
Blog Entries: 52

Rep: Reputation: Disabled
Works for me too:
Code:
brian@SlackB:~/Scripts$ ./ck_vbox_USB.sh
VirtualBox PUEL version found.  OK.
Name of user used to run VirtualBox: brian
This computer has udev rules file for VirtualBox, /etc/udev/rules.d/10-vboxdrv.rules.  OK.
No fstab usbfs line found. udev rules are effective.
Group name used for VirtualBox USB access is vboxusers.
Group vboxusers found in /etc/group.  OK.
Here is the group line from /etc/group:
vboxusers:*:102:brian
User brian is in group vboxusers/102.  OK.
Access mode used for VirtualBox USB access is 0664.
Access mode (0664) includes 'group write'.  OK.
Kernel module vboxdrv loaded.  OK.
All tests passed.  OK.  :-)
 
  


Reply

Tags
configuration, script, usb, virtualbox


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
70+ bug-fixes fro WindowMaker [testers wanted] gnashley Slackware 7 12-12-2009 08:38 AM
LXer: SwapBoost v0.1alpha - early testers wanted LXer Syndicated Linux News 0 07-08-2007 09:46 PM
Wanted: 2.6.20.2 .config for laptop, Please herbietheferret Linux - Kernel 4 04-05-2007 06:23 AM
Beta testers wanted for new distro (IBLS) ico2 Linux - Distributions 4 12-31-2005 07:18 AM
Wanted: A place to UL/DL kernel config files. FallGuy Mandriva 6 11-07-2003 03:38 PM


All times are GMT -5. The time now is 11:26 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration