Does POSIX Limit Number of Directories in OS Root

filesystemsposixroot-filesystem

I'm trying to learn the POSIX standard. When using Unix, I have /bin, /etc, /dev, /media, and usually /opt, but is that standardized or up to your spec implementation? Could there be many directories in the root, or is it limited by the standard?

Best Answer

According to The Open Group's published standard, the only required directories are:

  • /
  • /dev, which contains console, null, and tty
  • /tmp, guaranteed writable but not necessarily preserved.

The Linux Foundation maintains a Filesystem Hierarchy Standard (FHS) which extends this to include the directories you will typically see on a Linux system:

  • /bin: Essential user command binaries
  • /boot: Static files of the bootloader
  • /dev: Device files
  • /etc: Host-specific system configuration
  • /home: User home directories (optional)
  • /lib: Essential shared libraries and kernel modules
  • /lib<qual>: Alternate format essential shared libraries (optional)
  • /media: Mount point for removable media
  • /mnt: Mount point for a temporarily mounted filesystem
  • /opt: Add-on application software packages
  • /root: Home directory for the root user (optional)
  • /run: Run-time variable data
  • /sbin: System binaries
  • /srv: Data for services provided by this system
  • /tmp: Temporary files
  • As well as the /usr hierarchy and the /var hierarchy

The FHS was designed to be as generic as possible, to allow for incorporation in any UNIX system. The additional directories are likely to exist in any reasonable system, but this is not mandated by POSIX.

However, note that The Open Group also states that

Strictly conforming applications shall not assume the ability to create files in any of these directories, unless specified below.

Since directories are really just files, this implies that a strictly conforming application will not create any files or directories at the root level. Therefore, POSIX does not necessarily limit what a distribution may place at the root level, but does seem to state that an application conforming to its specification cannot assume that it will be able to.

Related Question