.comment-link {margin-left:.6em;}

Linux stories... and more

Monday, May 01, 2006

Fine-grained EVMS device nodes

Recently I've finally started to use EVMS for Volume Management. In this article, I'll explain how I've managed to marry EVMS with udev :).

First, I'd like to mention how my LFS-based systems boot: I distinguish "my" root file system by UUID. I.e. on kernel command line instead of root=LABEL=/root you supply UUID=543fcb1d-b73c-4f7b-8e00-1f92b232d188, which is the UUID of the partition that holds your root. Usually, initramfs image that does all of the magic, has hard-coded UUID of the root file system it was built from.

Next task was to make initramfs to discover file systems by their UUID. With recent udev rules, its rather easy. With the following rules from /etc/udev/rules.d/60-persistent-storage.rules:
# by-label/by-uuid (filesystem properties)
KERNEL=="*[!0-9]", SYSFS{removable}=="1", GOTO="persistent_storage_end"
IMPORT{program}="/sbin/vol_id --export $tempnode" ENV{ID_FS_UUID}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID}"
ENV{ID_FS_LABEL_SAFE}=="?*", SYMLINK+="disk/by-label/$env{ID_FS_LABEL_SAFE}"
all your initramfs needs to do is to:
  • load storage drivers
  • setup udev environment
  • finally, just look at /dev/disk/by-uuid/$UUID
    Back to EVMS. I've thought that all I'll need to do in order to add EVMS support to my initramfs is just to add evms_activate command. I was very surprised that my EVMS volumes did not show up under /dev/disk/by-uuid/.
    I've started to dig... Conclusions:
  • EVMS does not send any uevents, but
  • It uses device-mapper to export device nodes - this looks promising
    So, EVMS works together with device-mapper - for each EVMS object (i.e. Volume, Container, Segment, etc...) device mapper exports sysfs entry /sys/block/dm-*, which is picked up by udev and /dev/dm-<number> is created.

    Having a closer look at /etc/udev/rules.d/60-persistent-storage.rules I've found the following rule, which provides /dev/disk/by-name (does not help much).
    KERNEL=="dm-[0-9]*", ACTION=="add",     PROGRAM="/sbin/dmsetup info -c --noopencount                                    --noheadings -o name -j %M -m %m",     SYMLINK="disk/by-name/%c"

    Note, that the rule uses SYMLINK=... and not SYMLINK+=... action. That's why further matching rules are not applied.

    Take one: Change SYMLINK=... to SYMLINK+=... in the above rule.

    Great. The results are almost perfect - now all /dev/dm-0 device files have corresponding links in /dev/disk/by-uuid, BUT(!)...

    But... As I've mentioned earlier, device mapper has /dev/dm-* for each EVMS object. So lets say you have /dev/dm-1, which actually EVMS region, and /dev/dm-2 which a EVMS volume (that sit on the mentioned region) that contains valid file system.
    The bad news are, that running /sbin/vol_id --export will return the same sane results both for /dev/dm-1 and /dev/dm-2. But mounting of /dev/dm-1 will obviously fail (since it is not volume, but region).
    So the actual problem is that if your volume has UUID=<what_ever>,
    then /dev/disk/by-uuid/$UUID may point either to /dev/dm-1 or to /dev/dm-2, and in the first case, mounting /dev/disk/by-uuid/$UUID will fail!

    So we need to distinguish between dm-* devices that point to volumes and others. How? - All active volumes has corresponding device nodes in /dev/emvs/. That directory is managed by EVMS user-space tools.
    So for each dm-* node we first retrieve its name using dmsetup and then, if /dev/evms/<name> exists, we create /dev/disk... links.

    Take two: I've created separate udev rules file, 61-evms.rules, which has the following rules:
    KERNEL=="dm-[0-9]*",    ACTION=="add",    IMPORT{program}="/bin/sh -c 'echo DMNAME=`(/sbin/dmsetup info -c                     --noopencount --noheadings -o name -j %M -m %m`'"
    KERNEL=="dm-[0-9]*", ACTION=="add", IMPORT{program}="/sbin/vol_id --export $tempnode"
    KERNEL=="dm-[0-9]*", ACTION=="add", ENV{ID_FS_UUID}=="?*",PROGRAM="/bin/test -e /dev/evms/$env{DMNAME}", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID}"
    KERNEL=="dm-[0-9]*", ACTION=="add", ENV{ID_FS_LABEL_SAFE}=="?*", PROGRAM="/bin/test -e /dev/evms/$env{DMNAME}", SYMLINK+="disk/by-label/$env{ID_FS_LABEL_SAFE}"

    Related links:
  • evms.rules file
  • mkinitramfs project that creates all those "magic" images.
    Update 04.05.2006:
    After talking to guys from linux-hotplug, the following changes have been made:
  • /dev/dm-* device nodes are not needed
  • links should be created to /dev/evms/* files and not to /dev/dm-* files.So the line considering dmsetup in the 60-persistent-storage.rules was replaced with the following:
    # Do not create device-mapper nodes
    KERNEL=="dm-[0-9]*", NAME+=""
    and emvs.rules file now looks like following:
    KERNEL=="dm-[0-9]*",    ACTION=="add", IMPORT{program}="/bin/bash -c 'echo DMNAME=$$(/sbin/dmsetup info -c                     --noopencount --noheadings -o name -j %M -m %m)'"
    KERNEL=="dm-[0-9]*", ACTION=="add", IMPORT{program}="/sbin/vol_id --export $tempnode"
    KERNEL=="dm-[0-9]*", ACTION=="add", ENV{ID_FS_UUID}=="?*", PROGRAM="/bin/test -e /dev/evms/$env{DMNAME}", RUN+="/bin/ln -sf /dev/evms/$env{DMNAME} /dev/disk/by-uuid/$env{ID_FS_UUID}"
    KERNEL=="dm-[0-9]*", ACTION=="add", ENV{ID_FS_LABEL_SAFE}=="?*", PROGRAM="/bin/test -e /dev/evms/$env{DMNAME}", RUN+="/bin/ln -sf /dev/emvs/$env{DMNAME} /dev/disk/by-label/$env{ID_FS_LABEL_SAFE}"

    Here is the link to updated rules file: evms.rules.new

  • bug in konsole

    As a 'die-hard' KDE user, I use konsole application on every day basis. A long time a go I've run into a strange problem - I've failed to change default konsole session - it always remains shell.desktop.

    Looking down to config files, I've found that there is a DefaultSession parameter in konsolerc that is responsible for setting the default session. But the problem is that konsole just ignores this paramter.

    Source code inverstigaion showed that upon startup, konsole indeed ignores DefaultSession setting and just always sets shell.desktop to be the default session.

    Well, if it does not work - fix it yourself :) So I've created the patch (against kde-3.5.2) and opened the bug.

    Update 04.05.2006:
    The patch has been accepted upstream and the bug has been closed.

    Thursday, January 26, 2006

    blkid bug

    I've encountered blkid utility being stuck on the following scenario:

    I use kernel 2.6.15 with udev for hotplug and device nodes management.Suppose I load storage module (say ata_piix + sd_mod), then after some time (say A), /proc/partitions is updated. After a bit more time (say B), udev will create corresponding device nodes. Now the problem:

    If you run blkid between time A and time A+B, it will scan /dev recursivly trying to find device node with appropriate major/minor to match /proc/partitions entry. The problem is that there is a directory /dev/.udev/failed, that contains links to /sys, and from there one may easily go to infinite loop - and that is what blkid does.

    Proposed solution is just make blkid to skip /dev/.udev* directory.
    You can grab the patch here.

    I'll post updates if there will new from e2fsprogs maintainers.

    Wednesday, November 16, 2005

    Bugs in pam_timestamp module

    I have played a bit with pam_timestamp module. With the module, one can configure some application to grant access to the user, if the user has already authenticated recently. This is useful for various configuration tools (for example, RedHat's system-config-<xxx> series), and can get a feeling of Single-Sign-On.

    To demonstrate, I'll use su command. Here is its pam configuration file.
    NOTE: this is sample configuration - do not use this in real environments
    auth       sufficient    pam_rootok.so
    auth sufficient pam_timestamp.so verbose
    auth include system-auth
    account include system-auth
    password include system-auth
    session include system-auth
    session optional pam_timestamp.so

    When you su for the first time, session part of the configuration creates timestamp. Next time you su from the same terminal auth part will grant you access if recorded timestamp is recent enough.

    This is what is supposed to work. In practice, it works only if you login on /dev/ttyx. After ensuring that configuration is fine, I've started digging into sources, and have discovered, that checks for tty device file sanity are pretty loose:
  • The supposed tty name should not contain / character, and if it does, then tty name is something in the form /dev/ttyx. This rule ceases to work when you use, say, xterm and your tty in like pts/14.

  • I've decided to replace those policies with the following:
  • Complement received tty name to full device file string.
  • Execute access system call to ensure the terminal device file is writable by the user.

  • I've created patch that fixes the situation. The patch is relevant for pam-0.80-13-src.rpm (Fedora Development Sources).

    Monday, November 07, 2005

    Embarassing bash

    About three month ago I've discovered an interesting way to render bash shell unusable. Consider the following very simple bash script:
    for i in 1 2 3; do
    return
    done

    Put this script in the file, say, sourceme. Next, if you do the following:
    #> source source
    #> sleep 10

    ... Now hit CTRL-Z to suspend the sleep ...
    At this point, the shell starts to behave very strangely. Lets just say that ls /tmp (or anything else) does not show anything.

    I've send the message to bash-bug mailing list, reporting the problem to X, but there was no a single reply.

    Update 23.11.2005:
    bash guys have finally replied, saying that the bug has been confirmed and will be fixed in release 3.1.

    Thursday, October 13, 2005

    How to add counter to your blog

    This is a story how I've added counter to my blog. But the recipe is right for adding counters to any page, especially, if do not have much control over the host.

    OK, lets begin. One day I've come to http://nfsworld.blogspot.com and saw that the blog has counter at the bottom of the page. The design of the thingy was not astonishing, but it did the job. I've started to play with it: http://www.sitemeter.com - they give you free counter. Quickly, I've discovered major problem with their service:
    The counter display you actually get is rendered image. You can choose from a pretty small number of predefined patterns with different colors. Generated text on the image is not anti-aliased, and since its the image, it does not benefit from your CSS settings. Bottom line - no matter how I've tried, counter still did not fit well into overall blog design.

    I've said good bye to sitemeter and... Google we go. After short time, I've came to http://www.statcounter.com. They also offer free service. But here there are far more design options. I've chosen my favorite one - plain text. I.e. the script just gives you plain number. This way you can design counter look any way you like and perfectly fit it in your blog design.

    How to install:
    Generally, just follow instructions on website. If you host your blog on http://www.blogger.com, you'll need to insert script snippet to the blog template. That's what I've done:

    <h2 class="sidebar-title">Stats</h2>
    <p>
    Visitors:
    <!-- Start of StatCounter Code -->
    <span style="font-style: italic;">
    ... code you've got from statcounter goes here...
    </span>
    <!-- End of StatCounter Code -->
    </p><p></p>
    You may also want to place a link to statistics page of your counter

    To the end, here are some links to HTML and CSS resouces:

    Wednesday, October 12, 2005

    CD verification in RedHat installer - be careful

    Since RedHat Linux 9, there is a CD verification feature during install process. I.e. installer can check whether disc contents checksum matches the one written in checksum file.

    Recently I've received 4 CDs with RedHat Enterprise Linux 3 AS for i386. To make sure, I've decided to test them using the feature mentioned - all checks passed.

    During install, anaconda has asked to put disc 3 in. I did, but installer stated that the disc is wrong. After some investigation, I've found out that disc number 3 is actually for x86-64 (the guy gave me disc from other bundle) and not for i386!

    I.e. installer checks checksums, but does not check whether disc belongs to the same serie!

    I wonder what it would tell, if I gave it disc 3 from, say, RH EL 4. :)

    I hope RedHat will fix this misleading bug in future releases.

    Friday, September 30, 2005

    Out of Internet...

    While I've been out of Internet for some time, someone has dropped me the following to the mailbox:

    The girl gets irritated with the smoke and says to her lover:
    "Can't you see the warning written on the cigarette packet,
    Smoking is dangerous to your health?"
    The boy replies back:
    "Darling, I am a programmer, we don't worry about
    WARNINGS, we only worry about ERRORS!