BigSmoke

Smokes your problems, coughs fresh air.

Page 46 of 52

The road through Ubuntu

My mom bought a new laptop because of a broken screen on the old Linux machine that she had inherited from me (which wasn’t wasn’t a laptop, so I’m sure that the Golden Arrow of Consumption can explain why she didn’t just replace the screen, although the new boyfriend who is kind of Windows-but-not-Linux-literate qualifies as a more probable reason for getting a laptop that is needlessly dragged down by Vista).

I was a little surprised by her move. The first computer my mother learned turning on was this computer back when I was still using it. Of course it was running Linux at the time. Before I gave it to her, I replaced Gentoo Linux with Ubuntu Linux, and, honestly, she never had any problems with it that were not hardware-related. (Ok, there was that one time when there was some junk stuck in the print spool without a user-friendly path to getting rid of it, but you could argue that this was really due to a junk printer. (On the subject of print spools: my friend Wiebe complained to me a while ago that when the queue in their WorkCentre Pro 232 gets stuck, Xerox engineers have to come in to replace the whole damn control board; apparently, just plugging in a terminal with shell access isn’t possible.)) She was comfortable with and used to Linux. But, alas, she’s in love with someone who is less than comfortable with Linux and there’s always that male ego thing.

But, then, who cares? It was good news for my sister. With her having gone through a rally of shitty old machines in just a couple years and this still being an ok-enough machine, I asked her if she’d like a “new” machine running Linux when she called me about one of those typical Windows problems that had just taken out her previous wreck of a machine. Yeah, sure, she’s was more than willing to finally get rid of Windows.

I was glad that my sister didn’t feel the need to inflict the pain of Windows on this poor old machine. This meant I only had to upgrade and reconfigure i a bit. Upgrading Ubuntu to version 8.04 went pretty seamless, because it was a relatively fresh installation where all dependencies where actually marked as “auto”. After moving away some old – uhm – aesthetic imagery, ill-suited for big-sister-eyes, I brought the machine to her place, plugged in her peripherals, connected it to her screen, and tried to boot.

It booted, but GDM wouldn’t start. I had just swapped a Matrox G400 with a noisy GeForce 4 which I had previously assumed to be broken. This assumption actually goes all the way back to before I realized that the screen was broken. When the screen started complaining of “Not Recommended Mode”, one of my first diagnosis was that the GeForce card was borked. This diagnosis was arrived to after first blaming the screen, plugging it in elsewhere, seeing that working, plugging it back in, seeing that working too, then seeing that stop working again, resetting the screen in increasingly complex sequences, seeing it work again, seeing it stop working again, swapping the DVI connection with a VGA connection, and then, finally, swapping the GeForce racehorse with the old Matrox workhorse. Of course the problems returned, but not before another fun round of swapping parts and peripherals because the machine had started crashing. The crashing led me to replacing the power supply, only to find out later that the CPU’s cooling block had someone loosened dangerously. So, with all that in mind, I had now put back to GeForce plaything before I took the whole concoction to my sister. Now, GDM wouldn’t start. (The GeForce graphics worked fine before I moved the machine to her.)

Admittedly, I hadn’t exactly tried booting with the GeForce. (I’m not the rebooting type.) After swapping the card, not being able to use the binary nvidia and an hour or so of messing around, I found that the nvidia kernel module was actually missing. (I hadn’t noticed this because a “find /lib/modules|grep -i nvidia” did show an nvidia entry; had I looked better, I would’ve seen that it was a directory and not a .ko file.) So I performed a reinstall of the appropriate linux-restricted-modules package and—voila!—the files where there (in /lib/modules/2.6.24-21-generic/volatile/).

So I’m at my sister’s and I’m surprised that X won’t start. I try to find the module in /lib/modules/; it’s gone. Then, after reinstalling the package and an extraneous reboot to see it gone again, it dawns on me: what did volatile mean again? (I should really not be telling you this, because it’s fucking embarrassing. ๐Ÿ˜‰ ) Yes, the volatile directory is a tmpfs mount point. When I realized that this was probably due to initramfs, I realized that I know jack about initramfs, except that it makes Grub’s configuration incomprehensible to me.

I tried updating the initrd.img by issuing update-initramfs -u. When this didn’t work, I added the module name explicitly to /etc/initramfs-tools/modules. When that didn’t work, I changed the MODULES option in /etc/initramfs-tools/initramfs.conf to MODULES=dep and pulled update-initramfs through grep to find out if the module was added appropriately: update-initramfs -u -v|grep nvidia. It was outputted and it was the right initrd.img too but still, after booting, the module was missing from the volatile directory.

So, fuck this! I was getting inpatient: cd /lib/modules/2.6.24-21-generic/volatile; mv nvidia.ko ../kernel/drivers/video; depmod -a; reboot and GDM started nicely.

Now I just have to find out why the bloody eth0 interface isn’t ifup’ed at boot. The configuration seems fine to me (although I’m confused by all this new-fangled GUI stuff and by where everything is stored. :-?) For now, I just dropped a script on her desktop called Darn, the network doesn’t work:

#!/bin/bash
gksu ifup eth0

Pure sophistication, isn’t it? I’ve yet to encounter an operating system where solving such problems has any resemblance to anything I’d call user-friendly… For all the polish they add these days, if you can’t go below the hood and bang away at the shell, you’re basically screwed. That’s why I hate Windows so much, because I know nobody who can get under its hood.

Change ext3’s reserved block count and gain Gigabytes

Wiebe was looking over my shoulder while I was running df to check the disk space that was still available on my Lenovo ThinkPad:

# df -h /dev/sda2
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              90G   79G  7.3G  92% /

He noticed that there was a huge gap between the total space (79 used + 7.3 available = 88.3) and the actual size of the file system. According to him this was due to the reserved block count, which is set to five percent by default in ext2 and ext3 file systems—clearly a legacy from a time where disks were smaller.

# dumpe2fs /dev/sda2|grep -i 'reserved block count'
dumpe2fs 1.40.8 (13-Mar-2008)
Reserved block count:     1196559

# dumpe2fs /dev/sda2|grep 'Block count'
dumpe2fs 1.40.8 (13-Mar-2008)
Block count:              23931180

# echo 'scale = 2; 1196559 / 23931180'|bc
.05

I changed the reserved block count with tune2fs:

# tune2fs -m 1 /dev/sda2
tune2fs 1.40.8 (13-Mar-2008)
Setting reserved blocks percentage to 1% (239311 blocks)
# dumpe2fs /dev/sda2|grep -i 'reserved block count'
dumpe2fs 1.40.8 (13-Mar-2008)
Reserved block count:     239311
# df -h /dev/sda2
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              90G   79G   11G  88% /

Now, the reserved blocks take up roughly 934 MiB; I’ve freed 3.7 GiB with this little file system tweak. ๐Ÿ™‚

Update 14 nov 2010: I finally fixed two errors in my final calculations spotted by Den. He noticed that the numbers (700 MiB and 13 GiB) were wrong. Thanks, Den!

png2ico: converting favicons to Windows’ ICO format

Even though, strictly speaking, I should be using favicons in anything but Windows’ ICO format and refer to them from a <link>-tag at any location other than /favicon.ico, I sometimes like to help Microsoft break the web by putting an ICO file at the location that they reserved for it (/favicon.ico).

My tool of choice for converting PNG’s to ICO is Matthias Benkmann’s png2ico. To generate an ICO file with this program, you just need to feed it one or more PNG files. The possibility to include differently sized PNG files can help you make sure that the icon will steal look good when being dragged to the desktop or some other non-miniature context.

$ png2ico
png2ico 2002-12-08  (c) Matthias S. Benkmann
USAGE: png2ico icofile [--colors ] pngfile1 [pngfile2 ...]

Here’s an actual example which creates an ICO file from a single PNG file:

$ file favicon.png 
favicon.png: PNG image data, 16 x 16, 8-bit/color RGBA, non-interlaced
$ png2ico favicon.ico favicon.png 

Of course, we should discourage browsers from doing useless requests for /favicon.ico by actually telling them when it is available: (as if…)

<link type="image/x-icon" rel="shortcut icon" href="/favicon.ico" />

Now we can go back to pretending that: No, we’re not encouraging the practice of link squatting. We just happen to have put our favicon in that location.

For the less tech savvy

Update 30 sep 2012: There’s a free online service to convert PNG to ICO: www.pngtoico.com. It doesn’t require you to do anything complicated (like installing Unix stuff). Just pick your original and get the converted image. ๐Ÿ™‚

Decoding djvu files on the command line

So, you have djvu files on a remote machine that you have SSH access to, and the local machine you’re working on doesn’t have djvu tools. What do you do? Simple, use ddjvu to decode the djvu files to images.

And that’s all. I kept forgetting the name of the tool, so, now I won’t anymore…

PostgreSQL back-end for Ruby on Rails confusion

I just need to add a quick summary of what postgres back-end tool our Ruby on Rails application uses, and how we’ve configured it, because it’s quite confusing…

There are four postgresql backends:

  • ruby-postgres. This version is no longer maintained. This is the version we used when the project began.
  • postgres-pr. This is a pure ruby implementation, which is not interesting for us.
  • postgres. This is the continuation of the unmaintained ruby-postgres. This version includes such fixes as that it can be compiled against libpg-8.3.
  • ruby-pg. It is said that this one is now the official postgres back-end, but when I install it, the application still can’t find “postgres”.

Because the aforementioned article states that the pg extension is unstable, “postgres” seems to be what we should use. The article states that it is included in the ruby-pg package, but it doesn’t work when I install it, so I had to install “postgres”. I uninstalled ruby-pg, because it doesn’t seem necessary.

To continue, we once used a patched postgresql adapter, because we needed more accurate timestamps (the standard connection adapter rounded everything off to whole seconds), but if I recall correctly, this patch was only necessary on the connection adapter in Rails, not the back-end. We never commissioned the functionality that required this, so this existed only in the workdir of one of the devs.

As a final note; on our production server, we have a version of ruby-postgres installed in /usr/local. I can’t remember why…

Using wget to download all files on a page

Just a quick one-liner I used to download a bunch of MIDI files from an on-line listing of Chopin MIDIs:

$ wget http://www.piano-midi.de/chopin.htm -q -O - \
| grep 'href=".*\.mid"' \
| sed -e 's/^.*href="\(.*\)".*$/\1/' \
| xargs -i{} wget http://www.piano-midi.de/{}

Maybe not so useful to you, but it’s a good demonstration of applying the hacker’s mentality to one of those moments where, after clicking the fourth link or so, I find myself thinking: Wouldn’t spending a few moments on a one-liner be much more fun than clicking through and saving 44 more links?

Useful or not, I am now testing timidity’s piano sound with a nice rendition of Chopin in the background whereas, without this trick, I’d still be right-click-click-saving links instead of writing this post. It’s up to you to decide whether this is actually good or bad. ๐Ÿ˜›

VIM modelines for per-file configuration

The MediaWiki developers use tabs instead of spaces for indentation. This can be annoying for someone like me who has configured VIM to work with spaces by default—annoying because I don’t want to enter something like :set tabstop=4 noexpandtab shiftwidth=4 every time that I open a file. Adding different conditions for each project to my .vimrc is probably possible but not much fun.

The other minute, when I opened the sources of my Semantic Gallery extension for MediaWiki, I noticed that I had been mixing tabs and spaces again. So it was time to look up the VIM feature which allows you to put a configuration line in a comment at the bottom of a file. This quote is another perfect example of why it’s good practice to blog about such things. I remembered that the last time that I had wanted to do this, I could not find a useful search string at all and resorted to finding back an example in the code where I had first seen it and modifying that. Now, I thought I’d have to do the same, but from a quick googling I learned that I’m not the only one to use his blog as a memory extension. ๐Ÿ™‚

Good. Hopefully, from now on, I’ll remember that this configuration-thingy-at-the-bottom-of-a-file is called a modeline, so that I can just enter :help modeline in VIM the next time that I forget where the colons have to go.

An example for when I do forget:

# vim:set ts=4 sw=4 noexpandtab:

This reminds me of my many searches for Heredoc syntax when I didn’t know that they were called Heredocs.

Disabling SSH shell access for SVN users on a Linux/Unix system

A common problem is that Linux/Unix system administrators want to grant users access to SVN repositories, but prevent them from logging in on the shell. This can be accomplished quite easily.

First, disable the user’s account by running:

usermod --lock [user]

This way, only public key authentication is allowed. Then, when adding the user’s key to the ~/.ssh/authorized_keys file, prefix it with this:

command="/usr/local/bin/svnserve -t",no-port-forwarding,no-pty,no-agent-forwarding,no-X11-forwarding

I used our wrapper script in /usr/local/bin as the command, because it sets an umask of 002 before actually running svnserve. This is necessary when using svn+ssh access.

The source for this trick explains it in more detail.

Configuring a Debian satellite Exim server

A very common way to configure Exim on a Debian machine, is to make it a ‘satellite’; a server which uses another SMTP server for sending and does not do local delivery, the latter being the difference with a ‘smarthost’. It can be used by other computers in the network to send mail, but also by the machine itself, to send system notifications and such (one of my favorite apps, arpwatch, for example).

The following needs to be in /etc/update-exim4.conf:

dc_eximconfig_configtype='satellite'
dc_other_hostnames='[mailname]'
dc_local_interfaces=''
dc_readhost=''
dc_relay_domains='*'
dc_minimaldns='false'
dc_relay_nets=''
dc_smarthost='[your SMTP server]'
CFILEMODE='644'
dc_use_split_config='false'
dc_hide_mailname='false'
dc_mailname_in_oh='true'
dc_localdelivery='mail_spool'

The following needs to be in /etc/mailname:

[mailname]

[mailname] is the same in both locations, and is simply the FQDN (world wide, not just local, such as bla.net) which should appear after the @-sign. The reason that it must entered in both places, is because both have a different function. ‘etc/mailname’ Takes care of putting the specified domain after the @-sign if you mail to, for example, root. The ‘dc_other_hostnames’ is to let the server know that this is the machine that handles that domain. If you don’t specify the ‘dc_other_hostnames’, the server will just try to send it to the next relay. BTW, ‘dc_other_hostnames’ is colon (;) seperated.

Make sure the FQDN you use exists, otherwise a lot of mailservers refuse to accept it. What I don’t understand, though, is that in my experience, whatever you use as domain doesn’t have to exist as MX record, but just as an A record.

Also don’t forget to include an alias for root in /etc/aliases. I usually let all mail sent to root be sent to a local user, and alias that local user to an outside e-mail address.

« Older posts Newer posts »

© 2024 BigSmoke

Theme by Anders NorenUp ↑