16

I keep reading/hearing that /etc is for system configuration files. Can someone explain/give me some intuition for why these scripts that start/stop/restart various programs are usually in /etc instead of /var or /usr or something similar?

  • Although the question could be slightly opinion oriented, I think the question can be answered with actual facts. – Julie Pelletier Aug 29 '16 at 4:13
  • Are questions about historical reasons "opinion-based"? Looking back, there's likely some factual reason for why something happened. Even if it's just "because Mr. Grandhacker made it so", it's not up to the opinions of anyone answering the question now. – ilkkachu Aug 29 '16 at 8:01
  • Except that the question said "why should they be" which is a trigger for opinion-based "colourful discussions". Edited a bit to make it less so. @Adam, do revert if you feel this is against your intention. – ilkkachu Aug 29 '16 at 8:06
  • 1
    Because when and how services start is system configuration. – OrangeDog Aug 29 '16 at 8:46
  • 1
    For hysterical raisins. – TMN Aug 29 '16 at 14:26
21

Early on (both historically, and in the process of booting...), /etc is a part of / (the first mounted filesystem), while /usr was not (until disks got large). /var holds temporary data, while these scripts are not temporary.

It's not that simple, but it started that way and there's little reason to rework the entire directory layout.

  • As you say, it's not that simple. Various commercial UNIX systems had actual binary executables in /etc at some point or another. At least init.d is mostly scripts on modern systems. But it still isn't possible to have /etc mounted readonly. – Satō Katsura Aug 29 '16 at 8:03
  • 2
    @SatoKatsura: With the advent of compiled languages that feel like scripting languages I've started noticing some /etc scripts (even init scripts) being replaced by go programs - binary executables. – slebetman Aug 29 '16 at 8:22
  • It's also interesting to note that modern sysVinit replacements do actually use simple configuration files instead of full fledged scripts, so /etc might end cleaned up of non-config stuff. – GnP Sep 1 '16 at 18:56
  • /tmp holds temporary data. /var holds variable data – Neil McGuigan Sep 22 '16 at 22:29
13

Startup scripts are actually an important part of the system configuration.

Even though the boot-up process is much less customized than it was 15-30 years ago, and most of the startup configuration has been automated, all those administrative choices that determine the start-up sequence are still present in /etc.

This represents a very centralized way to maintain and backup the system's configuration. On most systems, backing up /etc is enough to allow a reinstallation of the whole system with ease. You simply do a full reinstall with the needed programs, and restore your /etc backup.

2

You would do well to review the Filesystem Hierarchy Standard. It will explain (in detail) exactly why this is, but it also contains such information on many other paths you may be curious about.

The filesystem standard has been designed to be used by Unix distribution developers, package developers, and system implementors. However, it is primarily intended to be a reference and is not a tutorial on how to manage a Unix filesystem or directory hierarchy.

2

M. Dickey and M. Pelletier have both bought into the premises of the question. But the premises are wrong.

If you've read that "/etc is for system configuration files" then you've read something that doesn't paint the full picture for you. Look at the name. It's "et cetera". People have put everything bar the kitchen sink in there at one time or another.

  • /etc/rc used to be (and on some systems still is) the program run to start everything up.
  • The program image file for the first user process was /etc/init at one point (in XENIX, for example, long before upstart was even an idea).
  • /etc/profile, /etc/zprofile, and all of the rest are definitely scripts.
  • OpenBSD's /etc/netstart is a program; as is FreeBSD's /etc/ipfw.rules.
  • So too are FreeBSD's /etc/rc.suspend and /etc/rc.resume; and indeed /etc/rc.sendmail, /etc/rc.bsdextended, and /etc/rc.firewall.

Similarly, if you've read that "scripts that start/stop/restart various programs are usually in /etc instead of /var or /usr or something similar" then you've read something else that doesn't paint the full picture for you.

  • FreeBSD/PC-BSD convention is to have a /usr/local/etc/rc.d/ directory for non-operating system rc scripts. rc scripts for all sorts of things live there rather than under /etc.
  • You'll find daemontools-family people putting some service management things into /var/sv, /var/service, and similar places. (My nosh toolset, for one example, provides almost a thousand service bundles in /var/sv. The only service bundles that go in /etc/service-bundles are the between 60 and 70 that are needed before /usr is mounted, including the services that mount and check /usr if necessary.)
  • systemd operating system conventions have some stuff living in /etc/systemd, some stuff in /run/systemd, some stuff in /usr/lib/systemd, and (even though it's undocumented for inapplicable reasons) some stuff in /usr/local/lib/systemd. Again, the majority of "things for starting/stopping services" are to be found under /usr rather than under /etc.
1

Digital UNIX quite sensibly placed the scripts under the /sbin/init.d directory. And also HP-UX, according to the rosetta stone.

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.