Archive for the ‘linux’ Category

Linux: how do I find the devce name of my USB drive?

Monday, December 28th, 2009

Around the time I reviewed Chromium OS, I managed to totally b0rk one of my thumb drives. I somehow botched the dd command, and the device became unusable. When I plugged it in, nothing would happen. Or rather nothing on the UI side. My KDE would simply ignore the drive and pretend it was not there. I didn’t want to just throw out the USB stick, so I decided to figure out what device name gets assigned to it, and then repartition it again.

How do you do that? The simplest method is to watch the log files. When you plug in a USB the device, your system should make a note of it in /var/log/messages. So you should do the following:

tail -f /var/log/messages

In case you didn’t know, the tail command prints out the last few lines of a text file, and the -f argument basically means “follow”. So tail will basically pring any new lines that are appended into the console in real time. Once you issue this command, just plug in your device. Your output should look something like this:

Dec  1 12:56:44 malekith kernel: [13631.153753] usb 2-1: new high speed USB device using ehci_hcd and address 4
Dec  1 12:56:44 malekith kernel: [13631.288125] usb 2-1: configuration #1 chosen from 1 choice
Dec  1 12:56:44 malekith kernel: [13631.288669] scsi5 : SCSI emulation for USB Mass Storage devices
Dec  1 12:56:49 malekith kernel: [13636.295004] scsi 5:0:0:0: Direct-Access     Kingston DT 101 II        1.00 PQ: 0 ANSI: 2
Dec  1 12:56:49 malekith kernel: [13636.295900] sd 5:0:0:0: Attached scsi generic sg3 type 0
Dec  1 12:56:49 malekith kernel: [13636.306962] sd 5:0:0:0: [sdc] 7831552 512-byte logical blocks: (4.00 GB/3.73 GiB)
Dec  1 12:56:49 malekith kernel: [13636.308590] sd 5:0:0:0: [sdc] Write Protect is off
Dec  1 12:56:51 malekith kernel: [13636.315523]  sdc: sdc1
Dec  1 12:56:51 malekith kernel: [13637.905840] sd 5:0:0:0: [sdc] Attached SCSI removable disk

Check out the second to last line – it says sdc1. What does that mean? That means that my b0rken thumb drive is assigned to the /dev/sdc1 device. Now that I know that I can easily run fdsk on the device to format it and rebuild the partition table that was messed up by a botched dd command.

It’s that easy. I’m putting it here for future reference more than anything else.

Make my OS Faster

Monday, November 30th, 2009

Have you noticed how all prominent operating systems seem to bloat with each release? Windows is probably the best example, but even Ubuntu had slowly gained weight and become more of a resource hog over the years. It’s sad really. Instead of becoming leaner, more optimized and streamlined our OS’s become bigger, more sluggish and encumbered with tons of unnecessary features. The primary driving force behind OS development these days is usability (a noble cause) and multiplying the feature count. Because nothing shows that the new version is better than a bullet list of new features that can be printed on a sales brochure. The OS makers are often forgoing optimization relying on Moore’s law to pick up the slack. Naturally they forget that most users do not replace their computer every 18 months. Therefore there is a discrepancy between what users have in terms of hardware, what should they have based on Moore’s law and what the developers are shooting for.

The result is that unless you have a bleeding edge hardware, your new OS is likely to run anywhere between slow and sluggish. Add an array of resident tools such as Anti Virus suite, print monitors, media programs that launch on start up, preloaders of various applications, IM suites and you have a machine that is moving in slow motion from the day one. Any new resident programs and (God forbid) inevitable malware infections will bring the machine to a grinding halt. If not today, then tomorrow when new releases of software will assume hardware moved to the next performance bracket as predicted by Moore’s law.

If you have ever worked in IT you know that the #1 user complaint you will hear on a daily basis is “my computer is slow”. Actually, you don’t even have to work in IT to know that. All you need is to work in any field where you need some technical knowledge. Or hell, if you ever reveal any kind of computer know-how to your friends and relatives you will likely be overrun with questions on how to make windows faster.

Slow performance is such a pervasive issue that even malware makers are using a promise of fixing it as a bait. If I had a penny for every time I’ve seen someone download a “registry cleaner”, “system speedup toolkit” or other “turbo booster” software which was really a trojan, I would be a rich man. People fall for this trick all the time, because they get desperate. They buy a computer which runs fine for 6 months to a year, and then starts becoming more and more sluggish. No matter what they do, they can’t return it to the original performance. Why?

Well, it’s a difficult question. The performance degradation has many possible causes:

  1. Malware
  2. Resident programs running at start up
  3. Unnecessary services running in the background
  4. 3rd party software modifying the OS functions ways that degrade performance (a/v suites are big offenders here)
  5. Disk fragmentation
  6. OS updates that increase memory footprint and CPU load
  7. Other software updates that increase memory footprint of running services
  8. Gremlins maliciously flipping bits in the memory for LULZ
  9. Bit bucket becoming full and overflowing
  10. Machine spirits nesting in the hardware

That last one is something I keep warning people about. If you keep personifying your computer, it will eventually cause a machine spirit to coalesce inside of your computer case. These spirits are not really autonomous beings – they are more like an empathic echo. They acquire all the personality traits which the user commonly ascribes to the machine. So if you keep saying something like “this computer hates me” or “I hate this computer” the machine spirit will really hate you, or assume you hate it and will work against you. A machine that is loved, and pampered may behave much better – but it can become moody, and downright malicious when it starts suspecting that the user is planing to replace it. Even if your machine spirit is benign most of the time, it still needs to steal some CPU cycles and some memory to store it’s personality and cognitive processes. The older the machine spirit, the more resources it requires. The only way to get rid of a machine spirit is to stop feeding it. When you think of your machine as an inanimate electronic box, or better yet – a tool, or extension of yourself the spirit will eventually cease to exist.

All joking aside, part of the performance degradation issue lies in the simple fact that most our operating systems are bloated to begin with. So even if you take a slow machine, wipe it clean and reinstall the OS it will still be slow. By the time you install all the current patches, all upgrades and equip it with the latest a/v suite you will be almost back to where you started minus the malware. But the user will install that back as soon as he gets the machine back. This happens because new applications and the OS updates are tailored at current hardware, whereas most users will be running them on a machine that is one or two Moore’s law iterations behind (if not more). Not only that, but our perception of what is fast changes quite significantly over the years. Your machine might have seemed fast 4 years ago, but that’s because it was on the cutting edge back then. Now the cutting edge has moved.

The more complex and feature full the operating systems get, the more prone they become to general crufting. For years now I have been dreaming about a lean, stripped down mainstream OS that would be available to general public, and could be installed on slightly older hardware. I mean, yes – you can do this with a stripped down Linux distro. For example I heard good things about Arch, and Crux. But these are more of a fringe systems that are targeted at enthusiasts. Not necessarily something you install on your neighbors machine when he cries about performance issues. Besides, if you try hard enough you can make those systems bloated as well.

Microsoft has it’s Windows Fundamentals thing, which is a stripped down XP. Still, it can only be obtained via Volume Licensing which means it is clearly not targeted at the home market. Also, Fundamentals seems a bit like an afterthought – it’s not a flagship product and gets limited amount of attention.

What we really need is a modern OS designed from ground up to be lean, mean and optimized for performance. I mean something built for speed and usability – not retrofitted for it by stripping off useful features and degrading user experience. The most user friendly Linux distributions are usually tailored towards feature bloat. Can Google Chrome break that trend?

Google certainly has the clout to market this OS to the masses, and brand recognition that won’t make people run for the hills. It’s still Linux, but people won’t know about it, and therefore won’t be scared of trying it. Could chrome be the first user friendly, mainstream Linux distro tailored towards non-geeks using legacy hardware?

It’s certainly interesting. I’m anxiously awaiting the release of the OS to see if it will follow the same high quality design as most other Google products. I’m also very curious as to how it will be received by mainstream, non-technical population.

Kubuntu 9.10 Upgrade: Karmic nVidia Failure

Monday, November 16th, 2009

Did they name Ubunu 9.10 Karmic on purpose, and then had it ruin the lives of the wicked people? My upgrade was an absolute train wreck. I spent my whole afternoon, and evening fixing it, and managed to accidentally delete few moths of email. Yay me!

The upgrade went smoothly up until I rebooted the machine and noticed that I’m running 800×600 and my dual head setup was broken. This was very noticeable on a 23 inch monitor, and running the new KDE version which super-large windows decorations. So I decided to fix it.

Quick note on KDE 4.3:

WHAT THE FUCK?

It seems that the design goal of this release was to “make it as shitty as Vista”. Can we please stop doing that? Seriously, I don’t even recognize this environment anymore. It was working fine before – there was no need to change the Kmenu, the panel or the fucking desktop.

Granted, the desktop effects are actually very nice, and the plasma widgets are cool. Still, I wasn’t very happy viewing it in 800×600 resolution on a 23″ monitor. Try that yourself and you will see why I was angry. Without the bells and whistles the desktop was just ugly and barely functional. I’m slowly getting used to it now and I think I will be fine but the first impression was horrible.

So I did the exact same thing that worked for me last time. I pulled up the KDE Hardware app and told it to activate proprietary nVidia driver. It didn’t work. I tried couple more times, and then restarted the machine thinking that maybe the damn thing is just not registering the change. That’s how I hosed my X. Kubuntu came back in text only mode and I had to hack the xorg.conf and switch it back to the generic driver.

After this I tried following some online troubleshooting steps trying to install, re-install the drivers, hack the xorg.conf and each thing I did made my system more broken than it was. Eventually I managed to delete my .kde folder with several moths of emails (ie. my last backup was few months ago, and I have no one to blame for this but my own stupidity).

PROTIP:

Do not do mv -i as root. Ever!

In fact, every time you do any moving or deleting from the command line you should back up the folders in question just in case. The beauty of working from the shell is that it does not try to hold your hand or second guess your choices. Linux will do precisely what you ask it to do – whether it is good or bad for the system. This gives you great deal of power and flexibility but comes at a price – a typo, or badly formatted command may actually damage the system or wipe your files.

This is what happened to my email folder. At one point during the troubleshooting I got it in my head that something went wrong in my KDE setup. At that point I got my machine to display the log in screen, but X would crash when trying to actually load the environment. So I decided rename my .kde directory and let the system generate a clean one to see if this helps. It did not, so I renamed it back. About 2 hours later I realized that I must have made a typo of some sort. When I finally got KDE to load it completely forgot all my settings. I went searching for the .kde-bak directory I created earlier, but it was nowhere to be found. It just went *poof*.

It wouldn’t be that bad if it wasn’t for the fact that Kontact keeps it’s email diles in there. Oops… I had backups, of course, but unfortunately I have been rather lax about them in the last few… um… months. So yeah – you get the idea. I was not a happy camper and there was no one I could blame for this but myself. First for being reckless with my commands. Second for not making a copy prior to fucking with such a crucial directory. Third for getting complacent and not running the backup script in god knows how long.

To make a long story short, half the solutions posted in the Ubuntu forums are total crap. It became painfully obvious that my problem ran much deeper. Reinstalling the drivers and re-creating the x config just wouldn’t cut it.

For reference my machine is a Latitude D820 with nVidia Quadro NVS 140m board. I was starting to think that there is just no working driver for this card that is compatible with the 2.6.31-14-generic kernel. Finally, after several hours I found the solution.

Alexander V. Røyne-Helgesen deserves one free internet for figuring this out. His fix is the only thing that worked for me. In case you are to lazy to click on the link, here is the solution:

First, open up your /etc/modprobe.d/lrm-video file and comment out every single entry that references nvidia. Your file should look something like this:

 # Make nvidia/nvidia_legacy and fglrx use /sbin/lrm-video to load  
install fglrx /sbin/lrm-video fglrx $CMDLINE_OPTS  
#install nvidia /sbin/lrm-video nvidia $CMDLINE_OPTS  
#install nvidia_legacy /sbin/lrm-video nvidia_legacy $CMDLINE_OPTS  
#install nvidia_new /sbin/lrm-video nvidia_new $CMDLINE_OPTS'

Once this is done, go to your /etc/modules file and add this at the end:

nvidia

Finally, go to your xorg.conf, find the entry that describes your video card and change the driver to nvidia. It should look something like this:

Section "Device"
   Identifier      "NVIDIA Corporation NV40m [Quadro NVS 140m]"
   Driver          "nvidia"
   # more lines here...

Now restart thy X server and… Boom! Back in business.

I should probably mention that I uninstalled and reinstalled the nVidia drivers about 10 times during the whole ordeal. I used various sources. The last thing I tried was the EnvyNG script (the package name is envyng – it’s in the repos). So I can confirm that this method above works with Quadro NVS 140m with a driver installed by EnvyNG. May not work after a straight upgrade.

Did I mention that the upgrade also broke my VirtualBox installation? Yeah, it did, but that’s a topic for a whole other post. Needless to say, I am never doing this sort of thing again on a weekday.