Smokes your problems, coughs fresh air.

Category: Technology (Page 38 of 47)

Installing grub on RAID1

When you have your kernel image and grub boot stages on a Linux software RAID1 partition, installing grub needs a bit of trickery.

It determines on what hardware device those files are located by looking at /etc/mtab. It will find /dev/md/0 for / or /boot (or whatever) where the files are located. That device has no BIOS device, because it is managed by the Linux kernel. Therefore, when you try to install grub, it says: “/dev/md/0 does not have any corresponding BIOS drive.“. But because the underlying partitions in a RAID1 have the same data as the virtual device, we can trick grub.

All we have to do is edit /etc/mtab and replace the /dev/md/0 with /dev/sda1 (or whatever). You can then run grub-install hd0. Of course, make a backup of mtab first so you can revert it after having installed grub.

I find it kind of weird that grub doesn’t determine that the device in question is a RAID1 and that it can simply use the underlying device; the internet is filled with people having the same problem. If anybody knows a more elegant solution than this, I’m all ears.

Based on the comments, this is what you need to install it from the grub prompt:

# grub
grub> root (hd0,0)
grub> setup(hd0)
grub> root (hd1,0)
grub> setup (hd1)

Fixing “expected NAV packet but none found” error on some downloaded DVD’s

With certain DVD’s, Xine fails when seeking in the movie saying “Expected NAV packet but none found”. It seems that I have finally found out how to fix this and it is not even difficult. If the theory is correct, it only happens with DVD’s obtained as an ISO image.

What you need to do, is mount the image over the loopback, copy the data files to another location and playing those copied files should work. You can then burn them to a video DVD if you want to, of course.

I have no idea why this works or what causes the error, but I’m glad I finally figured it out.

Also, some of these DVD’s don’t even play on normal players (so it’s not just Xine). This should fix that as well, but I have yet to test that.

Impossible to fix file collision when upgrading qt 4.3 to 4.5

I’m trying to upgrade my qt 4.3 to 4.5. Version 4.5 seems to be split up in several ebuils, one of which is qt-dbus. When trying to install qt-dbus, it says that the files conflict with qt-4.3. This is only normal, because in version 4.3, the files did belong to qt.

The thing is, some time ago, collision protection was disabled by default, which I thought made sense because when I tried enabling it, I’d get errors like these all the time. I disabled it for now (by putting “-collision-protect -protect-owned” in the FEATURES variable in make.conf), to be able to install Qt, but because it is enabled by default, I’d rather not keep it disabled.

(Text was copied from the post I made on the Gentoo forum about it.)

Really enabling portage compile cache

I always thought I had portage’s compile cache enabled, but upon recent inspection, it appears that I didn’t. What was missing, was the package dev-util/ccache. I also increased the cache size to 2 GB, as per the Gentoo documentation.

I noticed this because recently, portage started saying this:

!!! Directory does not exist: '/usr/lib/ccache/bin'
!!! Disabled FEATURES='ccache'

Correcting Spamassassins stale mirror configuration

My spamassassin updates daily by running sa-update. Recently, I’ve been getting failure notices that mirror spamassassin.kluge.net was no longer available. This was because of a known bug, apparantly. So, I deleted the MIRROR.BY file and ran sa-update again.

This caused problem number two: GPG key verification failed. This was also a known issue, so I had to do:

wget http://spamassassin.apache.org/updates/GPG.KEY
sa-update --import GPG.KEY

And then everything was OK again.

Adding locales in Ubuntu

I wanted the dates on my Kubuntu system to be shown as Dutch dates. Therefore, I needed to add a locale. The place to do it is in /var/lib/locales/supported.d/local. It now contains this:

en_US.UTF-8 UTF-8
nl_NL.UTF-8 UTF-8

Then run locale-gen to generate the locales.

Set the following environment vars (in profile or something) to let everything behave properly:

export LANG="nl_NL.UTF-8"
export LC_MESSAGES="en_US.UTF-8"
export LC_COLLATE="C"

I don’t know anymore why I chose this specific configuration. I guess this means that everything, from thousand and decimal separators to dates is Dutch, and messages are English. I don’t know, however, why the collate is C. I vaguely remember something about it otherwise not including some characters in the sorting, causing weird sorting in words with dashes and such.

Gentoo update: WiFi drivers (iwl4965)

When I got the Wireless working on this laptop (a Lenovo T61), I was using Linux kernel 2.6.25. I remember that it was quite a pain, because the iwlwifi stuff had only just stabilized enough to replace the (now deprecated) ipw stuff. One of the things I didn’t get working at the time was Monitor mode.

Now, I’m upgrading to kernel 2.6.29, and there have been some changes to the kernel configuration for the iwl4965 driver. CONFIG_IWL4965 is now a suboption of CONFIG_IWLAGN. The wireless didn’t work on the first boot however. eth0 didn’t work either. But, when I changed the wired driver from “Intel PRO/1000 Gigabit Ethernet” (CONFIG_E1000) to the same for PCI-express (CONFIG_E1000E), it did work on the next boot and the wireless magically started working too. 😕

I was surprised because I don’t see what the wired and the wireless driver have got to do with each other. Also, before, I’ve always successfully used the non-PCI-express driver for my wired Ethernet interface and I’m so old fashioned that I can’t imagine either way that my hardware uses something so modern as PCI-express. 😛

Anyway, it works now. I’ve gone from kernel 2.6.25 to 2.6.29 and everything seems to be working. I still have to find out how to get Monitor mode working though.

One final thing I noticed is that upgrading net-wireless/iwl4965-ucode created an extra entry in my world profile: net-wireless/iwl4965-ucode:0. I wonder what that is for.

Customizing Google AdSense alternate ads

When AdSense runs out of inspiration (i.e.: no targeted ads are available), it displays public service ads by default. You can choose to replace this with a custom ad of your own choosing. To do this, you have to put a HTML page somewhere and change the alternate ads settings for the appropriate ad unit:

AdSense unit: alternate ads settings for HardhoutWiki leaderboard

Alternate ads settings for HardhoutWiki leaderboard AdSense unit

Instead of the public service ads, I wanted to serve a banner ad to promote our beautiful family vacation home. I created this image a few years ago for an AdWords campaign started by my uncle because he wanted to reach more potential vacation goers.

Schuilplaats banner ad

The 728x79 banner image

I put put up a page with the image at http://www.bigsmoke.us/schuilplaats-banner-ad/. The HTML is very simple:

<html>
  <head></head>
  <body>
    <a href="http://www.hugovandermolen.nl/schuilplaats/startpagina.php"><img src="schuilplaats-banner-ad.jpg" /></a>
  </body>
</html>

If anyone wants to promote our vacation home for free, all they have to do is to change Alternate ads or colors to Show non-Google ads from another URL and fill in http://www.bigsmoke.us/schuilplaats-banner-ad/.

Although I put the alternate ad up over a year ago, I was prompted to blog about it because two months ago, for the first time, I suddenly saw the ad actually being serviced on my Dutch HardwoodWiki:

The alternate ad in action

The alternate ad in action

Complete WordPress Atom feed: an XSLT transformation

Previously, I tried obtaining a full Atom feed without pagination from WordPress. I didn’t succeed, so I ended up writing an XSL transformation which merges all the pages of this Atom feed into one valid Atom XML stream.

The transformation: wordpress-full-atom-feed.xsl

<?xml version="1.0" encoding="UTF-8"?>
 
<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:thr="http://purl.org/syndication/thread/1.0"
xmlns="http://www.w3.org/2005/Atom">
 
<xsl:param name="base_url" select="atom:feed/atom:link[@rel='self']/@href" />
 
 
<xsl:template match="/">
  <xsl:apply-templates select="node()" />
</xsl:template>
 
<xsl:template match="*">
  <xsl:element name="{name(.)}">
    <xsl:apply-templates select="node()" />
  </xsl:element>
</xsl:template>
 
<xsl:template match="@*|node()">
  <xsl:copy-of select="." />
</xsl:template>
 
<xsl:template match="atom:feed">
  <feed>
    <xsl:apply-templates select="@*|node()" />
 
    <xsl:call-template name="process_feed_page">
      <xsl:with-param name="page" select="number('2')" />
    </xsl:call-template>
  </feed>
</xsl:template>
 
<xsl:template name="process_feed_page">
  <xsl:param name="page" />
 
  <xsl:variable name="page_doc" select="document(concat($base_url, '?paged=', $page))" />
 
  <xsl:if test="$page_doc/atom:feed/atom:entry">
    <xsl:apply-templates select="$page_doc/atom:feed/atom:entry" />
  
    <xsl:call-template name="process_feed_page">
      <xsl:with-param name="page" select="$page + 1" />
    </xsl:call-template>
  </xsl:if>
</xsl:template>
 
</xsl:transform>

The transformation works by processing the atom:feed element. Before closing that, the process_feed_page template is called. This template tries to open the next page and process all atom:entry elements in there. Then it tries to recurse to the next page.

The next page’s URL can be guessed because this is the normal feed URL with ?paged=[pagenum] appended to it. The feed URL can be found because WordPress adds it to the feed:

<link rel="self" type="application/atom+xml" href="http://blog.bigsmoke.us/author/halfgaar/feed/atom" />

For very old WordPress versions this doesn’t work, because the paged parameter isn’t supported there. Also, older versions might require you to supply the $base_url param to the XSLT processor, because the rel='self' link is incorrectly set to the URL of the default feed within all other feeds (such as the author feed or the tag feed).

Invocation

Invocation is simple. I use libxslt‘s xsltproc:

xsltproc wordpress-full-atom-feed.xsl http://blog.bigsmoke.us/author/halfgaar/feed/atom

That’s it. You end up with a full feed as if there never was any pagination to begin with; it almost looks as if WordPress does support the nopaging option for feeds.

Enforcing Drupal URL aliases

I hate modules, especially core modules. I prefer code to be tightly integrated. I want it to work together. Is that too much to ask? In Drupal, most functionality has been stuffed in modules. There’s a Locale module, a Content Translation module and a Path module. What’s missing is a Working Together module.

For me, clean, meaningful URLs are a number one, two and three requirement for any website that I do. Drupal considers /node/54673 to be a cool URL. I don’t. So, as a kind of afterthought, Drupal comes with the Path module. This module allows you to set URL aliases per node.

The problem is that there’s no concept of a canonical URL. The URL alias works, but so does the node/3242 URL. Neither redirects to the other. In many cases this is not much of a problem (because regular visitors will not notice this) but for our current project it is.

We have a lot of blocks with URL dependent visibility settings. For example, for a section about investing we have a menu that is displayed on all URLs starting with /investing, such as /investing/projects and so on.

After editing a page, Drupal helpfully redirects the user to node/[nodenumber]. For us, this means that the menu is no longer displayed and even the theme will be wrong. (We use the Sections module to select a subtheme based on which section you’re in.)

Global Redirect doesn’t work

The Global Redirect module promises to solve this by allowing you to redirect node/[nodenumber] URLs to their alias if available. It kinda does, in some circumstances.

Our Drupal website sports two languages: English (EN) and Dutch (NL). English is the default language (not the fallback language; we don’t use a fallback) and doesn’t use a prefix. Dutch uses the nl prefix. Two example URLs:

URL alias Generic URL
http://www.example.com/investing/projects http://www.example.com/node/288
http://www.example.com/nl/beleggen/projecten http://www.example.com/nl/node/110

When /node/288 is requested, the client is correctly redirected to /investing/projects, but when /node/110 is requested, no redirect takes place. It will take place when prefixing /nl, but this is completely useless since Drupal’s built-in actions such as edit don’t redirect using this prefix, and these actions were what we needed this module for in the first place.

A very simple hack that does work

We ended up tearing our hair out trying to fix Global Redirect until we decided that we could just delete the module and replace it with a RewriteRule and a simple PHP script.

Modify: .htaccess

# Put this after RewriteBase and before Drupal's default rewrite rules
RewriteRule ^(../)?node/([0-9]+)$ fixurl.php?nid=$2 [L]

Add: fixurl.php

<?php
 
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
 
$result = db_query("SELECT * FROM {url_alias} WHERE src = 'node/%d' LIMIT 1", $_GET['nid']);
if ( db_error() ) die("O agony!");
 
$url_alias_object = db_fetch_object($result);
$destination = $url_alias_object->dst;
 
$result = db_query("SELECT prefix FROM {languages} WHERE language = '%s'", $url_alias_object->language);
if ( db_error() ) die("O agony!");
 
$prefix = db_result($result);
 
if ( !empty($prefix) )
  $prefix .= '/';
 
header("Location: /$prefix$destination",TRUE,301);
 
?>

Shortcomings in our hack

The code assumes that every content page has an URL alias. For us, this is okay, because we need these pretty URLs to even have menus show up or to have the right page be displayed with the right theme.

Also, this code is specifically tailored to language code in the URL prefix. For subdomain based language selection, for example, you’d need to modify it.

« Older posts Newer posts »

© 2024 BigSmoke

Theme by Anders NorenUp ↑