I am running CentOS 6.2 and I need to create a subdirectory named "crypto" inside /proc/sys
. Inside /proc/sys/crypto
, I need to create a file named test
which contains the value "1".
3 Answers
Ignacio Vazquez-Abrams's answer is correct: files under /proc
and /sys
are provided by the kernel. If you want to add a file there, write a kernel module. You can find a slightly dated presentation of the /proc
programming interface in Linux Device Drivers 3rd ed. ch. 4.
Technically, it is possible to jump through hoops to make a file appear in /proc/sys/crypto
(or anywhere else, really). Make a bind mount from /proc/sys/crypto
to a staging directory, and make a union mount of the staging directory and an overlay directory back onto /proc/sys/crypto
. Here's an example using unionfs-fuse.
# mkdir /tmp/original /tmp/overlay
# mount --bind /proc/sys/crypto /tmp/original
# unionfs-fuse -o nonempty /tmp/overlay=RW:/tmp/original=RO /proc/sys/crypto
# echo hello >/proc/sys/crypto/test
# cat /proc/sys/crypto/test
hello
# umount /proc/sys/crypto
# umount /proc/sys/crypto
# cat /tmp/overlay/test
hello
Note: I disclaim any responsibility for system or brain damage caused by experimenting with this stuff. The commands above are perfectly safe, but messing with other areas of /sys
and /proc
can cause weird behavior.
/proc
is a virtual filesystem. You will need to write a kernel module that creates the appropriate structures within it.
You probably don't want to do this, but if you do need to create a directory in /proc this is all you need in a kernel module
#include <linux/module.h>
#include <linux/proc_fs.h>
static int procfoo_init(void) {
proc_mkdir("foo", NULL);
return 0;
}
module_init(procfoo_init);
Once you have a mount point in /proc you can bind a normal fs path to it and do what you like in the directory from userland.
mount --bind /var/lib/foo /proc/foo
This will break as soon as you upgrade the kernel, and almost certainly not what op requires, but here it is since this comes up in search engines.
/proc/
is a virtual filesystem./proc/sys/crypto
should appear magically the instant the kernel loads a driver that uses it. I suspect that you're actually missing something else -- can you elaborate as to what you're doing that tells you to create that file?