hprofile - dynamic profiles for linux: hardware configurations; network connections; power management; usage patterns...
 
SourceForge.net Logo

Bits:

Download:

Documentation:

Contact:

Goodies

On this page, you'll find a few extra scripts and configuration tips. These are not directly related to hprofile, but they complement it in many of the situations where hprofile would be used. Suggestions and submission are more than welcome for additional scripts and tools. This page is expected to grow with time.

Make sure your hotpluggable devices retain their device nodes

Block devices such as USB "pen" drives, MP3 players or cameras that are plugged in and out frequently will get allocated device nodes in /dev sequentially. For example, if you have a USB "pen" drive and an MP3 player which connects as a USB storage device so you can move files across to it, the first device you plug in will be given the device node /dev/sda1 (via the usb-storage modules); the second device will get /dev/sdb1, and so on. This can cause trouble if you have created mount point for the various devices in /etc/fstab, because if you specify that /dev/sda1 should be mounted on /mnt/usb-pen, say, but plug in the MP3 player first, then /dev/sda will refer to the MP3 player, not the USB "pen" drive.

I wrote a script to solve this problem, which can be found here. This script is a hotplug event handler. You will need a 2.6 series kernel, sysfs mounted on /sys, hotplug enabled in the kernel and the hotplug package installed on your system. On my Gentoo Linux system, this has a configuration directory in /etc/hotplug.d. Since this event handler is meant for "block" device events, I put it in /etc/hotplug.d/block/make-symlinks.hotplug. The ".hotplug" suffix is important - if it's missing, hotplug will ignore it - and you (probably) have to put it in the "block" directory as well. See your system documentation for more details on how hotplug is set up, but from what I gather, Gentoo's setup is fairly standard, so chances are you should put the script in /etc/hotplug.d/block.

The make-symlinks.hotplug script above will create a symlink of your choosing in /dev based on the model name of the device, as reported by the driver in /sys. To set this up, note the model name by plugging the device in, and looking in /sys/block/sd?/device/model, where "sd?" will probably be "sda" or "sdb"; it could also be "hde", for example, if this is an IDE device (PCMCIA card readers, for instance, are ususally IDE devices). In my case, I have a Creative Labs Nomad MuVo NX, which shows up with a model name of "NOMAD MuVo NX". I want to have a symlink to this device called /dev/muvo.

The make-symlinks.hotplug script looks for a file called "symlinks.rc"; this should be /etc/hotplug.d/block/symlinks.rc. If you want it elsewhere, change the value of the variable CONFIG at the top of make-symlinks.hotplug. This file should contain a line for each device you want the script to set up (and nothing else), of "/dev/<link> <device model name>". For example:

/dev/muvo NOMAD MuVo NX
/dev/pen USB Pen Drive
Now, when the device with model name "NOMAD MuVO NX" is plugged in, it will take a device name (say, "/dev/sdb1"); make-symlinks.hotplug will then create a symbolic link from this device to /dev/muvo. Hence, in /etc/fstab you can set up a mount point for "/dev/muvo" on /mnt/muvo, say, and this will always work after you've plugged the MuVo in.

Warning: This script probably won't work great for devices with more than one active partition, nor will it be able to distinguish between two devices with the same model name. If you need this functionality, let me know, and I can probably extend it for you. Also note that the script will remove the symlink again when the device is removed.

 
Copyright (c) 2003-2004 Martin Aspeli