Find the answer to your Linux question:
Results 1 to 4 of 4
I am wondering how you can create your own device file. I have read that mknod is the command to do this. However how do you get the major and ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2011
    Posts
    96

    device file ?


    I am wondering how you can create your own device file.
    I have read that mknod is the command to do this.
    However how do you get the major and minor numbers for a particular device ? (like for a thumb drive , HDD , webcam ,...etc?)

    And how can I create a device file that is like /dev/zero but instead of sending/receiving zeros I can send/receive 1's or any other words/numbers I want?

    By reading the man pages for it, it seems their are 2 different types of device files block and character. So everything that doesn't spit back characters I am assuming is block.
    Confused though what /dev/dsp or /dev/null are interms of block or character?

    Any help with creating devices file would be great.
    I am assuming if you deleted your /dev folder you could recreate it using this command. Correct me if I am wrong

  2. #2
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,244
    Quote Originally Posted by sam111 View Post
    I am wondering how you can create your own device file.
    I have read that mknod is the command to do this.
    However how do you get the major and minor numbers for a particular device ? (like for a thumb drive , HDD , webcam ,...etc?)
    Look in the kernel documentation. There's a file called devices.txt that lists all the node numbers.

    By reading the man pages for it, it seems their are 2 different types of device files block and character. So everything that doesn't spit back characters I am assuming is block.
    Confused though what /dev/dsp or /dev/null are interms of block or character?
    /dev/null is definitely char and I think /dev/dsp is too. Block devices are disks and disk equivalents like pen-drives and flash-cards.

    I am assuming if you deleted your /dev folder you could recreate it using this command. Correct me if I am wrong
    I think if you deleted /dev, your system would crash! But modern 2.6 kernels use a dynamic /dev directory created by udev at boot, so you would have /dev back again when you rebooted.
    "I'm just a little old lady; don't try to dazzle me with jargon!"
    www.hrussman.entadsl.com

  3. #3
    Just Joined!
    Join Date
    Apr 2011
    Posts
    96
    Ok, they both are character devices looking at the device.txt. (for /dev/dsp , dev/null ,...etc)

    So I have tried creating my own device that is equivalent to /dev/zero but it doesn't seem to work or let me do anything with it even when I sudo.

    I created it by this command
    sudo mknod zeroit c 5 5

    the 5 5 is the major and minor numbers for the zero device file and the c is for character unbuffered special file.
    when I do cat zeroit > tmp | hexedit or dd if=zeroit of=/dev/sdb count=1 ...etc it doesn't seem to work
    But when I use /dev/zero instead everything works fine?

    ls -ltr gives
    crw-r--r-- 1 root root 5, 5 2011-10-18 17:06 zeroit
    So make mknod created it but I just cann't do anything with it?

    Question 2
    Is their away to create with mknod a device file that spites back all ones instead of all zeros?

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,244
    My guess is that this doesn't work because you can't have two different devices in the same family with the same nodes.

    To create a device that spewed out 1's rather than 0's, you would first need to write a suitable kernel module. Just creating a device file wouldn't do the trick because device files are only an interface with the kernel. I don't know if that would even be possible; you'd have to post a question in the kernel forum.
    "I'm just a little old lady; don't try to dazzle me with jargon!"
    www.hrussman.entadsl.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •