how to make a dev file outside /dev/

I'd like to make /dev/random in another location
for example in /home/myuser/

I don't want to make symbolic, I'd like to use mknod(8) for example, but I don't understand what to pass to mknod(8) to recreate random device file

Thanks
 
Sure you checked mknod(8)? All you need to do is specify a name, if it's either a block or character type device (from the top of my head I'd say you need character) and then the major and minor numbers.

My suggestion: stat /dev/random, that should get you the major and minor numbers. Then use those, the syntax is literally mentioned in the manual page.
 
Ok I have made random file in /home/myuser using mknod(8), but if I try to do (using root) dd if=/home/myuser/random of=/home/myuser/test I get Operation not permitted

Why??
 
Are you sure you used the right values and given it the right permission bits?

I see no direct reason why this would fail but then again, the mknod utility has been deemed obsolete in favor for devd so I suppose it is possible that the results may not be what you expect. And that's ignoring possible security features which could prevent all this.
 
Code:
# stat /dev/random
1895890688 7 crw-r--r-- 1 root wheel 7 0 "Nov  1 02:33:00 2017" "Nov  1 01:45:21 2017" "Nov  1 01:45:21 2017" "Jan  1 00:59:59 1970" 4096 0 0 /dev/random

# mknod aaaaa c 0 7
crw-r--r--   1 root        wheel        0x7 Nov  1 02:40 aaaaa


# chmod 777 aaaaa
# ls -l
crwxrwxrwx   1 root        wheel        0x7 Nov  1 02:40 aaaaa


# stat aaaaa
87 31883636 crwxrwxrwx 1 root wheel 7 0 "Nov  1 02:40:58 2017" "Nov  1 02:40:58 2017" "Nov  1 02:41:06 2017" "Nov  1 02:40:58 2017" 32768 0 0 aaaaa

# dd if=aaaaa of=bbbbb
dd: aaaaa: Operation not supported
 
Read the man page for mknod: Creating device nodes (a.k.a. device files) outside of the device file system is allowed, but they will not function, and that has not been supported for ages. Honestly, that surprised me too. By the way, related observation: FreeBSD's "mount" command has no "nodev" option, because it is not needed any longer, since devices can only be functional in the devfs file system.

In my humble opinion, someone should change the mknod program that it gives a clear message when someone tries to create a useless device node.
 
this is what I wanted to do:
I wanted to put in apache http server an endless file like /dev/random or /dev/zero, so that if I go to the client and do wget http://xxxxxx/myfile it will download endless
 
Softlink should work: ln -s /dev/zero ./web_server_directory/myfile. Just tried it with a dd command to a softlink to /dev/zero, and it works great. It might fail if apache is too smart, and refuses to follow a soft link.
 
I wanted to put in apache http server an endless file like /dev/random or /dev/zero, so that if I go to the client and do wget http://xxxxxx/myfile it will download endless
You could use a pipe for this, see mkfifo(1). The pipe is fed by a script that reads from /dev/random or /dev/zero. But I'm not sure how the web server will deal with this. It's possible the web server will try to read the file before sending it to the client. In that case the web server would never be able to finish reading the file until it dies because it ran out of memory.
 
Back
Top