Sat Feb 25 17:38:59 EST 2006

Not Another Gallery Generator!


Well, the photo gallery generator is done as far as the features that I want. The bugs that I was able to find have been squashed, which means there are probably plenty still there. There are still some minor tweaks that I want to do before I post it though. One of those minor things is what the heck to call it?

Thus far I've just called it "gal" which seems sufficient but a bit to bland. So, between me and the guys on the LUG IRC we came up with these three possibilities:
  • bGal - bash Gallery
  • gash - GAllery in SHell
  • nagg - Not Another Gallery Generator!
Now, so far I'm torn between gash and nagg but I'm slightly leaning towards nagg.

What do you think it should be? Or do you have a suggestion? Please comment.

Posted by Brian | Permalink | Categories: Computers and Technology | |

Mon Feb 20 23:36:56 EST 2006

A bash Photo Gallery Generator


My friend, Ricardo, created a photo gallery generator called jgal that I've grown accustomed to using. Up until a couple of weeks ago jgal has been working, giving errors, but still working. However, It seems that a recent update to slackware-current has finally broken jgal beyond use. Well, not beyond use, but it no longer re-sized the slide images and thumbnails to their smaller size and instead leaves them all full size. I can fix this my manually resizing the image files. Or, even better, I could try to fix jgal for him and then give him the fix. The only trouble with that is jgal is written in perl, which I know essentially nothing about. So, I thought I'd take it upon myself to write up something that spits out the same thing as jgal, but using the only thing I know at the moment which is bash.

So far I have all of the features that I use working. Those being:
  • Image Captions
  • Forcing thumbnail and slide regeneration
  • Changing the default index file name
  • Using image caption for the slide titles, striping out the HTML tags
  • Linking directly to the image and not creating HTML slide files
  • Scaling of thumbnails and slide images
Now, I must say, this is probably the most educational thing I've done and the biggest thing I've ever written. So, I'm sure it's not written particularly well, but thus far, it works. Which is what I want. Of course, it's slow compared to jgal but it's not horrifically slow.

The big hurtle I ran into was generating the table to be put in the index template. I used a place holder <!--INDEX-TABLE--> in the template with the idea that I could use sed to insert the table. I could send the HTML to the screen and have it look right, but then sed would choke on it. I even had the special characters escaped properly. And you wouldn't believe how difficult it is to get an answer other than "use perl" when asking for help in forums! I know, perl is easier, but only if you actually know perl in the first place. I needed a solution using something that I sort of knew, and it just didn't make any sense that sed or awk was not capable of doing what I wanted. Ultimately, the problem was me using the search command in sed. It just didn't like the multiple lines and would complain about an improperly terminated search string or something like that. I had a working function called indextd that spit out the HTML. After much prying and reminding that I don't know perl I finally got a decent suggestion, use the Change command like so:
sed "/<\!--INDEX-TABLE-->/c\
\\$(indextd)
"
The c\ is the change command and the \\ preserves the leading spaces in the replacement text.

Oh, something else I learned is that it seems sed doesn't know how to do a non-greedy match with a regular expression. In trying to strip off the HTML of the captions to be used in the page title I tried s/<.*?>//g but sed was unhappy with that. What does work is s/<[^>]*>//g which essentially says that the match can't include the end of it in the middle anywhere. So, it only matches the complete tags and not the first tag it sees, the last tag it sees, and everything in the middle.

Anyway, I'm going to keep working on this script, even just for the learning experience. Plus when I'm done I'll have a practical utility.

One day I'll have to learn perl. bash+sed+grep can't do everything, but for my purposes they do most everything that I want at this time.

Posted by Brian | Permalink | Categories: Computers and Technology | |

Mon Feb 13 19:54:59 EST 2006

Suspend2 - Change Suspend File Size


This is another one of my posts that's more for my notes than anything else. I recently (as in today) got more memory for my laptop taking it from 256MB to 512MB. Since I'm using Suspend2 to suspend to disk and am using the suspend file vs the swap partition I had to increase the files size. The original one was only 300MB, not enough to hold my physical RAM if it was full. So, I went to the Suspend2 website and found out that the instructions for creating a suspend file are not easy to find. Eventually I found the answer buried on a Gentoo Wiki.

The steps were as follows:
  1. Delete my old suspend file.
  2. Edit my hibernate.conf file by changing the FilewriterLocation line. The last number on the line is the size of the file to be created in MB. I just made it a number larger than my physical RAM.
  3. As root run hibernate --no-suspend which will create the file and then tell what "resume2" line to put in your bootloader. If using LILO don't forget to run lilo before rebooting.
That's it. Try a suspend and resume to see what happens. But make sure to get it right the first time and have a good backup because resuming from a bad suspend file has the potential to ruin your file system.

Posted by Brian | Permalink | Categories: Computers and Technology | |

Wed Feb 1 22:46:58 EST 2006

IE 7 Beta Preview Impressions


Last night I installed Internet Explorer Beta 2 Preview on my Windows XP partition. After 5 minutes or so of install and a reboot I loaded it up and found it looks very much like Firefox. It even has the search bar in the upper right just like Firefox, except that it points to MSN as your search instead of Google. Of course, tabbed browsing is there as we've all heard would be. It even uses the same short cut key of CTRL-T to open a new tab, just like Mozilla and Firefox. One thing I did noticed though was the Quick Tabs feature, which shows a thumbnail view every tab you have open allowing you to visually choose which one to go to. I at first thought this was a unique thing that Microsoft added that Firefox couldn't do. Then I found Firefox Showcase which is an extension to Firefox that does the exact same thing. IE7 finally has some anti-phishing stuff built in which is nice for the gullible average user. But that isn't even unique as Firefox also has extensions to deal with that such as SpoofStick.

I must admit though, I like the IE7 way of dealing with RSS better than the default Firefox way. When you subscribe to a feed it gets added to your favorites in the feeds category. When you choose a feed it gets presented to you in a nice, easy to read web page rather than the annoying pop out menus that you get from Firefox. If Firefox did RSS in a similar way I may actually stop using Bloglines. I need to research more on RSS related extensions for Firefox.

The pop up blocker seems adequate in IE7, though to be fair only 24 hours or so of using it probably isn't a good test. Though I find it hard to believe that anything that Microsoft can come up with would be better than Adblock Plus plus the Adblock Filterset.G Updater. That combination of plugins not only stops 99.9% of the pop ups but removes banner adds and other annoying things.

My first impression with this preview is that Microsoft is simply playing catch up. I don't really see anything that is new or can't be easily done via Firefox extensions. I'm guessing though that the average Joe will now be more inclined to just use IE 7 since it has pretty much the same features and comes already installed (or will come already installed). IE 7 has more functions out of the box than Firefox too, which is good for the typical user. We can't expect the typical user that can't change their home page, or always clicks on the "Free Offers" to figure out how to install an extension even though it so easy a retarded monkey could do it.

I'm not giving up my Firefox any time soon. But I have to say in comparing IE6 with IE7 that it's a huge improvement. Even though the improvements just make it more like Firefox. Who knows though, maybe there are more improvements under the hood than I realize? Time will tell if IE7 remains the giant security hole that IE6 has been.

Posted by Brian | Permalink | Categories: Computers and Technology | |

Wed Dec 28 20:05:44 EST 2005

Christmas Present from Choice One


As far as Christmas celebrations go this year was typical for us. Two fun and exhausting days where the kids get overloaded with excitement and my wife and I get less sleep that we would have on a typical day during the work week. All in all it was a good time with family and the presents were mostly practical for the adults which is what I wanted anyway.

My extra fun was on Dec 23rd just before the holiday weekend. I was thinking it was going to be a nice easy day. I was scheduled to install a new PC for someone around 10AM but instead was redirected to one of our largest customers, a multi-branch local bank. There really isn't much to the story to be told really but keep in mind that even though it's short it was highly stress inducing.

The problem specifically was that every branch was cut off from the main branch. Meaning they could not access any of their files located on the server there. Nor could their database function without the links being up 100%. The odd thing though was that I could access the Internet, ping all the servers across the VPN for all the other branches, and even PCAnywhere to them. What I couldn't do was access a SMB share or see anything other than local LAN systems in the browse list. It would have made 100% perfect sense if I couldn't ping, PCAnywhere, etc but this seemed to target just SMB related things. We had a case open with Microsoft support recently for an issue that was close enough that I could get help without started a new case so I called them up and we checked out the server. It turned out that, for some odd reason, ports 135, 139, and 445 were being blocked and it appeared that Windows wasn't the culprit this time. More detective work showed me that this was the case at all branches that used Choice One as their managed VPN provider but thing were perfectly fine at branches that didn't use Choice One. The next step was clear, and that was to call Choice One up and see what the heck was going on.

Once I slogged through the menus and got an actual person (located in the USA no less!) he didn't see anything wrong, no open tickets, no troubles reported, and no notes related to recent security related changes. Still, I had already proven that I couldn't telnet to any of the SMB related ports, and Windows looked OK so I asked him to check the ports instead of trusting the account notes. Besides, if the OS was the problem we would likely have had local problems as well and been only limited to effected servers. He opened up the ports and in a flash things were working as before.

It turns out that over the past few months Choice One had been closing off the SMB related ports for their clients on externally accessible addresses to combat the spread of viruses. It seems someone took it upon him/herself to close off these ports on the banks VPN stopping it on the internal side and then didn't make any notes in the case related to it. And in doing so managed in a few moments to bring every branch to a halt.

Really, it was such a simple problem at the root of it all, but it took on the order of 5 hours to pin point he problem, get it fixed and then tested. All the while having the manager freaking out and thinking it was some how our fault. Anyway, at least it worked out. The bank was up by the end of the day and it wasn't caused by anything we or anyone at the bank did wrong. Even so, thanks goes to Choice One for poor documentation, lack of procedure, and inducing a mountain of stress just prior to a holiday due to some individuals incompetence.

Posted by Brian | Permalink | Categories: Computers and Technology, Miscellaneous, Work | |

Fri Dec 16 15:29:50 EST 2005

Yahoo! owns del.icio.us


I just saw on Wired News that Yahoo bought del.icio.us. I don't know what this will mean. If del.icio.us will change or not remains to be seen. Just in case though I'm going to think about some alternatives to it. I know you can export all your bookmarks into an XML file for backup purposes. Does something exist out there that can read in that backup? It would be nice to bring the archiving of bookmarks to my local server instead of relying on an external source.

Who knows, maybe nothing will change but I think I'll just wait and see. And have a backup if Yahoo screws it up.

Posted by Brian | Permalink | Categories: Computers and Technology, News | |

Fri Dec 2 07:56:02 EST 2005

X11 Forwarding over SSH


One of the things I've been wanting to do but not made much of a priority is 11 Forwarding over ssh. For some reason getting this to work has been vexing me for the past couple of weeks because most references I've found have you messing with the xhost command, exporting your DISPLAY variable, and tunneling the remote computers port 6000 to your workstation. Now, I got all that working not using SSH but just couldn't get it with ssh.

It turns out the solution is super simple. The steps were as follows:
  1. Make sure X11Forwarding yes is somewhere in your sshd_config. For Slackware all my global ssh config files are in /etc/ssh/.
  2. Restart sshd. On Slackware just run /etc/rc.d/rc.sshd restart.
  3. In ssh_config make sure there is a line ForwardX11 yes somewhere.
Once that's done just ssh into the target machine and run your X application and it will appear on your screen. Can't get much easier than that.

I learned a couple of other cool things about ssh while I was messing around. I have a couple of ports that I want to tunnel though ssh every time I connect without having to do ssh -L <port>:<address>:<port> every time I connect. It turns out you can put user specific settings in $HOME/.ssh/config. So, if I wanted to tunnel port 80 and port 5900 through ssh I'd add these two lines to my config file assuming that the machine I'm doing the forward with on the remote network (the one sshd is running on) is addressed 192.168.6.2.
LocalForward	80 	192.168.6.2:80
LocalForward 	5900	192.168.6.2:5900 
LocalForward is the equivalent of -L on the ssh command line and RemoteForward is the same as -R. The ssh man page explains it well.

While I was messing around I also put PermitRootLogin no and Protocol 2 in to deny all login attempt for the root account and to only accept sshv2 connections just to make it a little more secure. I put those in the global sshd_config file rather than my personal one.

Posted by Brian | Permalink | Categories: Computers and Technology | |

Thu Nov 17 22:03:58 EST 2005

Laptop Drive Imaged Successfully


Whew, it was a pain but I finally got the drive imaged. Even though I marked the blocks as bad partimage still failed due to bad blocks. I thought partimage was intelligent and read the file system data so that it only backed up the blocks in use by the file system, but apparently not in this case. There probably is a really good reason that I don't understand since I'm not a file system expert.

Anyway, I finally got it to work with dd. I just marked the bad blocks like mentioned in this previous post then followed the steps I gave here to zero out the free space and make the image. The only thing I did different was I piped it through split to divide the image into manageable hunks that can fit on a FAT32 partition or onto a DVD-R. Oddly enough, prior to marking the blocks as bad dd complained about finding bad blocks. But, after marking them as bad dd didn't complain at all. This is the command I ultimately used:
# dd if=/dev/hda2 conv=sync,noerror bs=64K | gzip -c | split -b 2000m - hda2.img.gz.
This produced a 3 files named hda2.img.gz.aa, hda2.img.gz.ab, and hda2.img.gz.ac with the total being just over 4GB when added together. The actual data was about 7GB on this partition so zeroing out the free space really did help cut down the image size, considering that the partition is about 19GB in size.

I haven't tested it yet, but I figure I can get the image back using something like:
# cat hda2.img.gz.* | guzip -c | dd of=/dev/hda2 conv=sync,noerror bs=64K
So, why did I take all this effort to make an image rather than using something like tar? Well, no real reason other than a utility like partimage should be able to work around an issue like this. This is a drive that is brand new, and sometimes a new drive has errors. A couple of bad sectors are OK as long as the file system knows about it and does not use them. If I want to backup a drive like this using a program like partimage then I should be able to. Actually, the odd thing is, I would have never known the bad blocks existed if I didn't try using partimage. reiserfsck --check never found a single problem.

Sure I could have used tar, but then I wouldn't have learned how to use common Linux tools to do the same job! :D

Posted by Brian | Permalink | Categories: Computers and Technology | |

Tue Nov 15 23:50:11 EST 2005

Reiserfs - Dealing with Bad Blocks


Well, it seems my problems getting an image of the drive was a problem with the drive itself not the applications I was using the make the image. As I've said before, Partimage just would bomb out at the same point each time. I tried the dd procedure mentioned in my previous post and that barked about problems at about the same location in the imaging process as partimage did. That being said I figured all I had to do was scan the drive for bad blocks and mark them as such. Now, for some odd reason, in reiserfs you have to do this manually instead of just letting fsck take care of it for you with the -c switch. I don't know why this is the case but here is what I had to do.

Boot into a live CD like Knoppix and make sure it has the latest reiserfs tools as specified here. Also, I suggest you read the man pages for all the commands here and understand all the options. One mistake with these things can cause data loss.
  1. Find out your partitions block size. This is 4096 by default in reiserfs but you can use the debugreiserfs command to find out what it is. It's important for the badblocks command next.
    debugreiserfs <device> | grep -i 'blocksize'
    
  2. Run badblocks to scan the drive and store the list of found bad blocks in a file. I'm assuming the blocksize is the default here, if it isn't replace 4096 with the number given by debugreiserfs.
    badblocks -n -b 4096 -o badblocksfile <device>
    
  3. Then run reiserfsck to fix the areas where the bad blocks are and mark them to not be used again.
    reiserfsck --fix-fixable --badblocks badblocksfile <device>
    
    Supposedly you can use reiserfstune to just update the bad blocks list without having to run a check and a fix but in may case the bad blocks were already in use in the tree. Reiserfstune made it clear I had to use reiserfsck in the error message.
So, right now I have partimage trying to image the drive. Hopefully with the blocks marked bad it won't trip up anymore.

Posted by Brian | Permalink | Categories: Computers and Technology | |

Mon Nov 14 22:11:05 EST 2005

Image You Hard Drive with dd


I just found this article that explains how to use dd to image a hard drive. Being that partimage has some strange issue that I can't seem to work out in imaging my Laptop (and just my laptop it seems) I figure I better have a backup plan. I'm not sure if I'd do this or just tar the drive up. What would the advanage of one be over the other I wonder?

Below is the text of the article by sandip from his blog at Linuxweblog mainly for my notes and just in case the original site would go down for some odd reason.
  1. Boot from the live cdrom distribution.
  2. Switch to root.
  3. Make sure NO partitions are mounted from the source hard drive.
  4. Mount the external HD.
    # mount -t vfat /dev/sda1 /mnt/sda1
    
  5. Backup the drive.
    # dd if=/dev/hda conv=sync,noerror bs=64K | gzip -c  > /mnt/sda1/hda.img.gz
    
    "dd" is the command to make a bit-by-bit copy of "if=/dev/hda" as the "Input File" to "of=/mnt/sda1/hda.img.gz" as the "Output File". Everything from the partition will go into an "Output File" named "hda.img.gz". "conv=sync,noerror" tells dd that if it can't read a block due to a read error, then it should at least write something to its output of the correct length. Even if your hard disk exhibits no errors, remember that dd will read every single block, including any blocks which the OS avoids using because it has marked them as bad. "bs=64K" is the block size of 64x1024 Bytes. Using this large of block size speeds up the copying process. The output of dd is then piped through gzip to compress it.
  6. To restore your system:
      # gzip -x /mnt/sda1/hda.img.gz | dd of=/dev/hda conv=sync,noerror bs=64K
    
  7. Store extra information about the drive geometry necessary in order to interpret the partition table stored within the image. The most important of which is the cylinder size.
      # fdisk -l /dev/hda > /mnt/sda1/hda_fdisk.info
    
    Notes:

    One of the disadvantages of the dd method over software specifically designed for the job such as Ghost or partimage is that dd will store the entire partition, including blocks not currently used to store files, whereas the likes of Ghost understand the filesystem and don't store these unallocated blocks. The overhead isn't too bad as long as you compress the image and the unallocated blocks have low entropy. In general this will not be the case because the emtpy blocks contain random junk from bygone files. To rectify this, it's best to blank all unused blocks before making the image. After doing that, the unallocated blocks will contain mostly zeros and will therefore compress down to almost nothing.

    Mount the partition, then create a file of zeros which fills the entire disk, then delete it again.
    # dd if=/dev/zero of=/tmp/delete.me bs=8M; rm delete.me
    

Backing Up the MBR

# dd if=/dev/hda of=/mnt/sda1/mbr.img bs=512 count=1
This stores the first 512 bytes of the disk (contianing the MBR and the primary partition info - i.e. the first four primary entries) into the file "mbr.img".

To restore (be careful - this could destroy your existing partition table and with it access to all data on the disk):
# dd if=/mnt/sda1/mbr.img of=/dev/hda
If you only want to restore the actual MBR code and not the primary partition table entries, just restore the first 448 bytes of the MBR:
# dd of=/dev/hda if=/mnt/sda1/mbr.img bs=448 count=1.

Posted by Brian | Permalink | Categories: Computers and Technology | |

Sat Nov 5 15:06:19 EST 2005

More Added to "Slackware on Thinkpad" Article


I just added more info to the Slackware Thinkpad article. Specifically I've added more on general power saving and how to automatically hibernate when the battery goes critical. Read and comment if you wish.

Posted by Brian | Permalink | Categories: Computers and Technology | |

Wed Nov 2 23:52:11 EST 2005

Getting Slackware 10.2 on my Thinkpad T30


Well, all this talk about configuring Slackware 10.2 on my Thinkpad has turned into a few blog entries so far. So I decided to consolidate what I've figured out, as well as what I figure out in the future into an article instead of having it peppered all over my blog.

I know it's a bit Slackware and Thinkpad specific, but the general theory should be universal. Take a look and see what I have so far and let me know what you think.

Posted by Brian | Permalink | Categories: Computers and Technology | |

Wed Oct 26 20:59:32 EST 2005

Thinkpad T30 - Hotswap, and Software Suspend


One of the things that I've gotten used to in Windows is the nice Hibernate feature. I like to just close my laptop and have it suspend to disk then quickly resume. I'll do this several times a day during my work. I figured, if Windows can do it, then Linux should be able to do it better right? :D

Well, it wasn't exactly easy but it built on what I learned messing with ACPI as I talk about in my last post. First of all, there really isn't any specific documentation for Slackware when it comes to suspend to disk that I could find. But, I found some info on Gentoo, Debian, and Fedora which was useful. Now it turns out that in the 2.6.13 kernel (and possible older ones I don't know) that there is already a suspend to disk feature right under power management in your menuconfig. I gave that a shot and lets just say it doesn't play well with my Thinkpad. Basically I can suspend it but it never comes back. It tries to resume but then locks.

Some more research pointed me to a project called Software Suspend 2 for Linux that actually works. Basically it consists of a kernel patch for the vanilla 2.6.13 kernel and a hibernate script. Both the patch and the support scripts are super easy to install. The documentation and the FAQ are really nice on their site. Once you compile the kernel with suspend2 enabled you can either suspend to a file or to swap space. To resume you just add an option to your lilo.conf or your grub menu.lst file to tell the kernel where you expect a suspend file or partition. Then all you have to do it type hibernate and it will suspend to disk. They even have a tip on how to setup sudo so you can hibernate without being root which lets you use it in something like Klaptop to hibernate the system when the batter gets critically low.

This is all well and good but I want to set this up so that it will hibernate when i close the lid of the laptop regardless of if I'm in KDE or at the console. Oh, and make sure not to use the hibernate function of Klaptop with suspend2. It corrupted my drive so bad I had to reinstall. I'm thinking it may have been something I did wrong in the hibernate.conf file but since I'm not planning on using klaptop to take care of the lid I didn't look into it.

Anyway, I figured acpid would be the way to go to catch the lid button event and have it run hibernate for me. Watching /var/log/acpid gave me a event called "button/lid LID 00000080 00000001" but I found out the hard way that it actually counts up such that the last bit of it changes. Pressing the button counts as an event as well as releasing it. So I couldn't just check for the entire thing. Also, I needed to make it only suspend on every other event. Otherwise it would suspend on the lid button press and would then suspend again right after the resume when it would get the lid button release. The suspend2 FAQ had the answer. Here is what worked for me:
event=button[/]lid LID.*[13579bdf]$
action=/usr/local/sbin/hibernate
I just stuck that in a file in the /etc/acpid/events directory along with my other events and issued a /etc/rc.d/rc.acpid restart and now the laptop suspends to disk perfectly every time I close the lid. As a point of interest I initially made the event expression to be event=button[/]lid LID.*[02468ace]$ which had the odd effect of only suspending the system when opened the lid.

One word of advice, if you try to set this up manually like I did rather than relying on your distro to set it up for you then do it on a test system. It seems that once you get it tweaked and working it works fine, but one mess up while learning it can irreversibly corrupt your file system. On, and one other thing of to note, read the section of the How to Avoid Data Loss section of the HOWTO if you mount a Windows partition to avoid killing your fat vfat or msdos partitions.

The other thing I did that was much easier than figuring out all this ACPI and suspend to disk stuff was figure out how to hot swap my drive bay so I can switch between my floppy and my CD-ROM without having to reboot. The utility to use is called Khotswap that sits in your system tray in KDE. The author also has a Gnome applet for it and it has a command line only version of itself just called hotswap and an X generic one called xhotswap.

So, at this point I'm well on my way to getting the foundation of the laptop done in Slackware enough to start thinking of setting up the rest to use for day to day work. I know, I could have used another distro and had much of this stuff work right out of the box. I hear Ubuntu is very good at this. But if I did that where would the challenge be and what would I learn in the process?

Posted by Brian | Permalink | Categories: Computers and Technology, Work | |

Sun Oct 23 19:05:42 EST 2005

ACPI and Speedstep with Linux on my Thinkpad


Well, I've decided to go with Slackware for the laptop mostly because it's what I know. So, Slackware being what it is I had to take matters into my own hands and configure some of the more ugly things that may be done for you in other distributions. In this case it was ACPI and CPU Frequency Throttling (Speedstep). I don't know for sure if this stuff just works on another distro as I didn't try. What can I say, it's hard to break the Slack habit. ;)

The laptop in question is an IBM Thinkpad T30 and according to Google it is well supported in Linux (mostly). I went and installed Slackware 10.2 and most everything worked right out of the box like sound, wireless LAN, and APM. APM worked fine except that I didn't see any support for the Thinkpad buttons and saw that the kernel had a module just for Thinkpads in ACPI. Rather than figure out just what modules I needed to modprobe in I just compiled the things right into the kernel since I can't think of any time I'd not want them there. That worked well, the sleep button worked and when I closed the laptop lid the system went to sleep.

I did notice though that when I was on batter i was only getting about 40 minutes of run time when I was getting about 1.5 hours in Windows. So then it was onto learning how to throttle the CPU speed. Now, this was a pain in the rump. I had the modules I needed loaded and no matter what I did Klaptop wouldn't change the CPU speed when going from between battery and AC. I even compiled all the modules directly into the kernel to see if it helped. No go. I could change the speed manually but not automatically.

It turns out that after some research I learned that this model only supports two speeds of CPU. One at 1.8GHz and the other at 1.2GHz. Klaptop wanted to throttle based on percentage. For some odd reason I could set the percentage manually and it seemed to make a difference in performance but it just wouldn't do it automatically.

So, as far as CPU frequency throttling it can be by a userspace program or by the kernel itself. Klaptop is a userspace program and since that wasn't working I decided to try out letting the kernel do it. I compiled in speedstep-ich and the ondemand governor. The idea is that the ondemand Governor will watch your current CPU needs and adjust the speed accordingly. To get this working all you have to do is make sure the ondemend module and the speedstep module is loaded (or compiled into the kernel) and then echo -n ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor and supposedly it will "just work". For some reason when I echo ondemand into scaling_governor it doesn't take and just stays as userspace. I haven't put much effort into figuring out the why since I'm a bit tired of playing with this. I did figure out that I could manually echo either 1200000 or 1800000 into /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed and it would work. But how to make it do this automatically?

All I did was kept and eye on /var/log/acpid with tail -f and unplugged the AC adapter and plugged it back in a few times. In my case every time I plugged in the adapter it generated an ACPI event called "ac_adapter AC 00000080 00000001" and when I unplugged it a "ac_adapter AC 00000080 00000000" event was generated. All I had to do was create two scripts in /etc/acpi. One of the scripts I called on_battery.sh and it contains:
# Sets the CPU to 1.2 GHz when on battery
#
echo -n 1200000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
#
# Set Hard Drive sleep to 5 minutes
hdparm -S 60 /dev/hda
And the other one called ac_cpu.sh contains:
# Sets the CPU to 1.8 GHz when on wall AC
#
echo -n 1800000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
#
# Set hard drive sleep time to 20 minutes
hdparm -S 240 /dev/hda
I made them executable then went into /etc/acpi/events and created two new files to catch and then run the script to make the CPU frequency change. The two files can be called pretty much anything as far as I can tell as long as they aren't hidden files. I called one ac_cpu and the other onbattery_cpu. ac_cpu contains:
event=ac_adapter AC 00000080 00000001
action=/etc/acpi/ac_cpu.sh
and onbattery_cpu contains:
event=ac_adapter AC 00000080 00000000
action=/etc/acpi/onbattery_cpu.sh
Finally I had to restart acpid with /etc/rc.d/rc.acpid restart and it worked! Now I can get about 1.5 hours out of a full charge instead of 30-45 minutes. And I can put other commands into the scripts to do other things when the state changes. You can see I already have hdparm to tweak my sleep times.

Posted by Brian | Permalink | Categories: Computers and Technology, Work | |

Thu Oct 20 19:01:08 EST 2005

Moving Forward getting Linux on the Laptop


Today the 60GB hard drive for my laptop arrived at work. I've been wanting to dual boot with Linux on it for some time but the 15GB drive wasn't enough to give either Windows or Linux enough space and still be able to hold my work files. So I was faced with a choice of going cold turkey to Linux which I didn't want to do since I need to actually get work done on it. With the extra space I can make the change gradually like I did at home giving me time to work out any oddness that may crop up. I'm thinking it will go much more smoothly this time since I've already been using Linux for a couple of years but I'm a little nervous since I've never setup any Linux distro on a laptop.

This brings up one big question though. What distro to try first? ;)

Posted by Brian | Permalink | Categories: Computers and Technology, Work | |