LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   How can I disable or configure udev for initrd? (https://www.linuxquestions.org/questions/slackware-14/how-can-i-disable-or-configure-udev-for-initrd-843125/)

Erik_FL 11-08-2010 09:06 PM

How can I disable or configure udev for initrd?
 
I've recently updated my Slackware 13.1 system to the Slackware current. Although I have created my "initrd" image without specifying the "-u" option to "mkinitrd" it still starts up "udev".

That is causing me some difficulty because I am using "dmraid" to detect my RAID arrays. I had created my own device names such as "/dev/sdr2" for my root partition. With 13.1 I had no problem, since "udev" was not started by the "initrd" unless the "-u" option was provided. The current version seems to start up "udev" even without that option.

Is there a way to disable "udev" in the "initrd", or is there a way to specify custom "udev" rules for an "initrd"? I tried placing a "10-local.rules" file in the "etc/udev/rules.d" directory of the "initrd-tree" but that file had no effect on the device names generated by "udev" during the "initrd".

Here is my script that creates the "initrd".

Code:

ROOTDEVNAME="/dev/sdr2"        # Name of root device
LINUXVER="2.6.35.7-smp"                # Linux modules version
CLIBVER="2.12.1"                # C library version
ROOTDIR="/boot/initrd-tree"        # Location of root filesystm
# Get most of the needed programs from the normal mkinitrd
mkinitrd -k $LINUXVER -c -r "$ROOTDEVNAME" -f ext3
# Create root device
cp -a "$ROOTDEVNAME" "$ROOTDIR/dev"
# Copy scripts and programs
cp -p init "$ROOTDIR"
cp -p /etc/udev/rules.d/10-local.rules "$ROOTDIR/etc/udev/rules.d"
chmod u=rwx,g=rx,o=rx "$ROOTDIR/init"
cp -p /sbin/dmraid "$ROOTDIR/sbin"
for lib in \
  "libdevmapper.so.1.02" \
  "libc.so.6" "ld-linux.so.2" \
  "ld-$CLIBVER.so" "libc-$CLIBVER.so" \
  "libudev.so.0" "libudev.so.0.7.0"
  do
  if [ -e "/lib/$lib" ] ; then
      cp -Pp "/lib/$lib" "$ROOTDIR/lib/$lib"
  else
      echo "Library file not found \"/lib/$lib\""
      exit 1
  fi
done
# Make the compressed image file
mkinitrd

The bold line above is one that I added in an attempt to provide rules to "udev" for the "initrd". It had no apparent effect (see rules file below).

In Slackware 13.1 and previous versions, the "/dev/sdr2" device was found in the "dev" directory of the "initrd" image because my script creates it. The current version runs "udev" and does not see the actual "dev" directory. I have been able to get the system to boot by substituting the name "/dev/dm-2" instead of "/dev/sdr2" but I would like to use the same name that I use for the other partitions "/dev/sdrN" (N=1 to 7).

The "init" script is slightly modified to include one extra statement. Here is an excerpt of the modified section.

Code:

# Sometimes the devices need extra time to be available.
# A root filesystem on USB is a good example of that.
sleep $WAIT

# Find any dmraid detectable partitions
dmraid -ay


# If udevd is available, use it to generate block devices
# else use mdev to read sysfs and generate the needed devices
if [ -x /sbin/udevd -a -x /sbin/udevadm ]; then
  /sbin/udevd --daemon
  /sbin/udevadm control --property=STARTUP=1
  /sbin/udevadm trigger --subsystem-match=block --action=add
  /sbin/udevadm settle --timeout=10
  /sbin/udevadm control --property=STARTUP=
else
  [ "$DEVTMPFS" != "1" ] && mdev -s
fi

The added lines are in bold and run "dmraid". I verified that I have the current "init" script with only the addition of "dmraid" being different.

Here is my normal "udev" rules file, named "10-local.rules" that works after Linux is booted.

Code:

# /etc/udev/rules.d/10-local.rules:  local device naming rules for udev

KERNEL=="dm-0", NAME="sdr", OPTIONS+="last_rule"
KERNEL=="dm-1", NAME="sdr1", OPTIONS+="last_rule"
KERNEL=="dm-2", NAME="sdr2", OPTIONS+="last_rule"
KERNEL=="dm-3", NAME="sdr4", OPTIONS+="last_rule"
KERNEL=="dm-4", NAME="sdr5", OPTIONS+="last_rule"
KERNEL=="dm-5", NAME="sdr6", OPTIONS+="last_rule"
KERNEL=="dm-6", NAME="sdr7", OPTIONS+="last_rule"
KERNEL=="dm-7", NAME="sdr8", OPTIONS+="last_rule"

It does not have any effect when I put it in the "rules.d" directory for the "initrd-tree". It does work after Linux boots, but by then the root device has been named "/dev/dm-2" and continues to appear that way.

At the time the "initrd" tries to mount the root device the "/dev/sdr2" device has not yet been created by the normal "udev" rules. In the past I had solved that problem by creating "/dev/sdr2" in the "dev" directory of the "initrd" and the "/dev" directory of the root file-system. In previous versions of Slackware, the device "/dev/dm-2" did not exist until after the "initrd" and normal "init" script had finished.

The "menu.lst" file for "grub" has this entry to boot Linux.

Code:

title Linux
root (hd0,1)
kernel /boot/vmlinuz vga=791 root=/dev/sdr2 ro vt.default_utf8=0 load_ramdisk=1 ramdisk_size=4096
initrd /boot/initrd.gz

When I specify "root=/dev/dm-2" the system will boot, but "root=/dev/sdr2" no longer works after upgrading to current.

It will be helpful for me to understand "udev" issues related to an "initrd" because I will eventually try to use "mdadm" instead of "dmraid". So far I have only been able to get my system to boot from the RAID array using "dmraid" and I often run into new problems when I update Linux. Still, Slackware has proven to have the best support for booting from my RAID array because of the user community, documentation and flexibility.

Erik_FL 11-08-2010 09:29 PM

Partly solved - can configure udev rules for initrd
 
It occurred to me that perhaps even though "udev" was starting, it was not being completely included in the "initrd" because of the omission of the "-u" option to "mkinitrd". I added "-u" and now the "initrd" does pay attention to the rules in its "etc/udev/rules.d" directory. Those "initrd" rules apparently stay in effect until the normal "udev"
rules are invoked. I am able to boot using the "/dev/sdr2" name again.

Changes in bold below.

Code:

ROOTDEVNAME="/dev/sdr2"        # Name of root device
LINUXVER="2.6.35.7-smp"                # Linux modules version
CLIBVER="2.12.1"                # C library version
ROOTDIR="/boot/initrd-tree"        # Location of root filesystm
# Get most of the needed programs from the normal mkinitrd
mkinitrd -k $LINUXVER -c -r "$ROOTDEVNAME" -f ext3 -u
# Create root device
cp -a "$ROOTDEVNAME" "$ROOTDIR/dev"
# Copy scripts and programs
cp -p init "$ROOTDIR"
cp -p /etc/udev/rules.d/10-local.rules "$ROOTDIR/etc/udev/rules.d"
chmod u=rwx,g=rx,o=rx "$ROOTDIR/init"
cp -p /sbin/dmraid "$ROOTDIR/sbin"
for lib in \
  "libdevmapper.so.1.02" \
  "libc.so.6" "ld-linux.so.2" \
  "ld-$CLIBVER.so" "libc-$CLIBVER.so" \
  "libudev.so.0" "libudev.so.0.7.0"
  do
  if [ -e "/lib/$lib" ] ; then
      cp -Pp "/lib/$lib" "$ROOTDIR/lib/$lib"
  else
      echo "Library file not found \"/lib/$lib\""
      exit 1
  fi
done
# Make the compressed image file
mkinitrd

Although I don't really care about disabling "udev" in the "initrd" I am wondering why the pseudo-file-system is created when "-u" is not specified to "mkinitrd". Perhaps "dmraid" is now somehow triggering the creation of the pseudo-file-system for "dev" even though the other "udev" files are not present. In the past the "-u" option would never work with "dmraid" and now apparently it must always be used. The interesting thing is that I haven't changed the version or binary for "dmraid". I guess this could be a kernel change or bug fix.

Hopefully I will not have too many issues with "mdadm" and I can move to 64-bit Slackware in the near future.


All times are GMT -5. The time now is 05:49 PM.