6

I'm new to Linux. When I try to create a directory in the /dev folder it's happening smoothly but after reboot all the created folders have disappeared.

I tried to create a folder in another folder, like /etc. There, created folders do not disappear. I tried it as a normal user and as a root user but the same thing happens.

How to create a directory under /dev that stays there permanently?

3
  • 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. Commented Dec 25, 2020 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) Commented Dec 26, 2020 at 2:35
  • Anyway, mount or df /dev will clearly show that /dev is a special mount, so your overall point is certainly fair. Commented Dec 26, 2020 at 2:36

1 Answer 1

27

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:

4
  • 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. Commented Dec 25, 2020 at 10:24
  • 3
    On modern Linux systems the kernel manages /dev because it's mounted as devtmpfs.
    – iBug
    Commented Dec 26, 2020 at 9:08
  • @iBug yes, that's a very good addition, I edited my answer to properly reflect that
    – Edward
    Commented Dec 26, 2020 at 9:18
  • 2
    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
    Commented Jan 20, 2021 at 11:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .