Laptop hard drive lifetime (load cycles)

Run the following:

$ sudo smartctl -A /dev/sda | grep -P ‘Load_Cycle|ATTRIB’

And see something like this:

ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
193 Load_Cycle_Count 0x0032 100 100 000 Old_age Always – 6038

The last value is the number of load cycles. A laptop hard drive typically has a lifetime of 600,000 load cycles. If the count is increasing by several thousand per day (or even several hundred), it may be cause for concern.

For information and how to fix it, see [http://lwn.net/Articles/256769/](http://lwn.net/Articles/256769/)

The journey to Fedora 8

I’ve upgraded our family laptop to [Fedora 8](http://fedoraproject.org/wiki/Releases/8/ReleaseSummary) (yes, we still dual boot into Windows Vista). The upgrade would have been a rather bumpy ride, except that I knew that Fedora 8 upgrades are [problematic](http://fedoraproject.org/wiki/Bugs/F8Common#head-7b9bf2dab0e2bdd97d98334c7198cd9cd3eaf9be) (installs are OK), and that there’s a [workaround](https://bugzilla.redhat.com/show_bug.cgi?id=372011).

While Fedora 7 supported our laptop fairly well, Fedora 8 is even better. The power savings features are better. The Fedora community has tracked down and fixed several programs that were power hogs. The screen dims automatically while on battery power after about 30 seconds. File systems are reportedly mounted with the new [‘relatime’ option](http://www.lesswatts.org/tips/disks.php), which saves on hard drive battery usage — unless you upgrade, in which case, you have to add it manually. Improved wireless drivers in combination with an improved Network Manager connect more reliably, and more quickly, to our WPA2 access point.

*FreeNX broken, and manually fixed*

I use FreeNX regularly to connect to a remote linux box. When I upgraded one machine to Fedora 8, I couldn’t connect using an NX client. I found [a suggestion](http://www.nabble.com/Fedora-8-working-for-anyone–t4806795.html) that helped me fix it: Edit `/usr/libexec/nx/nxnode` and replace `DISPLAY=”unix:$display”` with `DISPLAY=”:$display”` everywhere. Hopefully, someone will re-roll the FreeNX packages to fix this for Fedora 8.

*Ubuntu sidenote*

I’ve heard the claim that Ubuntu is more ready for the desktop than Fedora, and up to this point, I didn’t know how that could be. Last weekend, I plugged a Logitech quick cam into my brother’s Ubuntu system. I was trying to figure out how to load the webcam driver, when we discovered that Ubuntu had already recognized the webcam, and it was ready to use.

Linux performance tuning

When attempting to find and fix performance bottlenecks on a Linux system, it’s helpful to know where to start. Here are a few resources I’ve found:

IBM’s [Linux Performance and Tuning Guidelines](http://www.redbooks.ibm.com/abstracts/redp4285.html), published July 2007

> This IBM Redpaper describes the methods you can use to tune Linux,
tools that you can use to monitor and analyze server performance, and
key tuning parameters for specific server applications. The purpose of
this redpaper is to understand, analyze, and tune the Linux operating
system to yield superior performance for any type of application you
plan to run on these systems. ( [Read more…](http://www.redbooks.ibm.com/abstracts/redp4285.html) )

This website has useful tips:
[http://www.performancewiki.com/](http://www.performancewiki.com/)

Google has some tools that people recommend:
[http://code.google.com/p/google-perftools/wiki/GooglePerformanceTools](http://code.google.com/p/google-perftools/wiki/GooglePerformanceTools)

This book seems to be recommended:
[Optimizing Linux Performance](http://www.amazon.com/Optimizing-Linux-Performance-Hands-Professional/dp/0131486829)

In my experience, strace and ltrace along with the “-c” and “-T” options, are extremely useful — even for Perl scripts. The “-T” option shows the timings of calls, and can help isolate what calls are the slowest.

* `strace -o program.trace -T -p `
* `ltrace -o program.trace -T -p `

The “-c” option gives a summary of the calls that used the most time:

* `strace -c -p `
* `ltrace -c -p `

I haven’t found a good way to isolate memory leaks in Perl programs — not that I’m an expert. What has worked for me is to [divide and conquer](http://en.wikipedia.org/wiki/Divide_and_conquer_algorithm) in order to isolate the problem.

Laptop lamentations and blissful benefits

At our household, we’ve finally made the leap from a desktop computer to a shiny new laptop — an [HP dv6426us](http://www.amazon.com/exec/obidos/ASIN/B000RGG5EC/). A new computer, in theory, should save time because it runs faster, right? Wrong. It takes time to become familiar with Windows Vista and where they’ve managed to hide various configuration options (displaying file extensions in Explorer). HP doesn’t make it obvious how to get rid of their annoying add-ons from popping up in my face. I didn’t buy this thing to run the HP Health Center. I bought it so the OS would stay out of my way, and let me focus on work (err, tinkering).

We’re still attached to our desktop computer until we have migrated our data and applications over to the laptop. Migration requires time, time, and more time. [FireFox](http://www.getfirefox.net/), [Thunderbird](http://www.mozilla.com/thunderbird/), Quicken, [Vim](http://www.vim.org), [Password Safe](http://passwordsafe.sourceforge.net/), [Putty](http://www.chiark.greenend.org.uk/~sgtatham/putty/), [Cygwin](http://www.cygwin.com/), PrintMaster, Hallmark Create-a-Card, Palm Desktop, [OpenOffice](http://www.openoffice.org/), [IrfanView](http://www.irfanview.com/), [NoMachine NX](http://www.nomachine.com/), an instant messaging client, and the list goes on. I’ve tried Vista’s new [Windows Mail](http://en.wikipedia.org/wiki/Windows_Mail), and it’s much better than Outlook Express, but my wife and I have our email in Thunderbird, and it was easy to migrate that across — once I figured out where to drop the folder on Vista — in `C:\Users\MyUserName\AppData\Roaming\Thunderbird`. PrintMaster 12 didn’t run for non-admin users until I figured out that I needed to grant Full Control access for `C:\Program Files\Broderbund\PrintMaster\Ereg`. Cygwin and NoMachine NX conflict with each other.

I bought this particular laptop because the hardware was likely to work with Linux — it has an Intel graphics card, which has open-source Linux drivers, and Intel WiFi. Open source drivers mean that suspend and resume are far more likely to function correctly than when using proprietary drivers (as from Nvidia or ATI).

I would install Fedora 7, which meant I needed to resize the existing windows partition. Vista’s disk manager made this a piece of cake. Installing Fedora 7 was easy. At first, Fedora didn’t resume after suspending to RAM. After applying all Fedora updates, it worked, although WiFi doesn’t work after the resume. Hibernate always works, and so does WiFi after resuming from hibernation. WiFi and the NetworkManager didn’t allow me to connect to my WPA2-encrypted access point until I disabled SELinux.

Linux has other problems running on the hardware, including:

– Secondary screen output hasn’t worked yet. This is easy and painless in Windows. It sounds like the latest xorg releases may help solve this situation with their Rotate and Render extensions ([RandR](http://en.wikipedia.org/wiki/XRandR)).
– Microphone doesn’t seem to work (although it does through VMWare Windows guest). Haven’t figured this out yet.
– Spotty webcam support in applications. Ekiga crashes. But yes, I found a [driver for my webcam](http://linux-uvc.berlios.de/). Too bad it didn’t come with Fedora 7 — I had to download, compile and install it myself.
– Slow hibernate/resume. The [TuxOnIce](http://www.tuxonice.net/) project supposedly remedies this, but I don’t want to spend all of my time tweaking my Linux box.
– Battery life. Even the Linux kernel hackers acknowledge that Windows gives better battery life than Linux. This situation is being remedied, gradually.

It takes more time than I want to spend to get Linux to run optimally on this hardware, and there are some Windows applications that just don’t have equivalents in Linux, like Print Master. My plan is to run Linux under [VirtualBox](http://www.virtualbox.org/) or [VMPlayer](http://www.vmware.com/products/player/).

I now realize that there’s huge value in an OEM preinstall of an operating system for end users. I had considered buying a [Ubuntu DELL laptop](http://www.dell.com/content/topics/segtopic.aspx/linux_3x), but let’s face it, DELL insiprons are ugly. HP systems are sleek, beautiful, and cost less while coming with more features (like a webcam).

Having a laptop is changing the way we work. Mobility is a huge win. We took the laptop with us when we went to vote in the primary election, because we had candidate information we could access using a web browser. There are downsides, of course.

We need a new printer and a new scanner with Vista drivers. We get to put up with frequent security dialogs interrupting our work flow. Vista itself consumes more RAM (nearly 500 MB), so we may need to upgrade to 2 GB. Vista runs slower than XP and Linux. Vista’s hibernate/resume is quite slow and gives no visual feedback during hibernation, just a blank screen. Vista’s boot and login experience is slow. Oh well. Life goes on.

FreeNX and SELinux

As I [mentioned earlier](http://jaredrobinson.com/blog/?p=87), upgrading from Fedora 6 to Fedora 7 broke FreeNX. A temporary solution was to disable SELinux. Here’s what allowed me to re-enable SELinux. First, I read the RHEL 5 SELinux guide to [building a local policy module](http://www.redhat.com/docs/manuals/enterprise/RHEL-5-manual/Deployment_Guide-en-US/sec-sel-building-policy-module.html). Next, I ran the following commands, as root:

setenforce Enforcing
/etc/init.d/auditd stop
mv /var/log/audit/audit.log /var/log/audit.log.old
/etc/init.d/auditd start

At this point, I used an NX client to attempt to connect to my server, which failed. Then I did this:

cd /etc/selinux
cat /var/log/audit/audit.log | audit2allow -M freenx
semodule -i freenx.pp

At that point, my NX client allowed me to connect to the server. Here’s the freenx.te file that audit2allow created:

module freenx 1.0;

require {
type unconfined_t;
type lib_t;
class file execmod;
}

#============= unconfined_t ==============
allow unconfined_t lib_t:file execmod;

Upgrading from Fedora 6 to Fedora 7

Last night, I completed the easiest Fedora upgrade I’ve ever had, without having to download and boot from a CD/DVD. Here are the instructions I followed:
[http://fedoraproject.org/wiki/YumUpgradeFaq](http://fedoraproject.org/wiki/YumUpgradeFaq)

I did have some unexpected glitches, mostly due to SELinux.

* The pidgin (formerly known as gaim) system tray icon didn’t appear until I deleted my .gconf settings and logged back in. This has the drawback that I had to reconfigure several aspects of my UI. It may be possible to only delete ~/.gconf/apps/panel/applets/systray (or to remove it from the panel manually), then re-add it by right-clicking the panel, selecting “Add to Panel” and chooise “Notification Area”.
* The Dovecot IMAP server wasn’t allowing Thunderbird to connect. I ran ‘yum upgrade’, and it installed an updated SELinux policy pack. After restarting, IMAP services functioned properly.
* HAL didn’t start up. To fix it, I ran ‘touch /.autorelabel’ as root and rebooted. Since then, I’ve learned that using [fixfiles](http://www.redhat.com/docs/manuals/enterprise/RHEL-5-manual/Deployment_Guide-en-US/sec-sel-admincontrol.html#sec-sel-fsrelabel) is a safer approach.
* FreeNX didn’t allow me to connect unless I disable SELinux. Later, I [figured out how](http://jaredrobinson.com/blog/?p=89) to configure SELinux to allow FreeNX.

Goodby VMWare, Hello VirtualBox

I’ve been using the freeware VMPlayer and VMware Server for a few years now, and while they function, it’s been a pain to have to recompile kernel modules every time the kernel is updated on my Fedora machines. A big disadvantage of VMWare is that the guests don’t seem to startup when run inside of an NX session, and I can’t run guests “headless” (without a monitor connected) using the free editions.

Based on the recommendation of [Craig Ozancin](http://www.linkedin.com/pub/0/826/810), I’ve tried [Virtual Box](http://www.virtualbox.org/), and I’m pleased with it — it lets me start and stop guests from the command line. I can connect to them using RDP (remote desktop). The new 1.4.0 release includes support for VMWare guest images! VirtualBox hasn’t required me to recompile kernel modules, and it seems to run faster than VMWare.

Goodbye VMware. Hello VirtualBox. What does the future hold? Probably [KVM](http://fedoraproject.org/wiki/Docs/Fedora7VirtQuickStart) (the [kernel-based virtual machine](http://www.phoronix.com/vr.php?view=9066)), which only works with newer Intel and AMD chips containing virtualization instructions.

I later discovered that when I (accidentally) ran the Xen kernel, VirtualBox wouldn’t work. It seems the Xen kernel doesn’t work well with third party virtualization solutions. It’s a good thing I don’t need Xen.

HOWTO disable middle-mouse-paste in Linux

A coworker couldn’t stand the fact that, on his linux computer, when he accidentally clicked the mouse wheel, it would paste text. He offered to buy me lunch if I could turn it off. Here’s how we did it. Run the following command:

> xmodmap -e “pointer = 1 25 3 4 5 6 7 8 9”

To persist this behavior, edit ~/.Xmodmap and add
> pointer = 1 25 3 4 5 6 7 8 9

Next annoyance: My coworker uses Eclipse, and wants to hit the F10 key. GTK (the toolkit underneath Gnome) maps F10 to pop up the application menu. In RHEL/CentOS 4, there’s no good way to fix it. On my Fedora 6 machine, I did the following:

> gconftool-2 –get /desktop/gnome/interface/menubar_accel

I saved off the value of that, which was “F10”. Then I ran this:

> gconftool-2 –type string –set /desktop/gnome/interface/menubar_accel “Ctrl-Shift-M”

It also works to use gconf-editor to edit the key /desktop/gnome/interface/menubar_accel.

SSH File System (sshfs)

I find that using `scp` to repeatedly copy files to a remote host gets tedious. Setting up NFS or Samba is often either not a viable choice, or is more work than seems warranted. Recently, I started using SSHFS, which I highly recommend. It works well because most servers I connect to support SSH, and therefore, my Linux box can use SSHFS to connect to them. Here are instructions for setting it up on Fedora Linux: [http://fedorasolved.org/server-solutions/sshfs/](http://fedorasolved.org/server-solutions/sshfs/)

glibc malloc hooks and TLSF

Recently, I was asked to constrain the memory usage of an application on Linux. Glibc provides hooks for [malloc, free, etc](http://www.gnu.org/software/libc/manual/html_node/Hooks-for-Malloc.html). By the way, the hook functions are responsible to guarantee thread safety — glibc doesn’t do it automatically. I used the malloc hooks in combination with a memory manager that a colleague found: TLSF. There are two implementations:

* [http://tlsf.baisoku.org/](http://tlsf.baisoku.org/) (public domain)
* [http://rtportal.upv.es/rtmalloc/](http://rtportal.upv.es/rtmalloc/) (GPL)

There are benefits and caveats when using a custom memory allocator. TLSF was meant to shine for real-time use, because the overhead of malloc and free are O(1) constant-time operations. On the other hand, TLSF isn’t thread-safe.