Saturday, June 27, 2009

Change SSH Port

If you have two or more computers behind a NAT (i.e., router) and you want to access both machines, you need to change the SSH port on at least one of them. To do so, as root, edit /etc/ssh/sshd_config. Add a line that reads "Port PORT_NUMBER". The relevant part of my file looks like this:

Port 2200
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::


You will need to either restart the SSH daemon (or reboot) before the change will take effect. And of course, you'll need to adjust the firewall on your computer to allow the new port to pass through, as well adjust your NAT.

Thursday, June 25, 2009

Freeing disk space

This is just an FYI to anyone who is deleting files off their hard drive and it's probably a pretty familiar concept to those who've been using Linux for awhile.

For any file, Linux maintains a list of handles, that is programs that are currently using the file. When you delete the file, it is only removed from the disk when the number of handles goes to zero.

This becomes important if your drive is almost full and you delete a file, but you find that your disk space has not changed. The most likely reason is that some program still has an open handle.

Make sure that any program that might be using the program is closed and if all else fails, a reboot will clear all of the open file handles.

And if you weren't already aware, the command line tool to find out how much disk space you have left is 'df'.

Tuesday, June 23, 2009

Sound not working in Flash? Here's a possible fix.

Here's the symptom: your sound works fine, except in Flash. You've tried multiple browsers and Flash sound doesn't work in any of them.

The problem is that you're using PulseAudio as a sound engine and sometimes Flash doesn't work well with it.

To fix this, remove the libpulse0 package. As root:

yast --remove libpulse0


When I did this, it ended up removing MPlayer due to dependecies. I reinstalled MPlayer from the repositories which brought back one PulseAudio package, but sound still worked in Flash.

Monday, June 22, 2009

::Updated:: A guide to getting the Digipro T-8000U Tablet to work with OpenSUSE

This post supersedes my previous one. It fixes the bugs that were in that one.

This guide will get the Digipro T-8000U tablet working with OpenSUSE 11.1.

1. Install the necessary prerequisites. As root:

yast -i gcc xorg-x11-devel xorg-x11-server-sdk


2. Get the latest version of the WizardPen driver, which as of now is 0.7.0a2. It is available on a Microsoft website (don't ask me why):

http://cid-43438aff38d34c29.skydrive.live.com/self.aspx/Public/wizardpen/wizardpen-0.7.0-alpha2.tar.gz

Untar, configure, and compile it. Do not install it.

tar xvzf wizardpen-0.7.0-alpha2.tar.gz
cd wizardpen-0.7.0-alpha2
./configure && make


3. The Makefile installs the driver where Xorg won't find it, so you have to install it manually. As root:

cp src/wizardpen_drv.la /usr/lib/xorg/modules/input
cp src/.libs/wizardpen_drv.so /usr/lib/xorg/modules/input


4. You need to find the device associated with the tablet. First, do:

grep Name /proc/bus/input/devices


Look for something that looks like your tablet. Mine was "Aiptek". If nothing sticks out, you can do an:

lsusb


to find the full name of the tablet and compare that with the output from "grep Name /proc/bus/input/devices".

Then do (assuming your tablet's name is Aiptek):

lshal | grep "input.product = 'Aiptek'" -A 20 -B 20 | grep input.device


This should produce a single line with your device. Mine was /dev/input/event7. If this doesn't work, do a "lshal" and search through the output until you find the string.

5. Download and run this calibration routine. The one that is provided with the WizardPen code does not calibrate in the Z-direction, which is critical to getting the pressures to work.

wget http://www.filefactory.com/file/ag8g447/n/wizardpen-calibrate_c wizardpen-0.7.0-alpha2/calibrate/wizardpen-calibrate.c
cd wizardpen-0.7.0-alpha2/calibrate
make
sudo ./wizardpen-calibrate /dev/input/event7


6. As root, edit /etc/X11/xorg.conf. Add a section that reads:

Section "InputDevice"
Driver "wizardpen"
Identifier "WizardTablet"
Option "Device" "/dev/input/event7"
Option "TopX" "0"
Option "TopY" "0"
Option "TopZ" "54"
Option "BottomX" "3000"
Option "BottomY" "2200"
Option "BottomZ" "511"
Option "MaxX" "3000"
Option "MaxY" "2200"
Option "MaxZ" "511"
EndSection


where all of the numbers are from the calibration program in step 5. In the ServerLayout section, add a line that reads:

  InputDevice  "WizardTablet"  "AlwaysCore"


7. Reboot.

The tablet should be working now. To use it in Gimp, you need to go to Edit, Preferences, Input Devices, Configure Extended Input Devices, and for the WizardTablet device, set the Mode to Screen. Be warned, with an extended input device (the tablet) enabled in Gimp the mouse can no longer be used to draw. However, disabling the tablet re-enables the mouse. See this GTK bug for more details.

There is one lingering bug and that is that hotplugging does not work. I'll look at this sometime over the next week. Until then, you'll need to have the devices you want to use plugged in at boot.

---===Very Important===--- If you have a dynamic collection of input devices, where what you have plugged into the computer changes from boot to boot, you'll need to make a couple of small modifications to your xorg.conf. These corrections are necessary if you want to, for example, use a USB mouse occasionally. You need to replace the "/dev/input/DEVICE" lines with either the "/dev/input/by-path/DEVICE_PATH" or "/dev/input/by-id/DEVICE_ID" for your device. You can find out what this are by doing a:

find /dev/input


with and without the device plugged in and then comparing the outputs. There will be two files associated with each device. For mice, use the one without "event" on the end and for the tablet, use the one with "event" on the end.

Sunday, June 21, 2009

Install openSUSE from a USB drive

If you have a netbook or any computer without a cd drive you can easily install openSUSE from just about any USB drive.

You'll need a bootable USB drive (they almost all are and the easiest way to find out if yours will work is just to try it) and a computer that can boot from USB (any computer build in the last five years should be able to).

1. Go to http://software.opensuse.org/ and get a copy of the installer. Make sure you choose the correct type of computer. On AMD/Intel chips, 32-bit will always work and 64-bit will work on most newer computers.

You can choose to use either the DVD or the network install. If you choose the DVD option, you'll need a USB drive with a capacity of at least 4.2GB. Practically, 8GB is the smallest USB drive you'll find with enough space. If you choose the network install, you'll need a network connection during the installation. In my experience, an ethernet connection always works and a wireless connection is somewhat iffy (although the Eee PC wireless card works perfectly).

2. Install the required packages. As root (the rest of the steps require you to be root as well):

yast -i syslinux lilo


3. Mount the installation image:

mkdir MOUNT_POINT
mount openSUSE-11.1-NET-i586.iso MOUNT_POINT -o loop


where MOUNT_POINT is any directory and openSUSE-11.1-NET-i586.iso is the name of the file that you downloaded.

4. The mkbootdisk program copies the files to the USB drive and makes the drive bootable.

mkbootdisk --32 --partition /dev/USB_DRIVE MOUNT_POINT


where USB_DRIVE is the partition you want to copy the files to. On my system, this was /dev/sdc1. If you're installing a 64-bit system, then replace "--32" with "--64".

5. Do a little bit of cleanup:

umount MOUNT_POINT && rmdir MOUNT_POINT



You now have a bootable USB drive with a copy of the openSUSE installation media.

Thursday, June 18, 2009

A *rough* guide to getting the Digipro T-8000U Tablet to work with OpenSUSE

This post has been superseded by this new one. It fixes the bugs that were in this one.

This guide will get the Digipro T-8000U tablet working with OpenSUSE 11.1. However, following this guide will break a couple of things:

-X will fail if the tablet is not plugged in.
-Gimp will not longer allow you to draw with the mouse.

I think I know how to fix both. I'll test and post fixes for both over the weekend. Also, the calibration that I give here is specific to my tablet. I had to write my own code to get the correct calibration (the calibration included with the WizardPen driver doesn't handle pressures correctly). I'll post that as well this weekend.

1. Install the necessary prerequisites. As root:

yast -i gcc xorg-x11-devel xorg-x11-server-sdk


2. Get the latest version of the WizardPen driver, which as of now is 0.7.0a2. It is available on a Microsoft website (don't ask me why):

http://cid-43438aff38d34c29.skydrive.live.com/self.aspx/Public/wizardpen/wizardpen-0.7.0-alpha2.tar.gz

Untar, configure, and compile it. Do not install it.

tar xvzf wizardpen-0.7.0-alpha2.tar.gz
cd wizardpen-0.7.0-alpha2
./configure && make


3. The Makefile installs the driver where Xorg won't find it, so you have to install it manually. As root:

cp src/wizardpen_drv.la /usr/lib/xorg/modules/input
cp src/.libs/wizardpen_drv.so /usr/lib/xorg/modules/input


4. You need to find the device associated with the tablet. First, do:

grep Name /proc/bus/input/devices


And look for something that looks like your tablet. Mine was "Aiptek". Then do:

lshal | grep "input.product = 'Aiptek'" -A 20 -B 20 | grep input.device


This should produce a single line with your device. Mine was /dev/input/event7. If this doesn't work, do a "lshal" and search through the output until you find the string.

5. As root, edit /etc/X11/xorg.conf. Add a section that reads:

Section "InputDevice"
Driver "wizardpen"
Identifier "WizardTablet"
Option "Device" "/dev/input/event7"
Option "TopX" "0"
Option "TopY" "0"
Option "TopZ" "54"
Option "BottomX" "3000"
Option "BottomY" "2200"
Option "BottomZ" "511"
Option "MaxX" "3000"
Option "MaxY" "2200"
Option "MaxZ" "511"
EndSection


And in the ServerLayout section, add a line that reads:

  InputDevice  "WizardTablet"  "AlwaysCore"


---===Very Important===--- My xorg file already had two input device sections, one for my touchpad and another where it had detected the tablet as a mouse. I had to delete that extra mouse section before the tablet would be correctly recognized. Otherwise, Xorg uses the wrong mouse driver and your tablet will only half work.

6. Reboot.


The tablet should be working now. To use it in Gimp, you need to go to Edit, Preferences, Input Devices, Configure Extended Input Devices, and for the WizardTablet device, set the Mode to Screen.

Like I said above, this is a very rough guide. I'll clean it up in a few days and repost then.

Friday, June 12, 2009

TV Antenna Design

I want to mount my TV tuner inside my laptop and I also want to build an internal antenna. In my area, TV stations are in the frequency range from 500MHz to 750MHz (as determined from my channels.conf file) which according to this online calculator puts my ideal antenna length (for a dipole antenna) at between 90 and 150 mm per half.

I wanted to get a better feel for the best antenna length to use, so I rigged an antenna like this:



and I scanned for channels several times, each time cutting 4 mm off of the end of each lead. I recorded the number of channels detected with each setup and then made a plot of the results:



While 128 mm was the best length, there is quite a bit of noise in the plot, so its hard to say for certain that the best length might not be somewhat shorter or longer. There definitely is a tendency for the longer antennas to do better than the shorter ones. Based off of this, I'll probably end up going for a 130 mm antenna, if I can make it fit in the case.

Also interesting: The 128 mm antenna picked up 34 stations, while the high quality antenna that came with the tuner picked up 37 channels. Overall, I think that is pretty good for an antenna made out of a couple spare pieces of wire.

Thursday, June 11, 2009

Creating and using an encrypted hard drive or partition

Considering the dropping cost of laptops and external drives, the most damaging part of having one stolen is not the cost of replacing the hardware, but the cost of the data.

You may have proprietary company information, tax returns, financial information, or worse on there. The best way to protect your data is to encrypt it and encrypt it well. Thankfully, Linux makes this really easy.

The encryption I'll show you how to setup uses a block-encryption algorithm, meaning that the encryption respects the underlying filesystem and in case of a hardware failure, such as a bad block, you'll only lose the data stored at that one location. I once had a Windows encryption package that encrypted using the entire volume. One day, an error cropped up in the middle of the encrypted volume and instantly all of my data was gone.

All of the following should be done as root.

1. The first step is to fill the drive with random data. This serves two purposes:

-If the drive previously contained any unencrypted data, you want it gone and unrecoverable.
-If the drive is not filled with random data, an attacker may be able to determine how much of your encrypted partition is in use.

I feel that the first reason is the more important one, so if your drive is new, then you can skip this step. If you are performing this step via a USB connection, it can be incredibly slow; you can expect this step to take up to a week to complete. If you need it done quick, then hook the drive up via SATA or eSATA.

The command to perform is:

dd /dev/random /dev/DEVICE


/dev/random contains high quality random data. You can replace it with /dev/urandom, which is faster, but uses lower quality random data (i.e., its not quite as random).


2. Create the encrypted partition:

cryptsetup --key-size 256 luksFormat /dev/DEVICE


You will be prompted for your passphrase. LUKS does not use your passphrase to encrypt the data, rather it uses your passphrase to secure the key that encrypts the data. As a result, you can setup multiple passphrases or even revoke passphrases. This way, if you ever feel that your passphrase may have been compromised, you can quickly swap it with another passphrase to maintain data security without having to reencrypt the entire drive.

3. Open the encrypted partition:

cryptsetup luksOpen /dev/DEVICE NAME


"NAME" is the name of the unencrypted device and can be any convenient name for this partition. For example, if you're setting up a backup drive, use "backup" to remind yourself what the drive is for.

4. Create the filesystem:

mkfs.ext3 /dev/mapper/NAME


Of course, you can replace mkfs.ext3 with whatever filesystem you want to use.


You're done! Now how to use your drive. To set it up, use:

cryptsetup luksOpen /dev/DEVICE NAME
mount /dev/mapper/NAME MOUNT_POINT


And to shut it down, use:

umount MOUNT_POINT
cryptsetup luksClose NAME


And if you're going to use this for a partition that needs to be mounted at boot, see my note about getting openSUSE to ask for the password at boot.

Wednesday, June 10, 2009

Backup - Part I

"If there's one thing people know they should do, it's backup their data.
If there's one thing people don't do, it's backup their data."

-Jim Fraser


For me, I resisted making backups for a long time because as a former Windows user, I was scarred by how hard it was. In Windows, your data is all over the place (and not in just one directory), backing up Windows itself is just about impossible, most backed up programs won't run after being restored, and there's no easy, integrated way to make backups.

Proprietary software tends to save your files in volumes, so that you have no access, without the software, to the individual files that comprise the backup. If you lose the install disk, your backup is garbage.

Linux makes backing up data so unbelievably easy though, it's almost stupid not to.

Rsync is the tool and it makes perfect copies between filesystems. It is incremental, so the first backup will take awhile, but each one after will only backup the changes. The command to use is:

rsync -a SOURCE DESTINATION


The "-a" switch puts rsync into archive mode, which activates a number of other switches that are useful for performing backups (such as recursing into subdirectories, for example).

Other switches to consider are:

"-x" keeps rsync from crossing filesystem boundaries. This is useful if you're doing a backup of / and you have /home on a different partition and you don't want the other partition included in the backup.

"-H" preserves hard links. The man page says that this is computationally expensive, but in my experience, it has never been a problem. Hard links occur when two files both point to the same location on the disk and they very rarely occur in personal files. If "-H" is not used, then the backup will have two separate files with two copies of the data, instead of two files pointing to the same data. I generally turn this on when I'm backing up / and leave it off when I'm backing up /home.

"-v" is for verbose mode and results in a listing of all the files that are backed up.

"-z" turns on compression of the data stream. This does not compress the backed up data. Generally, I only turn this on if I'm backing up data across a slow connection, such as across the Internet.

"--delete" deletes files at the destination if they don't exist at the source. Turn this on if you want a one-to-one copy of your data.

Tuesday, June 9, 2009

How to fix inconsistent font sizes

I had a problem after installing OpenSUSE 11.1 with KDE 3.5 where the fonts were normal in some programs and way too small in others. In Firefox, the fonts of webpages were normal, but the fonts of the controls (like the web address, File, Edit, View, etc) were too small. The font used for YaST was barely readable.

The fix is pretty easy. Fire up the KDE control center, either by choosing "Configure Desktop" from the Gecko menu or running kcontrol from the terminal. Choose "Appearance & Themes" from the left hand menu and then choose "Fonts". Set "Force fonts DPI" to either 96 DPI or 120 DPI. On my Eee PC, I chose 120 DPI and now all of my fonts are nice and large and readable.

Sunday, June 7, 2009

Create a movie using Fortran

Recently, I posted a method for making images in Fortran. With a couple of commands, its easy to turn those images into a movie.

I'm assuming that you're following my previous hack and you've got a directory of ppm image files, each one containing a single image of the movie you want to create. First, you'll need to convert each one to jpg:

convert IMAGE.ppm IMAGE.jpg


Then convert the jpg's to an avi file. This requires mencoder, which is included with the MPlayer package, which is part of the Packman repositories.

mencoder "mf://*.jpg" -mf fps=1 -o VIDEO.avi -ovc lavc -lavcopts vcodec=wmv2


The video is encoded using wmv2 which is playable on every Windows and Linux machine I've come across. This plays the video at 1 frame per second. You can increase or decrease the fps switch to set the speed at whatever you like (such as "fps=3.5"). The images are read in alphabetical order, so numbering your images 0001.jpg, 0002.jpg, and so on is not a bad idea.

Here's movie that I recently created as part of my thesis research:



It probably doesn't make a lot of sense what's going, but the important thing is that this entire video was created using a couple hundred lines of Fortran, my data files, and a couple of scripts.

Saturday, June 6, 2009

Force processes to a specific processor (processor affinity)

In OpenSUSE 11.1, you can use the taskset command to force a process to a single processor or set of processors. Some race condition bugs in Wine may be helped by fixing Wine to a single processor. To do so, use:

taskset -c 0 PROGRAM


The "0" is the processor to use (starting from zero). Another possibility includes "-c 0,2-3" which would run the program on the first, third, and fourth processors.

Friday, June 5, 2009

Make OpenSUSE 11.1 ask for encrypted volume password during boot

11.1 is the first version of OpenSUSE where I've had to follow these steps, specifically the last part about adjusting the system services. If you have an encrypted filesystem in your /etc/crypttab and /etc/fstab, but don't adjust the system services, then it won't ask for your password on boot and the boot will fail when it tries to mount the encrypted partitions.

If you have a LUKS encrypted filesystem and you want to mount it during boot, then you'll need to add an entry to /etc/fstab like this:

/dev/mapper/DEVICE /MOUNTPOINT ext3 defaults 0 0


An entry to /etc/crypttab like this:

DEVICE /dev/disk/by-id/DISK none none


And turn on the boot.crypto-early service in YaST. Go to YaST, then "System", and then "System Services (Runlevel)".



Turn on expert mode and then for the boot.crypto-early service, enable it for boot, "B".



Hit "Ok" and you're done.

Thursday, June 4, 2009

Fix for depmod gives "Cannot allocate memory" error

I encountered an error I've never seen before while building a kernel. While doing a "make modules_install" I got this error:

DEPMOD 2.6.29.4-0.1-pae
FATAL: Can't read module /lib/modules/2.6.29.4-0.1-pae/kernel/drivers/net/wireless/b43/b43.ko: Cannot allocate memory


At first, I thought it was a symptom of building a kernel on a low memory machine, but I upped the swap space and tried again, only to get stuck in the exact same spot. It turns out the error is easily fixed by turning off the debug option in the /usr/src/linux/.config file. You can do this either with a text editor or "make xconfig" (or "make menuconfig", etc).

You want to replace the line:

CONFIG_DEBUG_KERNEL=yes


with:

#CONFIG_DEBUG_KERNEL is not set


It is near the end of .config.

In the configuration programs, the option to turn off is "Kernel hacking | Kernel debugging".

Tuesday, June 2, 2009

SSH / login welcome message

For as long as I've used it, SUSE has welcomed me as I logged in with a message to "Have a lot of fun". The message is kind of pointless, but its easy to change. It is stored in /etc/motd (message of the day). On shared systems, I use it to post important system updates, like kernel and library updates that might break other's code.

On my own systems, I've found it to be useful to use cron to replace the message with important system stats like the amount of free hard disk space, current usage levels, CPU temperatures, etc.