Bumblebee error in ubuntu 13.10

I installed bumblebee couple times in ubuntu 13.10,12.04 but now it's not working for ubuntu 13.10. I followed the instruction here (including nvidia-319-updates). When i try to run optirun it shows errors.

$optirun -vv firefox
[   37.843018] [DEBUG]Reading file: /etc/bumblebee/bumblebee.conf
[   37.843234] [INFO]Configured driver: nvidia
[   37.843318] [DEBUG]optirun version 3.2.1 starting...
[   37.843325] [DEBUG]Active configuration:
[   37.843328] [DEBUG] bumblebeed config file: /etc/bumblebee/bumblebee.conf
[   37.843331] [DEBUG] X display: :8
[   37.843333] [DEBUG] LD_LIBRARY_PATH: /usr/lib/nvidia-319-updates:/usr/lib32/nvidia-319-updates
[   37.843336] [DEBUG] Socket path: /var/run/bumblebee.socket
[   37.843339] [DEBUG] Accel/display bridge: auto
[   37.843342] [DEBUG] VGL Compression: proxy
[   37.843344] [DEBUG] VGLrun extra options: 
[   37.843347] [DEBUG] Primus LD Path: /usr/lib/x86_64-linux-gnu/primus:/usr/lib/i386-linux-gnu/primus
[   37.863100] [DEBUG]Using auto-detected bridge primus
[   38.752137] [INFO]Response: No - error: [XORG] (EE) Failed to load /usr/lib/xorg/modules/libglamoregl.so: /usr/lib/xorg/modules/libglamoregl.so: undefined symbol: _glapi_tls_Context

[   38.752152] [ERROR]Cannot access secondary GPU - error: [XORG] (EE) Failed to load /usr/lib/xorg/modules/libglamoregl.so: /usr/lib/xorg/modules/libglamoregl.so: undefined symbol: _glapi_tls_Context

[   38.752158] [DEBUG]Socket closed.
[   38.752171] [ERROR]Aborting because fallback start is disabled.
[   38.752176] [DEBUG]Killing all remaining processes.

I purge/install bumblebee, nvidia-319-updates etc couple of times but no luck. dmesg message after start bumblebee.

[   38.020998] nvidia: module license 'NVIDIA' taints kernel.
[   38.021003] Disabling lock debugging due to kernel taint
[   38.027124] [drm] Initialized nvidia-drm 0.0.0 20130102 for 0000:04:00.0 on minor 1
[   38.027131] NVRM: loading NVIDIA UNIX x86_64 Kernel Module  319.60  Wed Sep 25 14:28:26 PDT 2013
[   38.752497] vgaarb: this pci device is not a vga device
[   38.778036] NVRM: failed to copy vbios to system memory.
[   38.780897] NVRM: RmInitAdapter failed! (0x30:0xffffffff:711)
[   38.780907] NVRM: rm_init_adapter(0) failed
[  334.417657] bbswitch: version 0.7
[  334.417663] bbswitch: Found integrated VGA device 0000:00:02.0: \_SB_.PCI0.GFX0
[  334.417670] bbswitch: Found discrete VGA device 0000:04:00.0: \_SB_.PCI0.RP05.PXSX
[  334.417682] bbswitch: failed to evaluate \_SB_.PCI0.RP05.PXSX._DSM {0xF8,0xD8,0x86,0xA4,0xDA,0x0B,0x1B,0x47,0xA7,0x2B,0x60,0x42,0xA6,0xB5,0xBE,0xE0} 0x100 0x0 {0x00,0x00,0x00,0x00}: AE_NOT_FOUND
[  334.417689] bbswitch: failed to evaluate \_SB_.PCI0.RP05.PXSX._DSM {0xA0,0xA0,0x95,0x9D,0x60,0x00,0x48,0x4D,0xB3,0x4D,0x7E,0x5F,0xEA,0x12,0x9F,0xD4} 0x102 0x0 {0x00,0x00,0x00,0x00}: AE_NOT_FOUND
[  334.417700] bbswitch: failed to evaluate \_SB_.PCI0.GFX0._DSM {0xA0,0xA0,0x95,0x9D,0x60,0x00,0x48,0x4D,0xB3,0x4D,0x7E,0x5F,0xEA,0x12,0x9F,0xD4} 0x102 0x0 {0x00,0x00,0x00,0x00}: AE_NOT_FOUND
[  334.417701] bbswitch: No suitable _DSM call found.

bumblebee.conf

# Configuration file for Bumblebee. Values should **not** be put between quotes

## Server options. Any change made in this section will need a server restart
# to take effect.
[bumblebeed]
# The secondary Xorg server DISPLAY number
VirtualDisplay=:8
# Should the unused Xorg server be kept running? Set this to true if waiting
# for X to be ready is too long and don't need power management at all.
KeepUnusedXServer=false
# The name of the Bumbleblee server group name (GID name)
ServerGroup=bumblebee
# Card power state at exit. Set to false if the card shoud be ON when Bumblebee
# server exits.
TurnCardOffAtExit=false
# The default behavior of '-f' option on optirun. If set to "true", '-f' will
# be ignored.
NoEcoModeOverride=false
# The Driver used by Bumblebee server. If this value is not set (or empty),
# auto-detection is performed. The available drivers are nvidia and nouveau
# (See also the driver-specific sections below)
Driver=nvidia
# Directory with a dummy config file to pass as a -configdir to secondary X
XorgConfDir=/etc/bumblebee/xorg.conf.d

## Client options. Will take effect on the next optirun executed.
[optirun]
# Acceleration/ rendering bridge, possible values are auto, virtualgl and
# primus.
Bridge=auto
# The method used for VirtualGL to transport frames between X servers.
# Possible values are proxy, jpeg, rgb, xv and yuv.
VGLTransport=proxy
# List of paths which are searched for the primus libGL.so.1 when using
# the primus bridge
PrimusLibraryPath=/usr/lib/x86_64-linux-gnu/primus:/usr/lib/i386-linux-gnu/primus
# Should the program run under optirun even if Bumblebee server or nvidia card
# is not available?
AllowFallbackToIGC=false


# Driver-specific settings are grouped under [driver-NAME]. The sections are
# parsed if the Driver setting in [bumblebeed] is set to NAME (or if auto-
# detection resolves to NAME).
# PMMethod: method to use for saving power by disabling the nvidia card, valid
# values are: auto - automatically detect which PM method to use
#         bbswitch - new in BB 3, recommended if available
#       switcheroo - vga_switcheroo method, use at your own risk
#             none - disable PM completely
# https://github.com/Bumblebee-Project/Bumblebee/wiki/Comparison-of-PM-methods

## Section with nvidia driver specific options, only parsed if Driver=nvidia
[driver-nvidia]
# Module name to load, defaults to Driver if empty or unset
KernelDriver=nvidia-319-updates
PMMethod=auto
# colon-separated path to the nvidia libraries
LibraryPath=/usr/lib/nvidia-319-updates:/usr/lib32/nvidia-319-updates
# comma-separated path of the directory containing nvidia_drv.so and the
# default Xorg modules path
XorgModulePath=/usr/lib/nvidia-319-updates/xorg,/usr/lib/xorg/modules
XorgConfFile=/etc/bumblebee/xorg.conf.nvidia

## Section with nouveau driver specific options, only parsed if Driver=nouveau
[driver-nouveau]
KernelDriver=nouveau
PMMethod=auto
XorgConfFile=/etc/bumblebee/xorg.conf.nouveau

xorg.bumbleebee.nvidia

Section "Device"
    Identifier  "DiscreteNvidia"
    Driver      "nvidia"
    VendorName  "NVIDIA Corporation"
    BusID "PCI:04:00:0" #changed to 04:00.0 but no luck. So revert back.

lspci

04:00.0 3D controller: NVIDIA Corporation GK208M [GeForce GT 740M] (rev a1)

At last i found the solution. I am posting it for future reference.

There are two problem.

1. bbswitch
2. nvidia-driver

ubuntu 13.10 is using 3.11.x kernel and bbswitch is not working in 3.8 to 3.11. It's kernel issue(according to blogs) and fixed in >= 3.12. I solved bbswitch problem by upgrading my kernel to 3.12.6. here

nvidia-304, nvidia-319 is not working in ubuntu 13.10. I am telling this because i run my card(740M) with nvidia-319 in 13.04. You have to install nvidia-331. This is a useful reference, how to install bumblebee with nvidia-331.