Magic Ubuntu performance tip?

How often is is that you come across a simple tweak to your configuration file (/etc/hosts in this case) that claims to give you a noticeable performance increase, and with no discernable drawback?

I was psyched to try this one out and then I realized that I already had my hostname in /etc/hosts.

On a side note, I’m looking forward to the Ubuntu Feisty release, which is coming up in a couple of weeks…

OnlyUbuntu: Performance tip for Ubuntu Edgy and Feisty

Mounting UFS partitions in Linux

My desktop machine at work is now running RHEL 4, but before that it ran FreeBSD 4.10 for a number of years and had three hard drives with UFS filesystems. When my box was converted over to Linux, I backed up the critical files on the main hard drive and then reformatted the drive with ext3. The other two hard drives with UFS filesystems sat there collecting dust, which was unfortunate, because I could use the disk space. Today, I decided to mount the UFS partitions and look through the files and see if there’s anything worth keeping, before formatting these drives for Linux and getting myself a whole lot more disk space. Here’s how I did it.

The first task was to build the UFS kernel module, as my kernel did not have UFS support built-in, nor did my install have the UFS kernel module available. Already, having installed the proper kernel-devel RPM a while back, I did the following:

$ uname -r
2.6.9-34.0.2.ELsmp
$ rpm -qa | grep kernel-devel
kernel-devel-2.6.9-34.0.2.EL
$ cd ~/rpm/BUILD/kernel-2.6.9/linux-2.6.9
$ make menuconfig
$ make modules
$ make modules_install
$ depmod
$ sudo modprobe ufs

At this point, I had built the UFS kernel module and loaded it. Now it was time to mount the filesystems.

$ sudo mkdir /mnt/hdc1 /mnt/hdd1
$ sudo mount -t ufs -o ufstype=44bsd,ro /dev/hdc1 /mnt/hdc1
$ sudo mount -t ufs -o ufstype=44bsd,ro /dev/hdd1 /mnt/hdd1

That’s it! I now had read-only access to my two UFS partitions. Now I have to look through these files and see what’s worth keeping.

Fixing NO_PUBKEY 2E2BCDBCB38A8516 error from Oracle Debian repository

Folks running and Debian, Ubuntu, etc. may be aware that Oracle has a Debian repository for Oracle Express and other open-source software.

If you weren’t aware of it and wanted to use it, here’s the magic line to add to /etc/apt/sources.list:

deb http://oss.oracle.com/debian unstable main non-free

Recently, my apt-get updates started printing this warning:


W: GPG error: http://oss.oracle.com unstable Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 2E2BCDBCB38A8516

because Oracle is signing their packages with GPG and my system didn’t have their GPG public key.

First, I tried:

$ gpg --keyserver subkeys.pgp.net --recv 2E2BCDBCB38A8516
gpg: requesting key B38A8516 from hkp server subkeys.pgp.net
gpgkeys: key 2E2BCDBCB38A8516 not found on keyserver
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0
$ gpg --keyserver subkeys.pgp.net --recv-keys B38A8516
gpg: requesting key B38A8516 from hkp server subkeys.pgp.net
gpgkeys: key B38A8516 not found on keyserver
gpg: no valid OpenPGP data found.
gpg: Total number processed: 0

No dice. So I poked around a bit and found Oracle’s RPM GPG key. I wondered if they used the same GPG key for their Debian packages as they did for their RPM packages. One way to find out:

$ wget http://oss.oracle.com/el4/RPM-GPG-KEY-oracle
...
13:50:04 (356.53 KB/s) - `RPM-GPG-KEY-oracle' saved [1744/1744]
$ sudo apt-key add RPM-GPG-KEY-oracle
OK
$ sudo aptitude update
...
Fetched 194B in 2s (94B/s)
Reading package lists... Done

Cool, it worked!

Setting up a Linksys WUSB54GC WLAN adapter in Ubuntu

My Ubuntu box has always been networked via Ethernet, but lately I’ve been toying with the idea of moving the box and/or the wireless hardware to different rooms. Before doing that, I’d need to get it on the network via wireless.

I happened to have a Linksys WUSB54GC USB wireless adapter so I plugged it in and hoped that Ubuntu would magically discover it and set everything up for me. No such luck. The adapter was detected and I even ended up with new wireless interfaces – wlan0 and wmaster0, which seemed to be using the rt73usb kernel module. I attempted to configure them, but things just weren’t working. For one thing, when I did ifup on them, they attempted to get an address via DHCP, but they could not get one. I also noticed that when I tried to use iwlist to list the available channels, it came back saying that 0 channels were available.

I did a search and came upon this page. This page walks you through downloading the source code for a ralink-rt73 kernel module and building it with module-assistant. The page also provides a link to a .deb package that installs all the udev voodoo to recognize the adapter and load the kernel module. When everything is done and working, you plug in the adapter and an interface called rasusb0 is automatically created. The only problem I had was that I had to unload the rt73usb kernel module and then reinsert the adapter to get the kernel module to load and to get the rausb0 interface to be created. Once, I had the rasusb0 interface, it was pretty easy to set it up to get the wireless working. I entered the SSID and WEP key in the Ubuntu “Networking” panel and then went to the command-line to do a few finishing touches:

$ sudo iwconfig rausb0 channel 2
$ sudo ifdown eth0
$ sudo ifup rausb0
$ ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=3.54 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=1.65 ms

Voila!

Definitely not plug and play but not as hellish as I had imagined.

Getting good performance out of USB hard drives in Linux

I recently bought two Western Digital MyBook 500 GB external USB 2.0 hard drives to house our CD collection ripped to FLAC. As they will be storing relatively small numbers of very large files, I opted to use a filesystem with a large blocksize and few inodes:

# mkfs.ext3 -T largefile4 /dev/sde1
# mkfs.ext3 -T largefile4 /dev/sdf1

Keep in mind, however, that the resulting filesystem has a fairly small number of inodes so if you start copying lots of small files to the filesystem, it will quickly become full even though a simple df might report tons of free blocks (df -i will give you information about inodes). Of course, you could get around this by tarring and bzipping directories with lots of files.

I noticed a problem, however. While rsyncing data from one drive to another, I noticed abysmal transfer speeds, on the order of 400 KB/sec. Not good. My first instinct was to check that I plugged the drives into USB 2.0 ports and not USB 1.1 ports. Nope – I had the right ports. So I looked at hdparm but that is ATA-specific. There is a sdparm utility for SCSI devices, but it doesn’t seem to have much support for USB and Firewire. Eventually, I found this Linux USB FAQ, which talked about the max_sectors setting. I did:

# echo 1024 > /sys/block/sde/device/max_sectors
# echo 1024 > /sys/block/sdf/device/max_sectors

This increased max_sectors from 240 to 1024 (it wouldn’t go any higher than 1024) and now rsyncs were transferring on the order of 15 MB/sec. Quite an improvement from 400 KB/sec to 15 MB/sec.

This is on an Ubuntu system with the 2.6.17-11-386 kernel. YMMV, but this worked like a charm for me.

Patch for GNU touch to add -p option, a la mkdir

The other day I realized that often when I’m using touch, I’d like it to have the ability to create ancestor directories that don’t exist, a la mkdir -p. I quickly hacked together a shell script to do what I want.

Then I thought that this might be a generally useful extension to touch, so I thought I’d take a stab at adding it directly to the touch source code in GNU coreutils. Here’s my patch, which I sent to the mailing list:

Continue reading