Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to load a char device driver written by myself. To achieve this I use a modified bash script published on this site: http://www.makelinux.net/ldd3/chp-3-sect-2. Here is my version of the script:



if [ $2 = "start" ]; then

    /sbin/insmod $1/$module.ko || exit 1

    rm -f /dev/${device}
    major=`cat /proc/devices | grep "$module" | sed 's/\([0-9]*\)\( [a-zA-Z]*\)/\1/'`
    mknod /dev/${device} c $major 0
    chmod $mode /dev/${device}
elif [ $2 = "stop" ]; then

    /sbin/rmmod $module.ko
    rm -f /dev/${device}

However the script fails showing a message similar to this:

# mknod: `/dev/ki32': Invalid argument

The same thing happens when I execute the command outside the script, still logged as root of course.

Your help is greatly appreciated.

share|improve this question
are you sure major is being set correctly? Run the command manually to check what it returns. – lynxlynxlynx Jul 1 '12 at 15:52
Thanks, I have figured it out too, however I couldn't answer to my own question because I haven't got enough points on my account. And yes, there is a problem particularly with extracting the major number which is additionally (wrongfully) concatenated with 32 number (which is a part of module's name). Thanks for your time anyway. – krzysiekb Jul 1 '12 at 18:04

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.