Category Archives: Linux/Unix

Nvidia driver on Ubuntu 13.10

I made the mistake to try to switch from the Nvidia driver to use the hybrid Bumblebee driver on Ubuntu 13.10 for my Lenovo T420s laptop with NVIDIA GPU NVS 4200M (GF119). I ended up with a situation where I couldn’t get the Nvidia driver working again. I had to switch back to the default Nouveau driver. I don’t remember the exact steps, but I did roughly the following:

sudo apt-get remove bumblebee nvidia-319-updates
sudo apt-get install xserver-xorg-video-nouveau
sudo dpkg-reconfigure xserver-xorg

This got me back to the Nouveau driver, but that didn’t support my external display on the Displayport, so I was eager to get the Nvidia driver working again.


sudo apt-get remove xserver-xorg-video-nouveau
sudo apt-get install nvidia-319
sudo dpkg-reconfigure xserver-xorg

But when I reboot it looked like the X server would start up, but it crashed and dropped to a shell before the login screen. Checking the logs I found that there was an issue loading the Nvidia kernel module. To make a long story short, I did the following the get the Nvidia driver working again. I’m not sure which step that actually made the difference.


sudo vi /etc/modprobe.d/blacklist.conf

add

#Problem getting Nvidia to work
blacklist nouveau

I found some remnants of Bumblebee, which possible caused some issues with kernel modules, since it blacklists Nvidia:


less /etc/modprobe.d/bumblebee.conf

So to get rid of it I did the following:
sudo apt-get purge bumblebee
Purge will delete configuration files, including bumblebee.conf.

I got to the login screen after a reboot, which was a step forward. However, trying to login failed and I got back to the login screen. Turns out that .Xauthority had incorrect permissions. Fix the ownership or just delete it.


cd
sudo rm .Xauthority

Finally running with Nvidia driver again!

Check Java version in class files

Java classes can be compiled for different target platforms. You could e.g. compile with JDK 7 creating class files for Java 6. The target version is encoded in the beginning of the class files.

The major version of the different Java releases are:
Java 8 = 52 (0x34)
Java 7 = 51 (0x33)
Java 6 = 50 (0x32)
Java 5 = 49 (0x31)

So the class files for Java 6 starts with

0xCA 0xFE 0xBA 0xBE 0x00 0x00 0x00 0x32

We can use the following command to find e.g. all Java 6 classes.

find . -name \*.class -exec grep -P "^\xca\xfe\xba\xbe\x00\x00\x00\x32" {} \;

Or better still, just checking first line:
find . -name \*.class -exec sh -c 'head -1 {} | grep -P "^\xca\xfe\xba\xbe\x00\x00\x00\x32" {}' \;

However, it might be more interesting to find if any of the files we compile is NOT Java 6. This might happen when compiling with JDK 7, but forgetting to set Java 1.6 as target.

find . -name \*.class -exec sh -c 'head -1 {} | grep -v -q -P "^\xca\xfe\xba\xbe\x00\x00\x00\x32" && echo "Java version is not 0x32 in file {}" &' \;

Java encoding of source files

I got a problem with some java source files, which javac couldn’t compile, because the file encoding was correct. The source files did include some Swedish UTF-8 characters.

unmappable character for encoding ASCII

So I checked what my ant environment looked like:

$ ant -diagnostics|grep encoding
file.encoding.pkg : sun.io
sun.jnu.encoding : ANSI_X3.4-1968
file.encoding : ANSI_X3.4-1968
sun.io.unicode.encoding : UnicodeLittle

Definitely not the UTF-8 encoding I desired.

Checked my environment

$ locale
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=en_US:
LC_CTYPE=”en_US.UTF-8″
LC_NUMERIC=sv_SE.UTF-8
LC_TIME=sv_SE.UTF-8
LC_COLLATE=”en_US.UTF-8″
LC_MONETARY=sv_SE.UTF-8
LC_MESSAGES=”en_US.UTF-8″
LC_PAPER=sv_SE.UTF-8
LC_NAME=sv_SE.UTF-8
LC_ADDRESS=sv_SE.UTF-8
LC_TELEPHONE=sv_SE.UTF-8
LC_MEASUREMENT=sv_SE.UTF-8
LC_IDENTIFICATION=sv_SE.UTF-8
LC_ALL=

And then:

$ locale -a
C
C.UTF-8
en_AG
en_AG.utf8
en_AU.utf8
en_BW.utf8
en_CA.utf8
en_DK.utf8
en_GB.utf8
en_HK.utf8
en_IE.utf8
en_IN
en_IN.utf8
en_NG
en_NG.utf8
en_NZ.utf8
en_PH.utf8
en_SG.utf8
en_US.utf8
en_ZA.utf8
en_ZM
en_ZM.utf8
en_ZW.utf8
POSIX

Notice that sv_SE.UTF-8 is missing.

$ sudo locale-gen sv_SE.UTF-8

$ sudo dpkg-reconfigure locales

Check java file encoding again:

$ ant -diagnostics|grep encoding
file.encoding.pkg : sun.io
sun.jnu.encoding : UTF-8
file.encoding : UTF-8
sun.io.unicode.encoding : UnicodeLittle

I’m running Ubuntu 12.04 Server and the previous command worked fine the other day. I guess that there was some Ubuntu update which destroyed my environment.