Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 09-08-2009, 03:53 AM   #1
LQ Newbie
Registered: Sep 2009
Posts: 9

Rep: Reputation: 0
Help on naming iscsi devices with udev

I don't like the idea when iscsi drives are attached on target system,
devices get names /dev/sdb, /dev/sdc. In virtual environment you get
easly 100 targets and how about when I don't need that LUN 26 on drive anymore. Will my device /dev/sdbb still
be there or will it be at /dev/sdba. And it is ugly anyway.

Partial solution can be found in /dev/disk/by-path/ where device is
assigned by iscsi server name and lun.
But this is ugly too. And doesn't tell much about what does one device

On iscsi server I have LVM with logical volume names like wwwportal,
dns1, dns2, windowsAD ..... and what I would like is name devices on
target with similar names /dev/iscsi/wwwportal, /dev/iscsi/dns1 .....
and the same way I will also name my KVM machines.

I know it can be done with udev rule calling extern script which would
have to include some kind of conversion table which would return name
for disk and lun. I also know that table must be edited each time new
disk is added. But that is just about everything I know.

Can you help me with this please.
1. udev rule and into which file to put it
2. skeleton of shell script which would be called by rule

Old 09-09-2009, 08:46 AM   #2
LQ Newbie
Registered: Sep 2009
Posts: 9

Original Poster
Rep: Reputation: 0
Since nobody got nothing I am asking you what do you think of this solution. I still have lots of testing to do, but so far it works:

1. I have created /etc/iscsi/persistent.names.conf. It looks like this:;0;iscsi/win_portal;1;iscsi/dns1;2;iscsi/dns2

2. I have created /etc/udev/rules.d/60-persistent-iscsi.rules. It looks like this:

# This file maintains persistent names for iscsi disks.

ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="", DEVPATH!="*/virtual/*", IMPORT{program}="path_id %p"
ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="?*", PROGRAM="/usr/bin/persistent_iscsi.rb $env{ID_PATH}", SYMLINK+="%c"

3. And finaly I have created this Ruby script, since I do almost all my programing in Ruby.


# id looks like this:
device = nil
id = ARGV.first
# parse id on - sign
a = id.split('-')
# get lun and iqn
id_iqn = a[3] + '-' + a[4]
id_lun = a[6]
# third part should be iscsi
exit 1 unless a[2] == 'iscsi'
# read my configuration file /etc/iscsi/persistent.names.conf'/etc/iscsi/persistent.names.conf').readlines.each do |line|
# config line looks like this:;2;iscsi/dns1
iqn, lun, dev = line.chomp.split(';')
if iqn == id_iqn and lun == id_lun
device = dev
# Error if not found
exit 1 if device.nil?
# out device name on stdout
puts device


Last edited by TheR_; 09-09-2009 at 08:51 AM.


iscsi, udev rules

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hotswap and udev persisten naming Thure Linux - Server 3 01-26-2009 07:41 AM
Changing UDEV persistent naming schemes orbit Slackware 5 04-21-2008 10:22 PM
udev rule failing to create iscsi symlinks! patrarch Linux - Newbie 1 11-29-2007 04:42 PM
udev rule failing to create iscsi symlinks patrarch Linux - Networking 1 11-29-2007 02:41 AM
iSCSI, LUN, and devices gmex Linux - Software 3 09-22-2007 10:13 AM

All times are GMT -5. The time now is 03:41 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration