Posted on Mar 6, 2006

Ubuntizing my PC – Part 2

In my last post, I wrote about how I installed Ubuntu on my old PII 266. It had a DLink DWL510 PCI card installed on it, but the card was not detected by Ubuntu on installation.

This blog is on my weekend project to get the WLAN card working so that I could connect to my home WiFi and the Internet from the PC.

Saturday:

I sat down to get the card working on Saturday afternoon, and was hoping to get it working by evening.

1. The first step was to run ‘lspci -v’ to see if the card was detected. It was detected as a RaLink device, was listed as ‘not recognized’. Most likely, the driver was missing. Ralink 2500 drivers are auto-detected in Ubuntu 5.10, so I wonder what went wrong. None of the searches I did turned up information suggesting that DLink used another RaLink chipset, and I assumed (Bummer 1) that my card had the same 2500 chipset. I could have quickly confirmed this by checking the Windows driver CD that came with the card, but I did not care.

2. The next logical step was to use NdisWrapper. This is a common driver that implements a wrapper for Windows NDIS (Network Driver Interface Specification) API over Linux kernel so that Windows drivers can run over the Linux kernel. I downloaded ndiswrapper v1.10 using my laptop and copied it over to the PC using a CD.

3. A search in the Ubuntu forum gave a good tutorial on setting up ndiswrapper. First thing to do was to get the linux kernel headers, gcc and make. The Synaptic Package Manager (SPM) that comes with Ubuntu is pretty good – it is very similar to the package manager that comes with Cygwin. A couple clicks, and I had installed all required components.

4. Ran ‘make install’ in ndiswrapper source folder – and here comes the first error: gcc-3.4 not found. Checked SPM, but gcc 3.4 does not come with the Ubuntu install CD. What I had was gcc 4.0. Assuming that gcc-4.0 should not be too different from gcc-3.4, I did the following (Bummer 2).

cd /usr/binsudo ln -s gcc-4.0 gcc-3.4

Ran ‘make install’ again, and the error went away.

5. Next error: “error: loadndisdriver.c:error:stdlib.h: no such file or directory”. A quick google search revealed that these are part of the glbc package. ‘glibc’ source and related header are not available with SPM, only the binaries are there with libglib. So I downloaded glbc package for Breezy from Ubuntu site, and copied it to the PC.

6. Ran ./configure in glibc source folder, and it failed with the error “compiler cannot create executable”. config.log gave the actual error as ‘crt1.o not available’. Another google search – libc6-dev needs to be installed. Fortunately, SPM has this package.

7. Ran ./configure again, and it failed with the next error: ‘error: you must have gettext support in your C library or use the GNU gettext library’. SPM has gettext also, and configure succeeded after installing it.

8. Ran ‘make’ and ‘make install’ in glibc source folder, and they went quite well.

9. Ran ‘make install’ again in ndiswrapper source folder, and the driver built successfully.

10. Now, I have to install the Windows driver with ndiswrapper. I loaded the DLink driver CD in the CD drive and checked the driver, and it was showing up as rt61. I had not heard about this chipset so I thought I will do a quick google search on it. Surprise! I should have checked this earlier – RaLink is providing a native open-source Linux driver for rt61 chipset (also called rt2561). So I dropped ndiswrapper and set about getting the native driver to work.

11. I downloaded the rt61 drivers from RaLink, and copied them over to the PC. The ‘readme’ file in the source folder is pretty good and contains clear instructions on building and installing the driver – though not specific to Ubuntu.

12. I have a 2.6 kernel, so I used the appropriate Makefile, and ran ‘make all’ – the driver built successfully.

13. The next step was to run dos2unix on the driver config file (rt2561.dat), but I did not have dos2unix. It is a part of the sysutils package, which does not come with SPM, so I downloaded and copied it to the PC. sysutils is not a single package, but it contains multiple packages – tofrodos (fromdos exactly) is the one to be used instead of dos2unix, and I ran that.

14. Then I inserted the driver using ‘insmod rt61.ko’, and boom came the error! – error: invalid module format. This essentially means that the headers used for building the kernel and the driver are different, but I was not really sure what went wrong. Web searches did not give anything conclusive either.

15. But there is an unofficial version of the rt61 drivers that was available on the internet. I downloaded them, and copied them to the PC. The following steps went well:

makecopy *.ko /lib/modules/`uname -r`/depmode -amodprobe rt2561.ko

Again the same error – invalid module format. :-(

16. This was unfortunate, and I decided to go back to ndiswrapper – after all, I was almost done on that.

cd /cdrom/drivers/driver/sudo ndiswrapper -i rt61.infsudo ndiswrapper -l

Good – it shows that the driver is present and that the hardware is up and running.

sudo modprobe ndiswrapper

Damn! The same error – invalid module format.

17. There is something that I am missing here – so I ran ‘sudo dmesg’ (should have done that before), and examined the output. That cat was out of the bag – ‘version magic 2.6.12-9-386 386 gcc-4.0′ should be ‘version magic 2.6.12-9-386 386 gcc-3.4′ – the breezy kernel is compiled with gcc 3.4. So I should have installed gcc 3.4 instead of linking it to gcc 4.0. And this is why even the native drivers did not work.

But this is crazy! gcc-3.4 should have been bundled with the install CD if drivers lunked to kernel needed to be compiled with it. Bundling just gcc-4.0 and then expecting people to download gcc-3.4 for compiling drivers is not a good idea.

18. Binaries for gcc-3.4 and other dependancies can be downloaded from Ubuntu web site, but I did not want to get into another round of compat issues, so I decided to download the source and build it. ‘configure’ went well, but I did not select specific components to build (Bummer 3), so the build just went on and on, building Java libraries and a lot of other stuff that I am not sure I needed. At 2am on Sunday morning, I decided to call it quits for the day.

Sunday:

19. The gcc 3.4 build was over by 10am. Ran ‘make install’ and installed gcc-3.4 into /usr/local/bin. It would be safer to have ‘gcc’ default to 3.4 with the kernel built with 3.4.

20. Go to the native rt61 driver, ‘make clean’ and repeated the steps. ‘insmod rt61.ko’, and the interface shows up in ‘ifconfig -a’. Great!.

21. Now I got over-enthusiastic, and took the Network Configuration applet that comes with the Gnome Desktop without reading the driver ‘readme’ file (Bummer 4!). Configured ssid, wep key, and dhcp – whoah! the machine just froze!.

22. Restarted the machine.

copy rt61.ko /lib/modules/`uname -r`/ (Bummer 5!)sudo depmode -asudo insmod rt61.ko

ra0 interface is available now. Used the network config applet to configure ssid, wep key, and a static ip address – but ping to my Wireless router fails. Then I configured dhcp again, and the machine froze again.

23. After this, it was real fun. Every attempt to re-boot will cause a hang at the point where the network interfaces was being configured. Doing a Ctrl-C will cause the boot to proceed, but all ‘sudo’ operations get stuck, so no chance to remove the faulty driver from start-up.

24. Tried loading with the Live CD (oh, the pain! :-( ), but could not access the hard disk partitions. After two hours of re-boots and struggles to access the hard disk from the Live CD, I gave up and went down for lunch and watched the India-England cricket match fizzling out to a draw.

25. Then came the flash! There has to be a recovery mode with Ubuntu. I booted up the PC – and there was the Grub menu which would pop up if you press ESC on boot up. There was a recovery mode there – how come I missed it earlier! Boot into the recovery mode, and I am in, with root access.

26. Removed the driver from startup list, and checked the readme file for the driver. It mentions different ways of configuring the card, but the config applet is not among them. So I edit the config file and add ssid, key etc., and re-insert the driver.

‘sudo iwlist ra0 scan’ does not display any AP. After juggling the iwlist and iwconfig for almost an hour, I give up.

27. Removed the native driver, installed the Windows driver using ndiswrapper and tried – same problem – the AP is not seen. It was detected a couple of times in between, but the connection got dropped in a matter of seconds. So I moved back to the native driver.

28. I guess that the problem is with conflict between the driver config file and some existing config so I checked the /etc/network/interfaces. There are some configs for ra0 – IP address, ssid, key etc. – there from my earlier attempts with the network config applet. I removed them and re-inserted the driver – and voila! the AP shows up in the iwlist scan. But for some reason, the ssid etc. are not set in iwconfig. I try to set the id and key explicitly using iwconfig, but no luck. Then I tried to force associate the card by giving ‘iwconfig ra0 ap _ap_mac_ – it is associated. I am able to ping the router, so I added a DNS entry in ‘resolve.conf’ and pinged ‘www.google.com’. That works as well. I quickly pull up Firefox and type ‘www.google.com’ – no luck. Issue ‘iwconfig’ again, the card is not associated. But the AP does show up in the iwlist scan. Repeated attempts to force the card to associate with the AP as before does not work.

So near, yet so far!

29. By now, I had given up on DHCP, so I was using static IP addresses after configuring my router for static DHCP (so that it would continue to work with mine and my wife’s laptops which were configured for DHCP).

30. Probably, loading the card on boot-up would make it work. So I copied rt2561.ko to the start-up modules list, and added an entry to /etc/modprobe.d/ (this is different from the instruction in the driver readme file which asks this entry to be made in modules.conf file), restarted the machine and crossed my fingers.

30. Issued ‘ifconfig -a’ on boot-up, the interface was there, and the IP was configured. ‘iwlist scan’ output showed the AP. But ‘iwconfig’ showed that the card was not associated. :-( I was at my wit’s end now and like all such unfortunate folks, I began to hope for some magic or miracle. I re-inserted the driver many times, re-booted repeatedly, but to no avail.

31. It was 10.30 pm, it was the end of my weekend, Nisha was cross with me for a spoiled weekend though she was trying her best not to show it, I could not take Safdar out as I had planned, train tickets that I had promised my father to book were still un-booked, and the Wireless card was not working. Time to sleep, to forget, to promise myself and Nisha that I would not work on this during the weekdays – at least.

Monday:

32. Went up to reserve train tickets for my father on irctc.com. The PC is sitting there, as the symbol of my defeat. I think that I should try one more thing – remove the driver from boot, write a script to insert the driver and configure it, and run the script exlicitly during start-up. Let me try just this one step – and I booted the PC up.

ifconfig -a

Interface ra0 shows up, IP is configured.

sudo iwlist ra0 scan

AP shows up

iwconfig ra0

Surprise! The card is associated!

ping 192.168.0.1 (router)

Ping works!

Start Firefox, type www.google.com

Whoah! It works! Yahoo!

I browsed for 15 minutes, and re-booted the PC. It works well.

So what went wrong on Sunday? I do not know.

It just needs a good night’s sleep – almost always!

PS: I assume that the card had gone into some race condition during the repeated experiments with the multiple options in iwconfig. And the quick reboot using the restart button probably did not really power it down.