≡ Menu


Linux udev tip: Assign Static SCSI Device Name

So how do you assign static names for SCSI device using udev under Linux? Simply use the scsi_id and other udev tools such as :

[a] scsi_id - retrieve and generate a unique SCSI identifier.
[b] udev_start - script to initialize /dev by using udev
[c] udevtest - simulate a udev run and print the action to the console.

What the hell is udev?

udev is the device manager for the Linux 2.6 kernel series. Its primary function is managing device nodes in /dev. Old UNIX system creates device in the /dev with static files. udev dynamically provides only the nodes for the devices actually present on a system.

Note following configuration is only tested on Gentoo / RHEL 5.x / CentOS 5.x Linux server systems but it should work with other distros with udev support.

Step # 1: Get WWID of the SCSI device

To get the WWID of /dev/sdd, type:
# scsi_id -g -u -s /block/sdd

  • -g : Treat the device as white listed
  • -u : Reformat the output
  • -s /bock/sdd : Generate an id for the /block/sdd (/dev/sdd). The mount point must not be included. For example, use /block/sdd, not /sys/block/sdd.

Step # 2: Create /etc/udev/rules.d/25-names.rules file

Open /etc/udev/rules.d/25-names.rules and append following text (replace WWID with actual id obtained from above command):

KERNEL=="sd*", BUS=="scsi", PROGRAM=="/sbin/scsi_id -g -u -s %p", RESULT=="WWID", SYMLINK+="scsiharddisk%n"

Above rule will create /dev/scsiharddisk (a symlink - select any other meaningful name as per your proecjet ) for the SCSI device with a given WWID. Please note that partitions on this device will be assigned the device names like /dev/scsiharddisk1, /dev/scsiharddisk2 and so on. Next, verify that everything is correct order, enter:
# udevtest
Start initialize /dev for new devices:
# start_udev
Verify symbolic links are created, enter:
# ls -l /dev/scsiharddisk*

Read the man pages for more information:
man scsi_id
man udevtest
man 7 udev

Many of our regular readers like to know more about lighttpd hotlink protection using mod_rewrite. Lighttpd can use HTTP referrer to detect hotlink and can be configured to partially protect hosted media from inline linking, usually by not serving the media or by serving a different file.

Lighttpd anti hotlinking configuration - redirect to another media

Open lighttpd.conf configuration file:
# vi /etc/lighttpd/lighttpd.conf
Append the following directive to redirect to a default picture called /hotlink.png:

$HTTP["referer"] =~ ".*BADDOMAIN\.com.*|.*IMAGESUCKERDOMAIN\.com.*|.*blogspot\.com.*" {
  url.rewrite = ("(?i)(/.*\.(jpe?g|png))$" => "/hotlink.png" )

So if anyone from *.blogspot.com linked www.cyberciti.biz/image.png it will be replaced with www.cyberciti.biz/hotlink.png. I've written small script to detect excessive hotlink from log file and ban all those domains. Most types of electronic media can be redirected this way, including video files, music files, and animations etc.

Related: Apache web server user can stop leechers using mod_rewrite / .htaccess rules.

A sudden outburst of violent disk I/O activity can bring down your email or web server. Usually, a web / mysql or mail server serving millions and millions pages per months are prone to this kind of problem. Backup activity can increase current system load. To avoid this kind of sudden outburst problem, run your script with scheduling class and priority. Linux comes with various utilities to manage this kind of madness.
[click to continue…]

Internally we use RT (enterprise-grade ticketing system) for customer support and it is one of the best GPL software around. It enables a group of people to intelligently and efficiently manage tasks, issues, and requests submitted by a community of users. RT manages key tasks such as the identification, prioritization, assignment, resolution and notification required by enterprise-critical applications including project management, help desk, NOC ticketing, CRM and software development.

Linux magazine has published a nice article about RT installation and configuration:

Managing bugs and help requests isn't easy, but it's crucial for effective project management. Using the wrong tool can set your project back to the dark ages, but the right tool can help your team excel. With that in mind, let's look at Request Tracker, an enterprise-grade (and free software) ticketing system written in Perl.

A ticketing system is a piece of software in which every bug, request, or problem is entered as a 'ticket,' which can then be tracked. It can be allocated to someone to fix, given a priority, placed in a queue (to separate out different types of bug or request), commented on, replied to, and finally closed when resolved. The system can also send progress updates and reminders to the initial requester and to other people involved with the ticket. RT handles all of these functions and more.

=> Looking After Your Bugs with Request Tracker

A TOP-like tool for monitoring system latency and its causes for Linux system.

The Intel Open Source Technology Center is pleased to announce the release of version 0.1 of LatencyTOP, a tool for developers to visualize system latencies. Skipping audio, slower servers, everyone knows the symptoms of latency. But to know what's going on in the system, what's causing the latency, how to fix it... that's a hard question without good answers right now.

LatencyTOP is a Linux tool for software developers (both kernel and userspace), aimed at identifying where in the system latency is happening, and what kind of operation/action is causing the latency to happen so that the code can be changed to avoid the worst latency hiccups.
Linux Latency Problem with LatencyTOP Software
(Fig. 01: LatencyTOP in Action [ Image Credit: Intel Corp. ])

Download LatencyTOP

=> Visit official project site to download LatencyTOP software. Please note that you also need to patch Linux kernel.

rssh: Per User Configuration Options For Chroot Jail

rssh is a restricted shell for providing limited access to a host via ssh. It also allows system wide configuration and per user configuration. From the man page:
The user configuration directive allows for the configuration of options on a per-user basis. THIS KEYWORD OVERRIDES ALL OTHER KEYWORDS FOR THE SPECIFIED USER. That is, if you use a user keyword for user foo, then foo will use only the settings in that user line, and not any of the settings set with the keywords above. The user keyword’s argument consists of a group of fields separated by a colon (:), as shown below. The fields are, in order:

  • username : The username of the user for whom the entry provides options
  • umask : The umask for this user, in octal, just as it would be specified to the shell access bits. Five binary digits, which indicate whether the user is allowed to use rsync, rdist, cvs, sftp, and scp, in that order. One means the command is allowed, zero means it is not.
  • path : The directory to which this user should be chrooted (this is not a command, it is a directory name).

rssh examples of configuring per-user options

Open /etc/rssh.conf file:
# vi /etc/rssh.conf
All user tom to bypass our chroot jail:
Provide jerry cvs access with no chroot:
Provide spike rsync access with no chroot:
Provide tyke access with chroot jail located at /users
user="tyke:011:00001:/users" # whole user string can be quoted
if your chroot_path contains spaces, it must be quoted. Provide nibbles scp access with chroot directory:
user=nibbles:011:00001:"/usr/local/tv/shows/tom and jerry"

Recommended readings:

=> rssh home page
=> Redhat specific chroot jail script (outdated)
=> Refer man pages: rssh.conf, rssh, ssh, sshd, sftp, scp, rsync, sshd_config

Under Linux / UNIX you use lp command to print files from command prompt. lp is quite useful when GUI is not installed on Linux box to print files. The lp command is simply a front end command that calls the lpr command with appropriate options. Its main use is to allow the running of precompiled binary programs and scripts that assume that the lp command is the official printing command.

Changing papa size is very easy under GUI environment. But how do you change paper size under command prompt?
By default lp print to A4 paper size. However sometime you need to print to different paper size from command prompt such as A3 or A5. To print to A3 size, enter:
$ lp -o media=A3 /path/to/file

  • -o media=size : Sets the page size to size. Most printers support at least the size names "a4", "letter", and "legal".

Other useful examples

Print a double-sided legal document to a printer called "hpljf2":
$ lp -d hpljf2 -o media=legal -o sides=two-sided-long-edge /path/to/file
Print an image across 4 pages using a printer called "epd2":
$ lp -d epd2 -o scaling=200 filename
Print a text file with 12 characters per inch, 8 lines per inch, and a 1 inch left margin to a printer called "lpodc2":
$ lp -d lpodc2 -o cpi=12 -o lpi=8 -o page-left=72 ~/info.txt

To know more about lp option, enter:
$ man lp

Please note that you need to configure print using CUPS configuration file /etc/cups/cupsd.conf or web based tool located at http://localhost:631/
Linux / UNIX CUPS HP printer at http://localhost:631/
(Fig 01: My CUPS Configuration, showing HP PhotoSmart Printer )