03 March 2012

91. Downgrading nvidia drivers from 295.20 to 290.10 on debian testing

How to downgrade your nvidia drivers

WARNING -- you must use the terminal during these steps. If you don't know how to use e.g. cd, ls and nano or vim you will want to be careful:
1. Make sure that you have internet access even without a graphical environment
2. Make sure that you have a basic understanding of how to navigate in the terminal
3. Print out or write down these instructions before startintg

I typically test all my instructions on several different computers as a form of proof-reading. For various reasons I can't do that with this blog post, so read through the instructions first to understand what they do and that typos won't throw you off.

If you've been having the gnome-shell crash bug
http://verahill.blogspot.com.au/2012/02/debian-testing-wheezy-64-nvidia-bug.html
[ 7011.967820] gnome-shell[32742]: segfault at 10 ip 00007fa1b6d98c0f sp 00007fa1914a1638 error 6 in libnvidia-tls.so.295.20[7fa1b6d98000+3000]
or the evolution crash bug
http://verahill.blogspot.com.au/2012/02/debian-testing-wheezy-64-no-real.html
[22129.426444] evolution[20435]: segfault at 10 ip 00007f2a05bf8c0f sp 00007f29e5725508 error 6 in libnvidia-tls.so.295.20[7f2a05bf8000+3000]
which are both caused by nvidia driver 295.20, here's how to gracefully downgrade to the previous version of the nvidia driver: 290.10. Be aware that evolution crashes occasionally under 290.10 too, but not nearly as consistently as under 25.20 -- chances are that evolution is a bit buggy on its own.

This will make use of the dkms package, which is what you should use anyway. We'll pull the old stuff from a snapshot archive.

1. Setting up your computer 
I prefer not to be forced to boot into X when I'm mucking about with graphics drivers, so:

Edit your /etc/default/grub
find your
GRUB_CMDLINE_LINUX_DEFAULT
line and add "text" to it e.g.
change
GRUB_CMDLINE_LINUX_DEFAULT="nomodeset nouveau.modeset=0"
to
GRUB_CMDLINE_LINUX_DEFAULT="text nomodeset nouveau.modeset=0"
Do
sudo update-grub

Now is a good time to do a reboot to see if you have internet in text-only mode. 
sudo shutdown -r now
To start your graphical environment again do 
startx


2. Set up snapshot archive
To your /etc/apt/sources.list add this line:
deb http://snapshot.debian.org/archive/debian/20120120T092809Z/ wheezy main contrib non-free
Also, create a
/etc/apt/apt.conf.d/60ignore_repo_date_check
file with the following in it:
Acquire
{
Check-Valid-Until "false";
}
Run
sudo apt-get update
Don't install anything yet.

3. Get the nvidia binary driver
Go to e.g. ~/tmp and
wget http://us.download.nvidia.com/XFree86/Linux-x86_64/290.10/NVIDIA-Linux-x86_64-290.10.run
chmod +x NVIDIA-Linux-x86_64-290.10.run

Don't forget where you put it.

4. Remove your existing drivers and packages:
First reboot:
sudo shutdown -r now
You'll now boot into a text-only environment, so you had better printed this out first.

Then
sudo apt-get autoremove nvidia-*
The following packages will be REMOVED:
  diffstat glx-alternative-mesa glx-alternative-nvidia glx-diversions libcublas4 libcuda1 libcudart4 libcufft4
  libcurand4 libcusparse4 libgl1-nvidia-alternatives libgl1-nvidia-glx libglx-nvidia-alternatives libnpp4
  libthrust-dev libvdpau-dev nvidia-alternative nvidia-glx nvidia-installer-cleanup nvidia-kernel-common
  nvidia-kernel-dkms nvidia-support nvidia-vdpau-driver opencl-headers quilt xserver-xorg-video-nvidia
0 upgraded, 0 newly installed, 26 to remove and 3 not upgraded.
After this operation, 435 MB disk space will be freed.
Do you want to continue [Y/n]?Y
[..]
Reboot for good luck:
sudo shutdown -r now

If you do
locate nvidia.ko
chances are you'll find
/lib/modules/3.2.9/updates/dkms/nvidia.ko
where 3.2.9 is the current kernel version.

Do
sudo updatedb
locate nvidia.ko
to make sure that the nvidia.ko is gone from your current kernel.

5. Install your old nvidia driver:
Go to the directory you downloaded the driver in, e.g. ~/tmp
sudo ./NVIDIA-Linux-x86_64-290.10.run
Reboot afterwards:
sudo shutdown -r now

After the reboot do
startx

Did it work? If yes, you're in good shape.
 dmesg | grep nvidia
[    7.540166] nvidia: module license 'NVIDIA' taints kernel.
[    8.509525] nvidia 0000:01:00.0: PCI INT A -> GSI 18 (level, low) -> IRQ 18
[    8.509600] nvidia 0000:01:00.0: setting latency timer to 64
6. Setting up the kernel-dkms
You really want to use dkms so that you don't have re-install the graphics driver each time you upgrade your kernel.

First check
apt-cache showpkg nvidia-kernel-dkms
Provides:
295.20-1 - nvidia-kernel-295.20
290.10-1 - nvidia-kernel-290.10
195.36.31-6 - nvidia-kernel-195.36.31

OK, time to get rocking:
sudo apt-get install nvidia-kernel-dkms=290.10-1 nvidia-glx=290.10-1 libgl1-nvidia-glx=290.10-1 xserver-xorg-video-nvidia=290.10-1 nvidia-vdpau-driver=290.10-1 nvidia-alternative=290.10-1

You'll be warned about remove nvidia-install etc. That's fine.

Once the installation is done it's time to put holds on the packages so they don't accidentally upgrade

sudo su
echo "nvidia-kernel-dkms hold"| dpkg --set-selections
echo "nvidia-glx hold"| dpkg --set-selections
echo "libgl1-nvidia-glx hold"| dpkg --set-selections
echo "xserver-xorg-video-nvidia hold"| dpkg --set-selections
echo "nvidia-vdpau-driver hold"| dpkg --set-selections
echo "nvidia-alternative hold"| dpkg --set-selections
exit

7. Cleaning up
Things to do:
a. comment out the snapshot in /etc/apt/sources.list
b. move the /etc/apt/apt.conf.d/60ignore_repo_date_check file out of the way
c. sudo apt-get upgrade
Reading package lists... Done
Building dependency tree    
Reading state information... Done
The following packages have been kept back:
  libgl1-nvidia-glx nvidia-alternative nvidia-glx
  nvidia-kernel-dkms nvidia-vdpau-driver xserver-xorg-video-nvidia
d. edit your /etc/default/grub and remove the "text" item you added.
e. Run sudo update-grub
f. You can now reboot and your computer will be back to normal, sans nvidia 295.20

DONE



8. In the future
Once it is safe to upgrade, all you need to do is

sudo su
echo "nvidia-kernel-dkms install"| dpkg --set-selections
echo "nvidia-glx install"| dpkg --set-selections
echo "libgl1-nvidia-glx install"| dpkg --set-selections
echo "xserver-xorg-video-nvidia install"| dpkg --set-selections
echo "nvidia-vdpau-driver install"| dpkg --set-selections
echo "nvidia-alternative install"| dpkg --set-selections
exit
sudo apt-get update && sudo apt-get upgrade

Links to this post:
http://www.pro-chip.de/linux-mint/161-linux-mint-debian-geforce-gtx-560-ti-treiberproblem.html

02 March 2012

90. Compiling kernel 3.2.9 on Debian Testing

UPDATE: the instructions below work without modification with kernel v 3.2.9

For a more exhaustive description of how to build a kernel for debian, see here:
http://verahill.blogspot.com.au/2012/02/debian-testing-building-your-own-linux.html

I'll be brief:
You need 6.6 Gb of free space to build, and a fair amount of free time.


sudo apt-get install kernel-package fakeroot
wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.9.tar.bz2
tar -xvf linux-3.2.9.tar.bz2 
cd linux-3.2.9/
cat /boot/config-`uname -r`>.config
make oldconfig
make-kpkg clean


-- apply to 32 bit only --
ln -s /home/me/tmp/linux-3.2.9/Documentation/virtual/lguest  Documentation/lguest
-- for 32 bit only end --


fakeroot make-kpkg -j4 --initrd --revision=3.2.9 kernel_image kernel_headers

where 4 is the number of cores(3)+1 (e.g. quadcore gives 5)
wait....wait...wait...takes a while...wait...wait...


mv ../linux*3.2.9*.deb .
sudo dpkg -i *.deb

Done. 
Linux tantalum 3.2.9 #1 SMP Fri Mar 2 15:21:59 EST 2012 x86_64 GNU/Linux

Minor note: Navigating Kernel.org


Each minor version has a stable release -- for 3.2.X it was 3.2.8 until 3.2.9 was released. Given that 3.3 is in the works, 3.2.9 will be the stable version of the 3.2 minor version.
"Full source" is the full kernel source, which is what we used in the example above. "Patch" is the difference between the previous version and the current version e.g. 3.2.8 vs 3.2.9 -- there's more information here. You can save both bandwidth and compile time by patching instead of doing a full download.




Build times:
Intel Celeron 32 bit (1.6 GHz)
still waiting...

AMD Athlon II X3 using -j4
real    44m56.522s
user    75m52.633s
sys     12m7.241s
Intel i5-2400 using -j5
real 22m26.712s
user 50m23.289
  sys 6m1.111s
AMD Phenom II X7 using -j7
real 28m46.599s
user 81m0.108s
sys 12m57.825s




01 March 2012

89. Compiling kernel 3.2.8 on Debian Testing -- example using kernel-packages and kernel.org source

For kernel 3.2.9, see here: http://verahill.blogspot.com.au/2012/03/debian-testing-kernel-329.html

Following: http://www.linuxplanet.com/linuxplanet/tutorials/6853/1 and http://www.sysdesign.ca/guides/linux_kernel.html  and very much http://old-releases.ubuntu.com/ubuntu/dists/hoary/main/installer-ia64/current/doc/manual/en/ch08s04.html

Update: added kernel_headers

I've added very litte to the guides, except proving that yes, the above tutorial works for the current stable kernel version (3.2.8) and the current debian testing (29/12/2012).

Here's what's new in 3.2.8 -- https://lwn.net/Articles/484042/
Here's what will be new in 3.3 -- http://www.h-online.com/open/features/Kernel-Log-Linux-3-3-goes-into-testing-1418516.html

Everything between SAFE START and END are ok -- they won't change anything serious on your system. If you're building on a 32 bit system, have a look at the end of the post before launching the make.

--  SAFE START --
Install tools:
sudo apt-get install kernel-package fakeroot
(if you use apt-bugs you may get a warning about an lguest bug. Ignore it. Look at the bottom of the post for 32 bit issues and a simple solution.)


Get the latest STABLE release from http://kernel.org/
wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-3.2.8.tar.bz2
It's 75 M and will take a wee while.
tar -xvf linux-3.2.8.tar.bz2
cd linux-3.2.8/

To get a head-start on a configuration file, see if you have one for your current kernel:
ls /boot/config-`uname -r`

If so (I know this is clunky, but the obvious solutions didn't work...)
echo "/boot/config-`uname -r` "|xargs cat > .config

I'm running 3.2.0-1.

Alright. Here's the thing. You shouldn't edit .config unless you know what you're doing. But then how will you ever learn? I don't yet know what I'm doing, so won't lead you into kernel-configuration related temptation.

Instead, we'll just learn how to build.

First
make oldconfig
which uses the .config

But it's not completely automatic -- when it comes to new features you'll have to provide input. Hitting enter i.e. accepting the default option is probably a good idea unless you think otherwise.

Alternatively, you do
make menuconfig
and pick everything you want


Here are the new features in 3.2.8 vs 3.2.0-1: 
  Cirrus Logic (Sound Fusion) New DSP support (SND_CS46XX_NEW_DSP) [Y/n/?] (NEW)
Agere Systems HERMES II Wireless PC Card Model 0110 (WLAGS49_H2) [N/m/?] (NEW)
 Linksys HERMES II.5 WCF54G_Wireless-G_CompactFlash_Card (WLAGS49_H25) [N/m/?] (NEW) 
Y means compile into kernel, m makes a loadable module and no means no.

Now build!
make-kpkg clean
The next step takes forever, in particular if you only use one core (>1 h). It takes ca 50 minutes on an i5 with the -j5 switch. You'll also need around 6.5 Gb of free space for the compilation.
fakeroot make-kpkg -j4 --initrd --revision=3.2.8 kernel_image kernel_headers

where as usual 4 is the number of cores(3)+1. Adjust as necessary.

--SAFE END--

This really isn't dangerous, although you may not want to do it remotely without a back-up plan.

Install with
sudo dpkg -i ../linux-image-3.2.8_3.2.8_amd64.deb
sudo dpkg -i ../linux-headers-3.2.8_3.2.8_amd64.deb

That's it! You don't even have to bother with update-grub.

Reboot at your convenience and admire your handiwork:
uname -a

Linux boron 3.2.8 #2 SMP Wed Feb 29 19:27:04 EST 2012 x86_64 GNU/Lin

The deb built this way is ca 33 M, while the stock debian 3.2.0--1 is a slim 23 M.

Once you're confident that you can compile and install a kernel without mishap you can start to remove kernel modules to make it slimmer -- or start including modules of your own choosing.


Tried and tested on:
AMD Athlon II X3 (64 bit)
2 x AMD Phenom II X6 (64 bit)
Intel i5-2400 (64 bit)
Intel core 2  duo T5870 (laptop, 64 bit)
Intel Celeron 1.6 GHz (32 bit)
-- all running debian testing.


Building on 32 bit

I had some issues on an Intel Celeron 1.6 GHz 32 bit due to a bug:
make[1]: Leaving directory `/home/me/tmp/linux-3.2.8'
/usr/bin/make    ARCH=i386 \
    -C Documentation/lguest
make: *** Documentation/lguest: No such file or directory.  Stop.
make: *** [debian/stamp/build/kernel] Error 2

The failure was pretty annoying...
real 157m58.192s
user 132m27.049s
sys 12m5.589s
There's a simple solution in a forum post at http://billy.com.mx/archives/660:

"I solved it by creating a symlink Documentation/lguest to Documentation/virtual/lguest"
that means (on one line)
ln -s /home/me/tmp/linux-3.2.8/Documentation/virtual/lguest  Documentation/lguest


That's all.


Check:
ls Documentation/lguest -lah
Documentation/lguest -> /home/me/tmp/linux-3.2.8/Documentation/virtual/lguest

ls Documentation/lguest/
extract  lguest.c  lguest.txt  Makefile

And once it's installed:
uname -a
Linux kookaburra 3.2.8 #3 SMP Thu Mar 1 14:43:45 EST 2012 i686 GNU/Linu


Modules
To get a list over the modules in use on your current system:
lsmod | gawk '{printf("%s ",$1)}'| sed 's/Module//g'

zlib_deflate crc32c libcrc32c ufs qnx4 hfsplus hfs minix ntfs vfat msdos fat jfs xfs reiserfs ext3 jbd ext2 pci_stub vbok8 mperf cpufreq_stats cpufreq_conservative cpufreq_powersave cpufreq_userspace ppdev bnep rfcomm bluetooth binfmt_misc as nfs_acl sunrpc kvm_amd kvm xt_state ipt_REJECT ipt_LOG xt_limit xt_tcpudp xt_conntrack iptable_mangle ipt_MASQUERADE ip
le_filter ip_tables x_tables hwmon_vid lp loop snd_hda_codec_hdmi arc4 rt2800usb rt2800lib crc_ccitt rt2x00usb rt2x00lib xer_oss snd_usb_audio snd_pcm snd_hwdep snd_usbmidi_lib nvidia hid_logitech_dj mac80211 joydev snd_seq_midi cfg80211 rfki5100_tco snd_timer snd_seq_device edac_core edac_mce_amd parport_pc parport snd i2c_piix4 soundcore pcspkr k10temp i2c_combcache jbd2 crc16 usb_storage uas sd_mod crc_t10dif ata_generic pata_atiixp ohci_hcd thermal thermal_sys floppy ahci lib
You can use that as a source of inspiration for what to keep and what to trim.