Rough Book

random musings of just another computer nerd

Tag: freebsd

My data-recovery story

I was looking through wayback machine at snapshots of my website, when I came across one from 2005. It reminded me of something I had almost forgotten. At some point in 2005, the network card in my FreeBSD server started to die. I got myself a new card and set about replacing the dying one. I can’t recall why anymore, but I guess I had needed to disconnect the hard-drive at some point. I remember that after I plugged it back in and booted up, I was greeted by a screenful of terrifying error-messages. Something horrible had happened to the drive that held my home directory, my website source-code, and my database. I had lost about 6 years worth of posts and images on my website. My first instinct was to power down the machine to prevent anything more being written to the drive, which I immediately did. After that I think I tried a bunch of disk-recovery tools to try and recover my data. But this was difficult because the filesystem was UFS. I can’t remember if there were any UFS recovery tools at the time, or if I tried them, but I remember having tried almost everything I could think of.

Out of desperation, I think I finally decided to use dd. I started dumping the data from the drive using the lowest size-setting possible in dd (I want to say it is a byte, but I don’t really remember). I then piped this into a perl script that would examine each byte, looking for magic numbers. The drive had been corrupted so badly that there wasn’t even any trace of a coherent filesystem anymore. I knew that the data I was getting were most-probably fragmented, but I didn’t care at this point. I would guess the file-type by looking for magic numbers, and then I would start dumping that data into a file until I found an ending marker, or if the file-type didn’t have one, until the start of another magic number. I remember having various settings in the script so that I could tune its behavior, especially when dealing with false positives. My priority was to retrieve my pictures, website, programming projects, and database. For my source-code I only had to look for ASCII data. For pictures I looked for file markers for JPG, PNG, and GIFs. The database was difficult though, because I was using MySQL. By sheer chance, I had decided to take a SQL dump of my website’s database the day before for backup purposes (ironically, on the very drive that would die the next day). This was ASCII data, and so it was one of the first things my script found.

I ran this script over a couple of hours I think, and then for most of the next day for good measure. Then I began the tedious process of sifting through these files, weeding out false positives. All said and done, I retrieved a good chunk of my data. I think I got back around 80% of my pictures, and almost all of my code and website source. It was a scary few days, but I’m glad that my desperation drove me to try something like this!

vivin.net is back… mostly

So I’m sure you’ve noticed that this website was down for a while. It went down about three weeks ago when one of the (two) hard-drives on my server died due to bad sectors; it was eight years old. I didn’t panic (too much), because my WordPress database was on the main drive, which is still alive. However, my home directory was on the bad drive and I hadn’t backed up in a while (sigh), and so I lost some images that I had uploaded. What baffled me were my WordPress uploads. I was sure that I had installed WordPress on my main drive, but when I went to search for it, I couldn’t find any trace of the install. Due to this, I’ve lost a few images and I’m not sure if I’ll be able to replace them unfortunately. Oh well.

Also, I must bid farewell to a dear and old friend: my webserver enterprise. I set up my webserver almost 10 years ago (running FreeBSD of course), and she has been serving me faithfully for all this time. Over the years I’ve dealt with all kinds of disasters and I’ve been able to keep her running. However, after this latest disaster I’ve realized that I just don’t have the time to maintain and administer a server anymore; it’s hard to do with a full-time job and with a full-load at school (did I mention that I am doing my Masters?). Therefore, I’ve moved my site over to dreamhost. The cool thing is that they also offer shell access too, which in my opinion is absolutely indispensable. It took me a little while to migrate my WordPress installation over (I had to work out a few kinks), but now it looks like everything is running smoothly.

On that note, I’m looking forward to less server-administration and more blogging!

Downtime and System Upgrade

Sorry for the downtime. My webserver had a failing hard-drive and I figured that while I was replacing the hard-drive, I would upgrade the entire machine as well. The box was a Pentium 4 1.4Ghz with 512MB of RAM that I hadn’t upgraded since I first built it in 2002. Now it’s been upgraded to a Pentium 4 2.4Ghz (hyper-threaded) with 1GB of RAM. Building from source will be a lot faster now! The whole upgrade process took a while because I was also in the process of upgrading another one of my machines and that took for EVER (some issues with shorting). Finally I had to install FreeBSD (version 8.0) on the new hard-drive as well as Apache, PHP, MySQL, WordPress etc. After I have everything set up, I’m going to make sure that I image the hard-drive so that I can restore it from backup easily.

GitHub broke my scp

I set up git on my FreeBSD box so that I can commit my code to GitHub. Today I tried to scp some stuff over and I was met with this rather unhelpful message:

[email protected] ~/Projects/code
$ scp -r [email protected]:~/code/agnostic .
Password:
ps: Process environment requires procfs(5)
Initializing new SSH agent...

[email protected] ~/Projects/code
$

I fixed the procfs problem by adding the following to my /etc/fstab:

proc                    /proc           procfs  rw              0       0
linproc                 /compat/linux/proc      linprocfs       rw      0       0

and then running:

[email protected] ~
$ sudo mount /compat/linux/proc

[email protected] ~
$ sudo mount /proc  

So I try to scp again and I get:

[email protected] ~/Projects/code
$ scp -r [email protected]:~/code/agnostic .
Password:
Initializing new SSH agent...

[email protected] ~/Projects/code
$

WTF? Then I remembered making some changes to my .bashrc to be able to commit to github:

function start_agent {
  echo "Initializing new SSH agent..."
  /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
  echo succeeded
  chmod 600 "${SSH_ENV}"
  . "${SSH_ENV}" > /dev/null
  /usr/bin/ssh-add;
}

# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
  . "${SSH_ENV}" > /dev/null
  #ps ${SSH_AGENT_PID} doesn't work under cywgin
  ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
    start_agent;
  }
else
  start_agent;
fi

I pulled all that out of my .bashrc and made a separate shell script for it. After I did that, scp started working again. I had no idea that calling scp would actually run .bashrc

Flu shot and bizarre network issues

This last weekend I had drill and the medics gave us the seasonal-flu mist-vaccine. It’s the one where they squirt gooey, inactive virus up your nose. I’ve had the vaccine before without any adverse side-effects. Yeah, not this time. I got the shot on Saturday and I was fine on Sunday. Not so on Monday. I woke up a few times in the middle of the night with a bit of a fever, but I figured that it would just go away. Yeah, didn’t happen. On Monday morning I felt like I had been run over by a semi. My throat felt like I had swallowed bits of broken glass. Needless to say, I didn’t go to work. I was bedridden most of the day, but towards the end I felt a little better. I tried to get a little work done but I wasn’t too successful since I had a hard time concentrating.
Read the rest of this entry »

Apple: Blurring the Line Between Hackers and Hipsters

Yesterday, while wrestling with my Windows XP machine to make it do dual-monitor display properly (I can’t get it to set my LCD as primary display), I ended up hosing the registry completely. It took me about two more hours to fix the system and get it back to where it was. During this whole ordeal, there were long periods of waiting when drivers were installing or when chkdsk was running. I took this time to surf the web and ended up landing on a digital copy of In the Beginning was the Command Line by Neal Stephenson. While skimming through the book (I have read the book before; I own the hard copy), I realized a few things. The book is definitely outdated; it was written before Mac OS X came out. However, a lot of points were still valid. I was mainly struck by the changing character of the Mac, and also in some sense, the changing character of (some) hackers:

Hackers like to hack. This is not a bad thing. In fact, “hack” originally did not mean “break into goverment/financial systems and do bad things”, and a “hacker” was not an unsavoury individual who did the aforementioned “bad things”. A “hack” originally meant “an elegant and clever solution to a problem” (although, it paradoxically also means “crude and ugly solution to a problem”), and a “hacker” is a person who comes up with such solutions. Most programmers call themselves “hackers”. The media term “hacker” is actually described by the term “cracker”. Hackers are constantly tinkering with things. Usually they are trying to make things better, but more often than not, they end up breaking it. However, in the process they learn very valuable lessons about how not to break something, and then immediately find another way to break it again. In all seriousness though, what we learn are the limits of the system, and how the system works. Hackers don’t like unknowns and black boxes. They want to know what makes things tick.

My dad got me my first computer in 1990. I didn’t do much on it at first other than play games. I actually started writing code in 1992, and I haven’t stopped. I’ve been hacking around since then, and in the process I’ve learnt a lot of many cool things. Over the years I’ve experimented with various OSes and programming langauges, and in the process broken and hosed many computers. But each time I learnt something valuable from them… mostly. One of the cooler things (I didn’t learn anything from this really, it was just a bug) I did was writing a self-replicating Perl script that kinda ran wild on ASU’s Solaris server. There were so many scripts running around that it brought the server to a crawl. I eventually figured out what was happening and managed to kill all the processes. Anyway, my point is that people like me like to tinker around. We don’t mind if we break stuff while doing it, because we’ll figure out a way to fix it. It’s the “figuring out” part that makes us happy. So what does all of this have to do with Apple, Hipsters, and Hackers? Well, in Neal Stephenson’s book he describes two kinds of people: Eloi and Morlocks. An Eloi is your average internet user; they view computers as appliances and tools and nothing more. A Morlock, on the other hand, is your average hacker. The computer is definitely a tool, but it is a tool that can be used to create other tools. The workings of a computer are usually a mystery to an Eloi, but not so for the Morlock. Before Mac OS X, most users of Macs were of the Eloi variety. The Mac was a beautiful and stylish magic-box that did wonderful things. The inner workings were a mystery. You couldn’t easily get inside and tinker with it, but that wasn’t really an issue because Eloi don’t care about things like that. Morlocks gravitated more towards the PC world. Sure, PC’s were clunky and definitely not as stylish as a Mac. Plus, a lot of them ran Windows which many Mac fans claimed was a clunky and cheap copy of the Mac OS (in truth, everyone basically copied Xerox PARC). However, they could be opened up and tinkered with. At this point in time, there was also this thing called Linux, which was an interesting piece of software (at the time). Linux is basically just an operating system. What most people mean when they say they “run Linux”, is that they run a distribution of Linux. A distribution consists of the kernel (Linux), in addition to a bunch of userland tools (programs that actually let you do something). The cool thing about Linux was that it was free. You could go download it and install it on your computer and it would run. What was even more interesting was that it was made by volunteers. People actually took the time to sit down and write code to improve and enhance the operating system. Running Linux in those days was a chore. Most distributions came with a GUI (X with a window manager), but sometimes things didn’t work quite right if you had an obscure monitor and video card. Getting things to work meant going to the command-line and writing strange, arcane incantations and if the Gods were pleased, your hardware might work. But that didn’t bother the hackers, because it was fun trying to get things to work. In addition there was also a certain elitism about it. Running a Linux box meant that you had the time, patience, and above all, intelligence required to go through the mental contortions required to get a working system. But intellectual elitism is nothing new for hackers since all hackers have a bit (ok, a lot) of hubris.

Mac Sales ChartOk, so where am I going with this again? Seriously, I have a point. Things changed when Mac OS X came out; it had a command line. The command line is very important to us hackers because it lets us look “under the hood” of the GUI. True hackers always go to the command line to do serious work. The command line is a place where a pithy one-liner can replace a series of windows and buttons. To the uninitiated, the command line is a scary place where confusing and dangerous things happen. Just like a magic spell, you had to write obscure words and symbols to the computer, in the correct sequence. If you were lucky, the computer would derisively spit out an error. If you weren’t you probably broke your computer. If you were really lucky, the computer accepted your commands and did what you told it to do. The point of the commandline is that you get God-like power (mostly; to truly be God you had to be root). While this power enables you to be extremely efficient, it also enables you to do destructive things equally efficiently. The GUI shields you from the hard edges of the underlying OS. The cryptic command line is replaced by friendly windows and buttons. When the Mac OS got a commandline in Mac OS X, hacker types were suddenly interested in it. You now got the legendary stability and the “it just works” attributes of a Mac OS with the power of a commandline, and that too, a UNIX commandline (OS X’s kernel is essentially based on BSD, which is a direct descendant of the original UNIX). Which brings me to the main point. What I’ve noticed over the last few years, especially after graduating from college, is that even though I love to hack around and test the limits of a system, most times I simply want a system to work. I want to spend less time fixing the system, and more time fixing my own code. I have also noticed that I’m not the only one with these sentiments. Many of my fellow nerd and hacker friends own Macs and develop on them now. I considered getting a Mac as well, but it was a little over budget for me and I couldn’t justify the cost at the time. Macs provide a very good mix of power and stability, and that is extremely attractive to a developer. You can still hack around on the Mac (and you could probably break it), but most of the time you know it’s something you did that broke the system, than just a quirk with the system. In my personal opinion, I think Apple’s decision to include the command line in OS X was brilliant (their other good move was moving over to the ubiquitous x86 architecture). In fact, if you look over the sales chart (courtesy systemshootouts.org) of the Mac from 1997 to 2008, you can see how their sales remained more or less constant from ’97 to ’02, after which it really started taking off. OS X was released in 2001.

In the old days, Mac users were a tight-knit, elitist bunch who sneered at their less-fortunate Windows-using cousins. Most times, it was with good reason. The Mac OS was stable and polished, while Windows was a clunky GUI bolted on top of a command line. To be fair to Microsoft though, Apple didn’t have to put up with exotic hardware since they had complete control over it. The demographic that Macs attracted was mostly the artistic or hipster bunch. In recent years, the demographic has increased to include some people who also liked the supposed “coolness” of the Mac. If you owned a Mac, you were different. You were part of a “cool”, “hip”, and “artistic” minority. Apple played this up, marketing the Mac as not only a stable alternative to a PC, but a cooler alternative too. Today you have more people than ever using Macs. From a sorority chick who uses it because “OMG it’s like so pretty!” to a programmer who likes it because “OMG d00d it’s lyk teh UNIX!!11!” Apple has successfully bridged the gap between two extremes. In future years, I think Apple will continue to grow stronger, and the sales of Macs will continue to rise, providing a viable, proprietary alternative to Windows. I’m not an Apple fanboi; I like FreeBSD (perhaps why I have a soft spot for OS X) and Linux more, but I think Apple deserves respect for making an excellent OS that’s friendly to hackers and hipsters alike.

There is no Windows 7

Here is a first look at the Windows 7 beta. All I could really get from the review was that “it’s done”, and that it “feels snappier” and that it is “more responsive”. In the screenshots it still looks like Vista. The taskbar reminds me of KDE. A bunch of torrent sites have the beta up for download. Microsoft is expected to announce the build’s public availability in January. So you can get a copy of it and try it out, but to do so might be “breaking the law”. But that hasn’t deterred a bunch of people who’re out downloading it. Right now, piratebay‘s torrent for the beta is showing 2,503 seeds and 8,137 peers.

On another note though. People seem to think that this is a new operating system from Microsoft. It isn’t. It’s just Vista Service Pack 3, in my opinion. I mean, how long did it take Microsoft to come up with Vista after XP? I seriously doubt they got a brand new operating system out in about a year and a half. The name is just a PR campaign to bury the name “Vista”. There is so much bad press and publicity surrounding the name that Microsoft has to get away from it, if they want the Vista codebase to be successful.

I had Vista on my laptop. It was alright; I didn’t use it long enough to run into too many issues. The UAC prompts were pretty annoying though. Also, compiling anything on it took forever. I’m running Ubuntu on it now, and it’s way faster. My sister and my dad both run Vista, but I haven’t heard of them having any problems. If Windows 7 really is good, then I might actually consider running it. I currently have only one Windows machine and that’s running XP. Everything else is either running FreeBSD or Linux.

Sorry for the delay

I’m really sorry for not updating this journal for… well, seems like forever. I figured I’d start writing regularly but that turned out to not be the case. A few things got in my way. Ever since I started working at Infusionsoft, I’ve had less of a desire to come back home and sit at the computer… again. The reason being, that most of my code-cravings are taken care of at work. Seriously, I love it. As a result I don’t really feel like coming back home and sitting in front of the computer.

The second thing was that my parents were here for a long time, and so I was spending most of my time with them. Then what else… oh yes, there was a thunderstorm and the power went out and my server decided that it didn’t recognize the NIC it had recognized for the past four years. So I went and bought a new one, and as soon as I plugged it in, it recognized the old one. I love computers. Then of course, there’s the fact that I was just pretty lazy. For some insane reason I decided that I wanted to upgrade the server to FreeBSD 7.0 and then I kinda just dragged my foot on setting everything else up.

Finally, there was my getting deployed again. Yeah, you read that right. I was going to Iraq… again. I pretty much found out about it around the time of my WLC training. So there was all the preparation for that. I really wasn’t looking forward to going (who does, anyway?) but I figured I had to (all that duty stuff, raising my right hand, taking the oath). However a few weeks ago I found out that I really didn’t have to go. As it turned out it hadn’t been two years since I got back and so I had the option of not going. So I told my readiness NCO that I didn’t want to go. I have my career to think of, and I think one tour in Iraq is more than enough. I was pretty torn when I had to make that decision. It took me about half a second to decide what I wanted to do. Part of me almost wanted to say “yes”. But I think this is the better decision.

Anyway, I just wanted to let you all know that I’m alive and that I’m definitely going to try and write more frequently on this journal. I’m doing a lot of exciting things at work and I’d like to be able to write about them. So, until next time…

My new laptop

I recently bought myself a new laptop – the Dell XPS M1530. I was originally considering a Macbook, but that was a little too pricey for me. I started to fancy OS X ever since I found out that it is basically FreeBSD at the core. Also, there is the eye-candy. Other than the price-tag, I also realized that the only reason I would want the Macbook was because it looks so good. That didn’t seem entirely practical. I could still get the eye-candy and the productivity on another OS. The last laptop I bought was an Alienware beast. It was ridiculously heavy and I got sick of lugging it around. It basically a desktop masquerading as a laptop. In addition to being really heavy, it generates quite a lot of heat. Enough to burn your lap. But it plays games really, really well. Anyway, I decided that I would look for a nice non-Apple laptop. After scouring the Internets and reading a bunch of reviews, I settled on the XPS. It’s sleek, stylish, fast, portable, and it got a bunch of good reviews. I went to the Dell site and configured my XPS:

  • Intel Core 2 Duo Processor T7700 (2.4GHz/800Mhz FSB, 4MB Cache)
  • 3GB Shared Dual Channel DDR2 SDRAM at 667MHz (2 Dimms)
  • 256MB NVIDIA GeForce 8600M GT
  • 250GB 5400rpm SATA Hard Drive
  • High Resolution glossy widescreen 15.4 inch LCD(1680×1050) 2MP Camera
  • Slot Load DVD+/-RW (DVD/CD read/write)
  • Integrated Sound Blaster Audigy HD Software Edition
  • Intel Next-Gen Wireless-N Mini-card (4965AGN)

It’s got some punch. I’m mainly going to use it as a development machine so the RAM and speed definitely help as far as compile-times go. They estimated about two weeks to build the laptop, but actually I got a pleasant surprise when the laptop arrived a little over a week after I ordered it. I wasn’t disappointed in the least when I opened up the package. The first thing I did was blast Vista off the hard-drive and install PC-BSD. This is where I learnt a hard lesson. Stability in the BSD world comes at a price. You don’t have very good hardware support (for no fault of FreeBSD; I’ll rant about this later) for the latest hardware. Drivers are not included until they are reliable and stable. As a result, my Marvell Yukon 88E8040 Gigabit Ethernet card, and my Intel 4965AGN Wireless-N card were unrecognized. Marvell (surprisingly) had a FreeBSD 6 driver on their website that is supposed to work with the 88E80XX series, but I was unable to get it to work on my system. I tried using ndiswrapper to get the Intel card working, but I only succeeded in crashing my system very nicely. I was pretty bummed. I really didn’t want to go back to using The Evil (Vista), and so I decided to play around with kubuntu for a while. It was nice, and I may get back to it. But for the hell of it, I wiped it off and tried to install OS X on it. I was able to get a “patched” Leopard ISO and I actually got it to install on the XPS. However, I wasn’t able to get it to recognize any of my network devices. So after playing around with that for a while, I went back to The Evil. I am hoping that by the time PC-BSD 2.0 or FreeBSD 7.0 rolls around, there will be more support for the network cards. If that’s the case, I’ll definitely be wiping out Vista and installing PC-BSD (or install FreeBSD 7.0 and build KDE). I’ve been using Vista for a little while, and I guess it’s not so bad. It’ll stay out of your way if you ask it to. But it really doesn’t compare to either PC-BSD, Kubuntu, or Leopard. As far as the XPS, I like it a whole lot. I think Dell has done a pretty good job with it.

Getting the Netgear WN311T to work on PC-BSD/FreeBSD

Recently, I decided to try out PC-BSD. It’s essentially FreeBSD with a desktop (KDE) and various other goodies. I’ll talk about my experience with PC-BSD in another post. This one is about setting up the Netgear WN311T RangeMax NEXT Wireless Adapter to work with PC-BSD. I had heard that setting up wireless to work with FreeBSD or Linux can be quite an adventure and my experience was no different. These instructions should also work for regular FreeBSD. You can also use the following instructions to get other wireless cards working. But remember that each one will have its own quirks so you will probably have to scour the web looking for additional documentation. Remember, Google is your friend!

When I installed PC-BSD, I noticed that it wasn’t able to recognize my Wireless Adapter. This wasn’t a surprise, and for no fault of PC-BSD’s. It’s just that very few manufacturers make drivers for OSes other than Windows. Also, they are reluctant to release details for the adapters because they regard them as trade secrets. Hence, developers are left with the option to painstakingly reverse-engineer the adapters and write drivers for them. Anyway, before I could get my card to work, I needed to know what chipset it uses. To do this, you can use lspci, which lists devices on the PCI bus.

So first, open up a terminal window from Start->System->Konsole. Then do:

[[email protected] ~] su
Password:
[[email protected] /home/vivin]# pkg_add -r pciutils
Fetching ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-6.1-release/Latest/pciutils.tbz... Done
[[email protected] /home/vivin]# lspci
00:00.0 Host bridge: Intel Corporation 82875P/E7210 Memory Controller Hub (rev 02)
00:01.0 PCI bridge: Intel Corporation 82875P Processor to AGP Controller (rev 02)
00:03.0 PCI bridge: Intel Corporation 82875P/E7210 Processor to PCI to CSA Bridge (rev 02)
00:1d.0 USB Controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #1 (rev 02)
00:1d.1 USB Controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #2 (rev 02)
00:1d.2 USB Controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #3 (rev 02)
00:1d.3 USB Controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB UHCI Controller #4 (rev 02)
00:1d.7 USB Controller: Intel Corporation 82801EB/ER (ICH5/ICH5R) USB2 EHCI Controller (rev 02)
00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev c2)
00:1f.0 ISA bridge: Intel Corporation 82801EB/ER (ICH5/ICH5R) LPC Interface Bridge (rev 02)
00:1f.1 IDE interface: Intel Corporation 82801EB/ER (ICH5/ICH5R) IDE Controller (rev 02)
00:1f.2 IDE interface: Intel Corporation 82801EB (ICH5) SATA Controller (rev 02)
00:1f.3 SMBus: Intel Corporation 82801EB/ER (ICH5/ICH5R) SMBus Controller (rev 02)
01:00.0 VGA compatible controller: nVidia Corporation NV31 [GeForce FX 5600] (rev a1)
02:01.0 Ethernet controller: Intel Corporation 82547EI Gigabit Ethernet Controller (LOM)
03:01.0 Ethernet controller: Marvell Technology Group Ltd. Unknown device 2a02 (rev 03)
03:02.0 Serial controller: 3Com Corp, Modem Division 56K FaxModem Model 5610 (rev 01)
03:03.0 Multimedia audio controller: Creative Labs SB Audigy (rev 03)
03:03.1 Input device controller: Creative Labs SB Audigy MIDI/Game port (rev 03)
03:03.2 FireWire (IEEE 1394): Creative Labs SB Audigy FireWire Port
03:04.0 Multimedia controller: Sigma Designs, Inc. REALmagic Hollywood Plus DVD Decoder (rev 02)

As you can see, the wireless controller has a Marvell chipset. Unfortunately, FreeBSD doesn’t have a driver for Marvell chipsets. This is where the amazing piece of software known as ndiswrapper comes in. FreeBSD doesn’t have ndiswrapper per se, instead it has something similar called ndisulator (also known as Project Evil). This nifty piece of software creates a kernel module by making a wrapper around the Windows driver (using the SYS and INF files). You can then load this kernel module and FreeBSD will be able to recognize your wireless card.

Before you can run ndisulator, you need access to your hardware’s driver files and the kernel source files. For PC-BSD, you can get the source files here. You will need to copy this from /Programs to /usr and extract it. For FreeBSD, run /stand/sysinstall and then download the src distribution. I think it’s somewhere under “Configure”.

As far as the driver files, you can usually get this from your installation CD. However, in some cases (such as this one), the driver files are packed into an executable and there’s no way you can get it unless you actually install the program. If this is the case, you can probably search the web to be able to find the driver files. What I did was install Wine and then run the latest driver from Netgear’s site. If you don’t have X running, then this is a problem. Anyway, I have made it easier for you and I have the bzipped and gzipped tarballs available for download. Now once you have extracted the files to a directory, you will need to run ndisgen on these files. If you notice, there are two SYS files. I built modules for both, and I use both on my system. It seems to work if you load either one. Using ndisgen is simple. However, there are a few caveats. When you first run ndisgen you may get a “Conversion failed” error with a syntax error on line 998 (or something to that effect). The reason is that the INF file parser on FreeBSD is not as forgiving as the one on Windows. It’ll trip up on DOS-style EOL characters (\r\n) and on some other weird characters as well. Often, the file itself has some other weird syntax errors as well. Anyway, to fix the the EOL character problem, you have to change the DOS-style EOL characters to Unix. Some systems have a dos2unix and unix2dos command. If you don’t have it (I didn’t) you can use the sed command:

[ro[email protected] /home/vivin/wn311t]# sed -i -e 's,^M,,g' NetMW14x.inf

The ^M is not just the caret sign and the capital letter M. To get it, you have to press CTRL+V and then CTRL+M. This command will convert all DOS-style EOL’s to UNIX-style EOL’s. Now we need to try converting the files to kernel modules. Unfortunately, when I did this first, I got the following error:

[[email protected] /home/vivin/wn311t]# ndisgen NetMW14x.inf netmw145.sys
        ==================================================================
        ------------------ Windows(r) driver converter -------------------
        ==================================================================

                        Kernel module generation


        The script will now try to generate the kernel driver module.
        This is the last step. Once this module is generated, you should
        be able to load it just like any other FreeBSD driver module.

        Press enter to compile the stub module and generate the driver
        module now: 

        Generating Makefile... done.
        Building kernel module... In file included from /usr/share/misc/windrv_stub.c:57:
./windrv.h:150:4: unknown escape sequence '\p'
./windrv.h:150:4: unknown escape sequence '\H'
./windrv.h:318:4: unknown escape sequence '\p'
./windrv.h:318:4: unknown escape sequence '\H'
build failed. Exiting.

This is problem is due to un-escaped backslashes in windrv.h. I went ahead and fixed the file, but then realized that when I ran ndisgen again, my changes would be overwritten. So I copied my changes to another file called windrv2.h. I ran ndisgen again, and at the prompt where it tells you that it is going to build the kernel module, I opened up another terminal window and copied windrv2.h over windrv.h. This time the conversion process went through without a hitch. After you convert both SYS files, you will be looking at two .ko files; netmw143_sys.ko and netmw145_sys.ko. You need to kldload these modules:

[[email protected] /home/vivin/wn311t]# kldload netmw145_sys.ko
[[email protected] /home/vivin/wn311t]# kldload netmw143_sys.ko
[[email protected] /home/vivin/wn311t]# kldstat
Id Refs Address    Size     Name
 1   23 0xc0400000 753dc8   kernel
 3    2 0xc0b5f000 1af50    linux.ko
 4    1 0xc0b7a000 75650    netmw143_sys.ko
 5    4 0xc0bf0000 1753c    ndis.ko
 6    3 0xc0c08000 c9e0     if_ndis.ko
 7    1 0xc0c15000 757d0    netmw145_sys.ko
 8    1 0xc0c8b000 58554    acpi.ko
 9    1 0xc57ff000 6000     snd_emu10k1.ko
10    1 0xc5805000 1c000    sound.ko
11    1 0xc5872000 6000     linprocfs.ko
12    1 0xc588f000 4000     logo_saver.ko

Note that I took this output from my machine where I automatically load the modules at startup (more on that later), which is why they are in lower memory locations. Anyway, the highlighted modules are the ones you need to worry about. If all goes well, these modules should be visible. If you do an ifconfig you should now be able to see the ndis0 interface:

[[email protected] /home/vivin/wn311t]# ifconfig ndis0
ndis0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        inet6 fe80::218:4dff:fe1f:f432%ndis0 prefixlen 64 scopeid 0x7 
        inet 0.0.0.0 netmask 0xffffff00 broadcast 255.255.255.255
        ether 00:18:4d:1f:f4:32
        media: IEEE 802.11 Wireless Ethernet autoselect
        status: no carrier
        ssid "" channel 1
        authmode OPEN privacy OFF txpowmax 100 protmode CTS

This is good, because FreeBSD now recognizes your card. The next hurdle is getting your card associated to a wireless network. This is where I had the most difficulty. Scanning for networks didn’t seem to work for me. KDE’s wireless tools were unable to find anything and I was also unable to find anything from the terminal. I figured I could still try and connect to the network by providing my SSID. Since I use WPA, I was going to use wpa_supplicant to connect to my wireless network. This proved to be easier said than done. I set up my wpa_supplicant.conf file in /etc like this:

eapol_version=1
ap_scan=1
fast_reauth=1

network={
           ssid="<put your ssid here>" 
           # 'RSN' == 'WPA2'
           proto=RSN WPA
           key_mgmt=WPA-PSK
           pairwise=CCMP TKIP
           group=CCMP TKIP
           psk=<put your psk here>
        }

After that:

[[email protected] /home/vivin/wn311t]# wpa_supplicant -i ndis0 -c /etc/wpa_supplicant.conf
ioctl[SIOCG80211, op 24, len 24576]: No space left on device
ioctl[SIOCG80211, op 24, len 24576]: No space left on device
ioctl[SIOCG80211, op 24, len 24576]: No space left on device
ioctl[SIOCG80211, op 24, len 24576]: No space left on device
ioctl[SIOCG80211, op 24, len 24576]: No space left on device

As you can see, things didn’t go too well. I spent hours scouring the web and message boards. I found someone with exactly the same error message, but they had received no responses to their queries. Finally after about another hour of searching, I had enough information to put it all together. Instead of using the wpa_supplicant binary, you need to use FreeBSD’s wpa_supplicant script together with dhclient:

[[email protected] /home/vivin/wn311t]# /etc/rc.d/wpa_supplicant forcestart ndis0
[[email protected] /home/vivin/wn311t]# dhclient ndis0

If all goes well, your wireless card should be able to authenticate with your wireless router and receive an IP address:

[[email protected] /home/vivin/wn311t]# ifconfig ndis0
ndis0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        inet6 fe80::218:4dff:fe1f:f432%ndis0 prefixlen 64 scopeid 0x7 
        inet 10.0.1.197 netmask 0xffffff00 broadcast 10.0.1.255
        ether 00:18:4d:1f:f4:32
        media: IEEE 802.11 Wireless Ethernet autoselect
        status: associated
        ssid "" channel 1
        authmode OPEN privacy OFF txpowmax 100 protmode CTS

This is fine and dandy. But now you need to make sure that all these steps are done automatically when you startup your machine. First, you need to ensure that your new kernel modules are loaded up when you start your machine. To do that, copy your kernel object files to /boot/kernel. Then, add the following lines to /boot/loader.conf

[[email protected] /home/vivin/wn311t]# grep net /boot/loader.conf
netmw143_sys_load="yes"
netmw145_sys_load="yes"

These changes will ensure that your wireless adapter drivers are loaded up on startup. Finally, you need to add two lines to /etc/rc.conf to let FreeBSD know that your wireless adapter needs to be configured through wpa_supplicant:

# Enable wpa_supplicant
if_ndis0="WPA DHCP"
wpa_supplicant_enable="YES"

I have read that the second line is superfluous because apparently the “WPA” option tells FreeBSD to use wpa_supplicant, but it didn’t seem to hurt anything so I left it in there. Once you have done all this, go ahead and restart your machine. Your WN311T Wireless Adapter should now be able to connect to the wireless network. You can verify that wpa_supplicant is running by doing the following:

[[email protected] /home/vivin/wn311t]# ps x | grep wpa
 1368  ??  Ss     0:56.72 /usr/sbin/wpa_supplicant -B -q -i ndis0 -c /etc/wpa_supplicant.conf -D ndis -P /var/run/wpa_supplicant/ndis0.pid

In some cases, wpa_supplicant still won’t start. I have had this problem before. In that case, you will have to run wpa_supplicant and dhclient manually (like I showed before) to get your card to work. I am not sure why this happens.

These instructions deal with using WPA for your Wireless Security. I believe wpa_supplicant can be configured to use WEP as well.

So there you have it. I hope this writeup is helpful and saves you hours of frustration!

All original content on these pages is fingerprinted and certified by Digiprove
%d bloggers like this: