Byobu (Advanced GNU Screen) under Centos 5/Python 2.4

I recently discovered Byobu, which is a set of scripts that lets you use GNU Screen more easily. If you spend a lot of time ssh’d into a server, you should definitely check it out. It worked fine on my desktop machine, but on my Centos 5 server, not so much. I did a little research and I found there were two problems.

The easy problem was keeping F2-F4 from working. The trick is that /etc/screenrc has the following line in it:

termcapinfo xterm 'k1=\E[11~:k2=\E[12~:k3=\E[13~:k4=\E[14~'

Commenting out the line make the function keys work! That was easy.

The 2nd problem was that F9 was not bringing up the menu. Well, most of the time. Sometimes you could get a peek of a Python traceback and sometimes — not often — it would work. The real puzzle was that if you started byobu-config from the command line it worked fine.

It turns out Centos has Python 2.4 which is pretty old. I intercepted stderr from the script and found out that a command that was reading from a pipe was returning “System Call Interrupted.” This isn’t really an error, but this version of Python apparently thinks it is. So sometimes, that signal wouldn’t interrupt the pipe and it would work.

I tried installing Python 2.6 but there are a lot of dependencies in Centos on Python and although I found someone with a “parallel” RPM it didn’t have the necessary libraries and I finally gave up. But then it hit me. If I could just pause a bit before the offending pipe, the signal would come in — not interrupt the pipe — and then all would be well. It seems to work!

Here’s the fix:

if os.path.exists("%s/.%s/disable-autolaunch" % (HOME, PKG)):
return 0
time.sleep(3)

The script already imports time, so that wasn’t a problem. Problem solved. I like Byobu!

Speeding up Ubuntu Linux with SSDD

A lot of people are switching their Windows machines to boot of solid state disk drives (SSDD) to get faster boot times. The price of these drives has been dropping, but since I use Linux (Kuuntu, actually, which is Ubuntu with KDE) it didn’t make much sense to me. I maybe reboot my machine once a month. What do I care if my reboot time is 30 seconds faster?

Fry’s had a 64GB SSDD on sale this week. After rebate it was around $85 after rebate (you can get roughly the same deal at Newegg). They had a 32GB drive (which had slower specs, too) for even less. So I couldn’t resist. The drive was for a laptop, but the SATA connectors fit. I bought a $4 pair of brackets to make it fit, but in the end since the thing doesn’t spin, I just let it sit on top of a drive tray — I’ll probably secure it later, but for now it is just sitting on the inside. I formatted the whole device with btrfs (no partitions at all) and sure enough I had about 59GB of useful space in a new volume.

I edited fstab to have the line:

UUID=f9f6588e-dc7f-4675-b132-8b008486d243      /ssdd1    btrfs  defaults,ssd,noatime,discard

Of course, your UUID will vary. I had to create /ssdd1 as root and then I did a mount -a to put the drive in place. Now… how to make things go faster?

My basic idea was to copy stuff that KDE, X Windows, etc. uses a lot to the SSDD. I didn’t care so much about user files and I didn’t want the constant writing of /tmp or things from /var (in general) since SSDDs have some limit on write endurance (although modern drives do pretty well if you look into that). And I didn’t want to get messed up with things in /boot or things that I would need if the drive ever failed to mount (/bin, /sbin, and /lib, for example).

What I did was make exact copies of /usr/share, /usr/lib, /usr/bin and put them on /ssdd1/usr/share, and so forth. You have to make exact copies since some things in /usr/bin are suid — that is, they run as their owner and a normal cp won’t do the job (not without a lot of options; look at -p, for example). I used cpio:

find . -print | cpio -admp /ssdd1/usr/bin

Obviously, you need to be root to do that and you need to be in the /usr/bin directory. Once I had the directories in place, I had to move the old directories (I was too chicken to delete them) and link to the new one. Before you do that, though, I’d check that /usr/bin/sudo was in place on the SSDD and that its sticky bit was set. If you lose that and you have no root account set…. well… let’s not do that, ok?

Moving /usr/bin is a little tricky because you need to be root, but sudo is in /usr/bin! The easiest thing to do is just become root even though that angers the Ubuntu faithful:

sudo -i

Then you can do commands like the following:

mv /usr/bin /usr/bin-old ; ln -s /ssdd1/usr/bin /usr/bin

If things go wrong you can still get to things via /usr/bin-old.  So if you do mess up you could do something like:

/usr/bin-old/sudo mv /usr/bin-old /usr/bin

That actually sped things up quite a bit. Booting is notably faster and the response time of X in general is greatly improved.

I then repeated the steps but this time I made shadow directories for ~/.config and ~/.kde. I redirected these to /ssdd1/home/alw/.config and /ssdd1/home/alw/.kde, respectively. This also made the system much snappier.

There are other ways you could have done this. I considered loop mounting over the existing directories, for example. This would be very safe since if the drive didn’t mount you’d just lose performance. The issue is you’d need to occasionally sync the real directory and the shadow directory to be sure any updates were applied. I had bad luck with a scheme like that for putting Firefox’s files into a ram drive — if it does get out of sync, look out. Of course, my scheme has a similar issue — if you lose the SSDD your old files are out of date. But with my setup there is no way for updates to occur to the old files (for example, if the SSDD fails to mount and you don’t notice) making them  mismatched in both directions. You can rsync them from time to time, either way, but with my method if the SSDD fails to mount you will know it immediately. Also, the old files stay visible making syncing them easier if you care to do that.

Meanwhile, I’m happy with how fast this has made my system. Granted, it was fast to start with (8G of RAM, 3.6GHz, and 4 cores), but the system does boot much faster, Gimp loads almost immediately, and switching between tabs in Chrome is notably faster. Since the system files are just moved and not removed, this “update” is fairly safe — you can still get to the original files if you have to. Just remember that updates will not change the old copies.

UPDATE: Turns out Apparmor realizes that things aren’t in /usr/bin anymore and starts blocking things. The only thing I noticed was my printers (the CUPS daemon won’t start). You need to go to /etc/apparmor.d/tunables and edit the alias file. Then reload apparmor and reload affected services (or reboot, which is easier). Here’s mine:

alias /usr/bin/ -> /ssdd1/usr/bin/,
alias /usr/lib/ -> /ssdd1/usr/lib/,
alias /usr/share/ -> /ssdd1/usr/share/,

UPDATE #2: VirtualBox does not like /usr/lib as a symbolic link, I’m not sure why but the code specifically checks for this case and throws an error. I had thought about using bind mounts instead of symlinks before and this pushed me over the edge. So I still use the symlinks for stuff in my home directory but for /usr instead of creating bin, share, and lib links I created empty directories to use as mount points. Then in /etc/fstab I put:

/ssdd1/usr/bin   /usr/bin   bind   defaults,bind   0 0

And similar lines for /usr/share and /usr/lib. Now Apparmor is happy and so is VirtualBox. I assume fstab mounts in order, so be sure those lines come AFTER the mount of /ssdd1, of course.

And one more update: Nepomuk and Strigi — which always give me grief anyway — write huge files to ~/.kde/share/apps/nepomuk/blah blah blah. This will quickly fill up a small SSDD. So one more link. I made ~/.nepomuk and then linked it in the ~/.kde tree. UNFORTUNATELY, filling up a btrfs volume causes it (at least in my case) to become totally unusable and unrepairable. So I would up switching everything to ext4. No compression, but better than having a total crash of the drive when it gets full.

After I had the crash I decided it would be nice if the regular hard drive had a pretty recent copy of what it was supposed to have. Since I had the space full crash about a week after I installed, it wasn’t so bad, but what if it had been a year or more later? Luckily, I had followed a simple pattern to replace the directories. Given some directory I wanted to replace called /x/y/z, I copy it to /ssdd1/x/y/z and then rename the original to /x/y/z-nossdd. Finally a bind mount or symlink points the original location at the SSDD.

Given that pattern, it was easy to create a daily cron job (/etc/cron.daily) named ssdd-backup:

#!/bin/bash
for dir in /home/alw/.kde /opt/google /usr/bin /usr/share /usr/lib /usr/include /usr/lib32 /home/alw/.config /home/alw/.local
do
rsync --archive --update --quiet /ssdd1$dir/ $dir-nossdd
done
This runs every day early in the morning and ensure that the old directories get any updates. The update is NOT two way. If you change something in xxx-nossdd, that does not propagate to the SSDD (but why would you?). Of course, you’ll want to modify the first line to name the directories you actually shadowed.

Viewing EFX Fax Files (EFAX) with Linux (or anything else probably)

I get about 2 faxes a year, so I hate to stand up a dedicated fax machine and phone line. There is, of course, a free fax service available. But the problem is the free version only delivers proprietary efx files. To open these you need to run the eFax software. Sure its free, but its Windows only! Might run under Wine with some coaxing and, of course, you can run Windows in VirtualBox, but what a pain just to open a fax or two a year.

EFax will let you get the fax as PDF if you upgrade. I just don’t get enough faxes to justify that. But there is a way.

If you log into your account online you will see several options including “View Faxes.” Click that. You get a web page that looks like an e-mail inbox. You’ll see the faxes you have received. Click the fax you want to view or print. This will load a preview pane at the bottom. But you can only look at the first page. Double clicking the fax brings up a  new tab that shows the same preview image. But there is a link in the header that says “View Fax: xxxxxxxx.efx” (where the x’s are the file name). You’d think that would just download the efx file, right? Nope.

Click the link. Go on. Now you have a viewer that lets you pick a page of the FAX, zoom it, and rotate it. If you just need to look at the fax you are done. But I wanted to print mine. Am I out of luck? Here’s the trick: Right click on the displayed fax (it doesn’t matter if you can see it all or not). Depending on your browser you’ll get an option like “Copy Image URL” (I guess you could also “Save Image” and then go open the image in your favorite picture editor and go from there.  With the Image URL, go to a Web browser and paste it into the URL bar. Woo hoo! You now have a full page image that you can print from the browser. Different browsers handle images differently, so you are on your own at this point. On Chrome I’d zoom the image up to 100% and print and I got nice full page faxes. If you were not at 100% the print would be smaller than the page.

Of course, if you have a 100 page fax its a pain to have to do this for every page. But seriously, if you are getting 100s of pages of fax, subscribe or install the free app under VirtualBox or Wine! But for those of us who left most of our faxes back in the 1990’s this is an easy way to get faxes printed without Windows.

Upgrade to Ubuntu (Kbuntu) 10.04 Fails

Like an idiot I always upgrade stuff. Can’t help it. I know better. Really. I do.

I ran the install and got an error that apt’s post install script failed. Then it kept going for some time. And then it decided it had failed and my system was in an unstable state. Have a nice day.

I could still boot to the old kernel (the new kernel worked but the system was too trashed to rebuild the Nvidia drivers).

Turns out in /var/lib/dpkg/info/apt.postinst there is a function called:


set_apt_proxy_from_gconf

What’s more is down a ways in the script it calls this line and that is what makes it fail. Three hash signs later and the system is happily configuring away!

Hope that is useful info for you.

Remote Access

Recently I wanted my wife’s machine to be able to run a particular program (kmymoney) from my computer. I trust my security more than hers, plus she runs Windows 7 and I couldn’t find a good way to run kmymoney on 64-bit Windows without running VirtualBox or something similar.

I tried x2go, and it is very cool, but seemed to have a lot of stability problems and very poor documentation. I’ve used nx before too, but it is hard to set up. So instead, I loaded good old cygwin onto the Windows machine. I used cygrunsvc to setup sshd on the Windows machine (you’ll see why in a minute) and made sure the X server runs on startup. I also modified the X startup so that it does not launch an xterm or anything on startup. Finally, I set both machines up so you can log into the right account (pat on the Windows box or money on the Linux box) using RSA certificates so no password is needed (google ssh with no password if you need to know how to do that). I set up the Windows ssh client to automatically do X forwarding to the Linux box (in .ssh/config).

So when my wife’s machine boots there’s nothing different from her point of view. Windows 7 hides the rarely used X icon down in the task bar. However, I made a batch file for her and there’s an icon for it on the start menu. It is very simple:


@echo off
c:\cygwin\bin\ssh moneypc /home/money/start pat patpc /cygdrive/c

There are 5 arguments to the ssh command. The moneypc name is the name of the Linux box in the .ssh/config file. That’s where the real IP address and all the options are (including the passwordless certificate names). Then /home/money/start is the name of a script on the Linux box (I’ll show you that in a minute).

The next three tokens are arguments to the start script. They identify the remote user’s name, the remote user’s machine name (by IP address, hostname, or entry into the .ssh/config file) and the user’s local file system.

Why does start need all that? Here’s the start script:

#!/bin/bash
USER=$1
IP=$2
ROOT=$3
sshfs $USER@$IP:$ROOT /home/money/media/drivec &
kmymoney
fusermount -u -z /home/money/media/drivec

So the script actually uses sshfs to mount the user’s local file system on /home/money/media/local (similar to what x2go does). That’s why I needed sshd on the Windows box. Of course, this would work just as well on, say, my Linux laptop.

The x2go software also makes printing work — not an issue for me since my intent is this is all local and it forwards sound. I didn’t put a pulseaudio server on the Windows box, but if I did it would be easy enough to set the default server to the user’s IP address in the start script.

This is nowhere near as handy as using x2go. But it seems to be way more robust and its workable. I don’t intend to use this remotely, but it would be reasonable to do so since my firewall is open for ssh and ssh provides good encryption.

Velleman PCS500 Oscilloscope under Linux

Velleman Software on Linux

Velleman Software on Linux

I like my Velleman PCS500. Its not perfect, but it does a good job and has been my “bench scope” for awhile now edging out my old faithful Tek scope for all but the most demanding jobs. However, there are two things I definitely don’t like about it. It uses a parallel port which many of my computers no longer have and the software doesn’t run under Linux.

When I built my last computer I stuck a cheap PCI parallel card in it. Of course, the PCI bus puts it at some wacky address like 0xE000 and most software can’t find it. I read this article: http://www.lafraze.net/nbernard/doc/misc_tips/velleman.html but it didn’t help either since the I/O wrapper won’t work on “high ports.” For the longest time I’ve just used an old Windows laptop as my “scope” and that’s worked ok.

But today I finally cracked the code to running the software under Linux (see the picture). Here’s what I did:

1) Set the permissions on the /dev/parport0 device to 666 (or you could add your user ID to the lp group and set it to 664 or 660):
sudo chmod 666 /dev/parport0

2) Create a new wine prefix:
WINEPREFIX=~/pcs500 winecfg

3) Inside winecfg set the default operating system to Win98. Close winecfg.

4) Run the wine regedit program. Create a key under HKEY_CURRENT_USER named Software\Wine\VDM\ppdev. Create a string value named 378 and make the value /dev/parport0. This must be under Current User and not System!

5) Download the PCLab2000SE software from Velleman and run setup like this:
WINEPREFIX=~/pcs500 wine setup.exe

6) Finish the install then run pcs500.exe from the ~/pcs500/drive_c/Program Files/Velleman/PcLab2000SE directory:
WINEPREFIX=~/pcs500 wine pcs500.exe

7) If you like, make a shortcut in your desktop software to launch this automatically.

I have noticed the software occasionally hangs up under Wine — don’t know if it is a problem with Wine or a problem with the software, but it doesn’t happen enough to be a problem.

Update: I can’t prove it, but it seems it mostly hangs when you switch away from the main window and then switch back (but not necessarily every time you switch). It actually doesn’t hang per se. You still get a trace, but you can’t work any of the controls. Sometimes if you play around it will respond again but mostly not. Again, I can’t prove it, but setting the main window to always be on top (or “Above Others” depending on your window manager) seems to improve the situation. It doesn’t eliminate the hangs but it seems to make them less frequent.

Hope that works for you!

Graphing CPU Temperatures in Linux

I recently changed motherboards and as always mounting the fan and heatsink on the CPU makes me feel stupid. I have a large non-stock cooler and it is always a struggle to make it fit with all the other things motherboard makers stuff near the CPU these days. After some busted knuckles, I thought I had it. But the temperature was a little high for my taste and seemed to climb for no good reason.

I looked at the setup and realized the plate that touches the CPU was off center. So I decided to remount it. Well, turns out there was a reason the plate wouldn’t center, but I eventually solved it. But all this has given me an unsual interest in temperature the last few days.

I won’t tell you how to set up lmsensors since there are plenty of good references on how to do so (a quick google on “lmsensors howto” shows lots of pages including . I even used ksensor (I use KDE) to give a nice display. I was thinking how nice it would be to automatically collect the data and graph it. Then I thought, well, why not?

I wrote a quick and dirty script — you’d need to change it for your setup. I have an AMD 5600+ (overclocked though), so when I run “sensors” I get several devices. The one I wanted was the k8temp-pci-00c3 which shows the two core temperatures. Unfortunately, it isn’t in a great format for processing:

k8temp-pci-00c3
Adapter: PCI adapter
Core0 Temp:  +38.0°C
Core1 Temp:  +36.0°C

But certainly awk is up to the challenge of fixing this up. Here’s the quicky script:

#!/bin/bash
#usage: tempdata delay file
echo Press ^C to exit
echo "Date/Time,Core 0,Core 1">$2
while true
do
   echo -n `date +%Y%m%d%H%M%S,` >>$2
   sensors k8temp-pci-00c3 | awk 'NR==3 { gsub/.C/,""); c1=$3; } NR==4 { gsub(/.C/,""); print c1 "," $3; } >>$2
   sleep $1
done
[/caption]

So there you have it. A classic example of using little Linux tools to create something bigger.

Setting Input Audio for VirtualBox (Linux)

If you use VirtualBox to run things (like Windows) under Linux you know that its pretty capable. It can even map sound from the guest OS to the Linux ALSA system. However, the GUI only provides a way to use the same input and output device on the host OS. That’s a problem for me. I have a normal PCI or onboard sound card (I have both) that I use for output. But for input I use a USB microphone that has no output.

It turns out there is an environment variable for this. If you set:

VBOX_ALSA_ADC_DEV

you can select a different sound device for input. For example, my microphone is set to hw:3,0 (getting a USB device to come up as the same card every time is another post for another day). So before launching any VirtualBox I make sure to have this environment variable set:

VBOX_ALSA_ADC_DEV=hw:3,0

Works great!

Maximize Firefox Screen Space

One of the things that makes Firefox a great browser is its extensions. If you want an extra feature you can add it to Firefox without having to rewrite Firefox. However, all those great extensions keep cluttering up your toolbars with more and more little icons.

The answer? Um, more extensions! Here’s how I get the most bang for my buck on Firefox screen space:

[/caption]

Note that I lied. My bookmark toolbar has a few non-folders on it (Hulu, for example). But most of them are folders containing live feeds.

Java Browser Plugin for Linux AMD64 is Here

Early release, it is true but it does work.

Download from here:

From a terminal:

cd /opt

sudo sh ~/jre-6u12-ea-bin-b02-linux-amd64-08_dec_2008.bin

# So you wind up with /opt/jre1.6.0_12

cd /usr/lib/mozilla/plugins
sudo ln -s /opt/jre1.6.0_12/lib/amd64/libnpjp2.so

# (restart firefox)

http://www.thinkfree.com finally works! Hoo ray!