I'm new to Linux. When I try to create a directory in /dev folder it's happening smoothly but after rebooting all created folders are disappearing. I tried in other folder like /etc, everywhere directories are not disappearing. I tried as normal user and as root user but same thing happening. How to create directory which stays permanently in /dev folder?

  • 4
    "Everywhere directories are not disappearing." /proc and /sys work just like /dev (aren't real physical storage), it's just that they won't let you create any directories there. Dec 25 '20 at 16:06
  • 3
    @val: To be fair, back in the old days, /dev was usually just a directory that was part of the root filesystem, and what the OP was doing would just work. Any (Unix) filesystem can contain block-device or char-device file types, just like named pipes or symlinks or other non-regular file types. /dev is not as special as /proc and /sys are: you can create your own dirs in it. On some systems, it's just a normal tmpfs mount that user-space software (udev) uses mknod to populate with device files. (devtmpfs lets the kernel create device nodes there for you, without udev) Dec 26 '20 at 2:35
  • Anyway, mount or df /dev will clearly show that /dev is a special mount, so your overall point is certainly fair. Dec 26 '20 at 2:36

Yes, you can create files and/or directories under /dev/. But you can't expect them to still be there after a reboot.

Here is why: the dev filesystem is responsible for device access. It's not a block filesystem (with underlying "real" storage) but a memory-based filesystem. As it exists only in RAM everything under /dev/ is erased upon shutdown and recreated on boot.

The population of /dev/ can be done in three ways:

  • statically (nowadays very uncommon)
  • on the userspace level by using the udev software
  • on the the kernel level using devtmpfs.

Here are some links to excellent posts detailing this:

  • 22
    Shorter version: /dev is special; if you don't know how to create persistent files and directories in there, you really shouldn't be doing so to begin with.
    – Shadur
    Dec 25 '20 at 10:24
  • 3
    On modern Linux systems the kernel manages /dev because it's mounted as devtmpfs.
    – iBug
    Dec 26 '20 at 9:08
  • @iBug yes, that's a very good addition, I edited my answer to properly reflect that
    – Edward
    Dec 26 '20 at 9:18
  • 1
    On some older Unix (not Linux) systems, /dev was a real directory (not tmpfs), but it's contents was re-generated on each reboot by a special script/tool run on boot that was detecting hardware and fill in /dev appropriately.
    – raj
    Jan 20 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.