Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
EVMS + Udev HOWTO
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
garlicbread
Apprentice
Apprentice


Joined: 06 Mar 2004
Posts: 180

PostPosted: Sun Nov 28, 2004 9:52 pm    Post subject: Reply with quote

This is something I've only just got working, so perhaps this will be useful
note that I'm using the latest version of udev 046 (but I don't think this makes a difference)
also your nodes for evms and lvm may already be showing up via the tar-ball method but if you want to do this via a udev pure system

Quick Setup Guide

1. install multipath-tools
the devmap_name binary has now been moved out of udev into multipath-tools
see ebuild here http://bugs.gentoo.org/show_bug.cgi?id=71703

2. create a new script called /etc/udev/scripts/dmmapper.sh
with this code
Code:
#! /bin/sh -e
#
# Add a second output to devmap_name

mappername=`devmap_name ${1} ${2}`

vname=${mappername}
# For evms the seperator used is |
vname=`echo ${vname} | sed -e 's/|/\//g'`
# for lvm the seperator used is -
vname=`echo ${vname} | sed -e 's/-/\//g'`

prefix=${3}
echo ${mappername}' '${prefix}${vname}


3. add these rules to /etc/udev/rules.d/10-local.rules (create the file if it doesn't already exist)
EDIT, I've removed the lookup on the Major number as I think this is assigned dynamicly
remove the beginning # depending on if your using evms or lvm

Code:
# For LVM Uncomment this line
#KERNEL="dm-[0-9]*", PROGRAM="/etc/udev/scripts/dmmapper.sh %M %m", NAME="mapper/%c{1}" SYMLINK="%c{2}"
# For evms Uncomment these lines
#KERNEL="dm-[0-9]*", PROGRAM="/etc/udev/scripts/dmmapper.sh %M %m evms/", NAME="mapper/%c{1}" SYMLINK="%c{2}"
#KERNEL="device-mapper", SYMLINK="evms/dm/control"


4. to refresh the udev /dev directory (or wherever it's setup)
run "udevstart"


Testing udev

Also this might be useful
if your like me and you want to test out udev before moving away from devfs, there is a simple way to do this
if devfs is active then it will take presedence over udev and will take control of the /dev directory, the udevd process will run but not do anything as it can't write into /dev while devfs is active
(note don't do this if your already booting from udev and have turned devfs off, this is only for those users still booting from devfs, otherwise your system may become unbootable)

create a new directory called /udev
alter the /etc/udev/udev.conf file
change udev_root="/dev/" to udev_root="/udev/"
change udev_db="/dev/.udevdb" to udev_db="/udev/.udevdb"

I also added this to my /etc/fstab
Code:
none                    /udev           tmpfs           defaults                0 0


and run
mount /udev
udevstart

udev will now output it's files to /udev instead of /dev
the advantage of this is that you can still boot your system with devfs but fiddle around with the udev configruation files
and compare the contents of /dev against /udev to check everything is being picked up with udev. Although you'll need to run udevstart manually for /udev to be populated properly after bootup as I don't think the bootup scripts run this if it detects that devfs is active

once your happy with the correct files showing up in /udev
(that all the hardware is showing up okay, including the device nodes you'll need to boot off e.g. /udev/evms/lvm2/root etc)
you can alter the udev.conf to point back to /dev (the way it was originaly)
alter the fstab entry from /udev to /dev
and finaly disable devfs


How the above scripts work

At the moment udev only sees device mapper files as dm-0 dm-1 dm-2 etc
since evms and lvm use device mapper this can be a problem

looking at the default rules /etc/udev/rules.d/50-udev.rules
the default rule for device mapper files is
Code:
# dm devices (ignore them)
KERNEL="dm-[0-9]*",     NAME=""

This means that device mapper files are not mapped at all at the moment and are just ignored

there is another rule that could be used instead below which is commented out
Code:
# note devmap_name comes with extras/multipath
#KERNEL="dm-[0-9]*",    PROGRAM="/sbin/devmap_name %M %m", NAME="%k", SYMLINK="%c"

but it's best to use a different rule instead to get the same result as you would with devfs
the above example puts custom rules into 10-local.rules which is called before the default rule set as it has a lower number

devmap_name is able to give the name of the device by giving the major and minor numbers of the device as parameters and getting the name of the device as the output

On my own system evms has a major number of 253, and lvm has a major number of 254
but I've left this out of the rule for matching the device, as I think these numbers are assigned dynamicly and may be different for different systems
the minor number is the device that evms or lvm has setup which ranges from 0 to whatever
the first place that these files show up is in /dev/mapper
e.g. for my evms desktop system the /dev/mapper directory looks like this
Code:
crw-r-----  1 root root  10, 61 Jan  1  1970 control
brw-r-----  1 root root 253,  0 Jan  1  1970 hda1
brw-r-----  1 root root 253,  1 Jan  1  1970 hda2
brw-r-----  1 root root 253,  2 Jan  1  1970 hda4
brw-r-----  1 root root 253,  3 Jan  1  1970 hda5
brw-r-----  1 root root 253,  4 Jan  1  1970 hda6
brw-r-----  1 root root 253,  5 Jan  1  1970 lvm2|vg|root_first
brw-r-----  1 root root 253,  6 Jan  1  1970 lvm2|vg|swap

I also have a second system on LVM, /dev/mapper looks like this
Code:
brw-r-----  1 root root 254,  0 Jan  1  1970 vg-root


running "devmap_name 253 5" on the evms system would give the name "lvm2|vg|root_first"
since we also want files to appear within /dev/evms/
we can create symlinks for this, but I needed a way of interpreting lvm2|vg|root_first into lvm2/vg/root_first
dmmapper.sh does this and calls devmap_name in the process
running "dmmapper.sh 253 0 evms/" will give the output "lvm2|vg|root_first evms/lvm2/vg/root_first"
%c{1} picks off the lvm2|vg|root_first
and %c{2} picks off the evms/lvm2/vg/root_first


If your also using an evms initrd (if your running root on evms) then you'll probably need to include udevd and the config files into the initrd image as well as altering the linuxrc file to run udevd
this is the next thing I'll be trying out :D
Back to top
View user's profile Send private message
tschenturs
n00b
n00b


Joined: 17 Nov 2004
Posts: 12

PostPosted: Thu Dec 09, 2004 10:41 am    Post subject: Reply with quote

Thanks a lot garlicbread. Great post.
Back to top
View user's profile Send private message
pilla
Administrator
Administrator


Joined: 07 Aug 2002
Posts: 7212
Location: Pelotas, BR

PostPosted: Thu Dec 09, 2004 11:58 am    Post subject: Reply with quote

split from here and moved to Documentation, Tips & Tricks.
_________________
"I'm just very selective about the reality I choose to accept." -- Calvin
Back to top
View user's profile Send private message
garlicbread
Apprentice
Apprentice


Joined: 06 Mar 2004
Posts: 180

PostPosted: Sat Apr 09, 2005 11:15 pm    Post subject: Reply with quote

As of device-mapper 1.00.20 it's now posible to use dmsetup in the same way as devmap_name
EDIT latest version 1.01.00 can handle this no problem

EDIT
as of udev058 the behavior of custom rules has now changed (I think)
udev appears to search through the rules in lexical order as before i.e. 10-local.rules and then 50-udev.rules
but the last rule found with NAME instead of the first rule found is being used

I'm not sure if this is correct or if its a bug but we can get around this by adding OPTIONS="last_rule" to the end of our own rules
the default rule for 50-udev.rules is KERNEL="dm-[0-9]*", NAME=""
which basically means ignore anything to do with device mapper
to use our own rule in favour of the one in 50-udev.rules
I had to add OPTIONS="last_rule" to the end of each rule in 10-local.rules


as an example add this into 10-local.rules
Code:

SUBSYSTEM="block", GROUP="disk"
# For LVM uncomment the below
#KERNEL="dm-[0-9]*", PROGRAM="/etc/udev/scripts/dmmapper.sh %M %m", NAME="mapper/%c{1}", SYMLINK="%c{2}", OPTIONS="last_rule"
# For evms uncomment the below
KERNEL="dm-[0-9]*", PROGRAM="/etc/udev/scripts/dmmapper.sh %M %m", NAME="mapper/%c{1}", SYMLINK="evms/%c{2}", OPTIONS="last_rule"
KERNEL="device-mapper", SYMLINK="evms/dm/control", OPTIONS="last_rule"

# If nether of the above are chosen default to creating under /dev/mapper
KERNEL="dm-[0-9]*", PROGRAM="/etc/udev/scripts/dmmapper.sh %M %m", NAME="mapper/%c{1}", OPTIONS="last_rule"



updated dmmapper.sh script (to be placed in /etc/udev/scripts/)
Code:

#! /bin/sh -e
#
# manipulate the output of dmsetup info

# This doesn't appear to work with kpartx
# Some sort of timing issue
# linear maps via dmsetup don't appear to have this problem

# first grab the output of dmsetup info by passing the major / minor numbers
basename=`dmsetup info -j ${1} -m ${2} | grep "Name"`
# Strim off the Name: part
basename="${basename#*:}"
# Strim off and leading spaces
basename=`echo ${basename} | sed "s/^[ \t]*//;s/[ \t]*$//"`

# typically for evms this could be hda1 or lvm2|vg|rootfirst
# with | used as a seperator for evms or - for lvm

# Now work out what the seperated name would be
# e.g. convert lvm2|vg|rootfirst into lvm2/vg/rootfirst
sepname=${basename}
# For evms the seperator used is |
sepname=`echo ${sepname} | sed -e 's/|/\//g'`
# for lvm the seperator used is -
sepname=`echo ${sepname} | sed -e 's/-/\//g'`

echo ${basename}' '${sepname}
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum