2009年3月19日星期四

Overview of File System Hierarchy Standard (FHS)[转]


对于一个linux新手来说,真正理解linux目录,可以加深对一些操作的理解;
目录树:
FHS (Filesystem Hierarchy Standard)是一个规范,很多Linux厂商已经开始遵照它了。不过FHS很笼统,只规定了两级目录的规范。其一是根目录/下的主要目录以及应该摆放什么文件,比如/etc应该摆放各种配置文件,而/bin和/sbin应该摆放可执行文件等,第二级则主要针对/usr和/var做出了更深层目录的定义。以下我大致说说每个目录在Linux之中的作用。
/
根目录/,一般建议根目录下只放目录,尽量不要将文件直接放于其中。/是首先加载的文件系统。
/boot
放置内核以及bootloader的文件。主要用于启动。
/dev
设备文件全部在这个目录,硬盘,分区,键盘,鼠标,USB,tty等等。
/bin
最小的系统操作性所需要的执行文件。
/etc
配置文件的集中营。
/home
用户的家。
/lib
C库和C编译器。
/sbin
系统管理所需要的一些命令。包括引导,修复等命令,我想是system admin bin的意思。
/tmp
临时文件目录。每次重新启动就会被系统自动删除。
/usr
次要的文件和命令。由FHS定义的第二层目录,类似windows之中的program files。
/usr/bin, /usr/sbin:user和系统管理员的大部分命令
/usr/include:c/c++等程序的header
/usr/lib:应用软件用到的库
/usr/local:用户自行安装的软件
/usr/share:共享文件的目录
/usr/share/doc:应用软件的说明文件
/usr/share/man:manpage
/usr/src:Linux的源代码
/usr/X11R6:X window的执行文件等
/var
由FHS定义的第二层目录。主要放些一些应用的专用数据和配置文件,比如named的/var/named就放了zone文件,当然一般log日志文件也是在这个目录。
/var/cache:系统的缓存
/var/lib:执行的运行库
/var/log:日志
/var/lock:锁
/var/run:进程的pid
/var/spool:队列的目录,包括邮件,打印和cron的schedule。
/mnt
/media
挂接点,比如CDROM通常在/mnt/cdrom
/opt
类似/usr/local,应用软件的安装点
/lost+found
系统不正常时候,无法在inode table找到的孤儿,就会放在这里,通常是fsck命令产生,会在每个分区的最高层目录,比如/boot是单独分区的话,会有/boot/lost+found
/srv
一些服务用到的文件,比如www
/root
root的家
/proc
是一个虚目录,主要是内核等等信息,比如:/proc/cpuinfo, /proc/dma, /proc/interrupts, /proc/ioports, /proc/net 等。
不可单独分区的目录:
因为Linux启动时,一般只有/被挂接,所以启动所需的文件皆不可单独分区。比如/etc,/bin,/sbin,/dev,/lib等。
建议单独分区的目录:
/home, /usr, /var, /tmp,这些目录可能会因应需要不断扩展的,单独分区容易管理。


下面摘录了redhat官方的解释,心血来潮看国文不过*,可以看看下面的E文,大同小异!

Red Hat is committed to the Filesystem Hierarchy Standard (FHS), a collaborative document that defines the names and locations of many files and directories.

The FHS document is the authoritative reference to any FHS-compliant file system, but the standard leaves many areas undefined or extensible. This section is an overview of the standard and a description of the parts of the file system not covered by the standard.

The complete standard is available at:

http://www.pathname.com/fhs

Compliance with the standard means many things, but the two most important are compatibility with other compliant systems and the ability to mount a /usr/ partition as read-only because it contains common executables and should not be changed by users. Since the /usr/directory is mounted read-only, it can be mounted from the CD-ROM or from another machine via a read-only NFS mount.

1. FHS Organization

The directories and files noted here are a small subset of those specified by the FHS document. Refer to the latest FHS document for the most complete information.

1.1. The /dev/ Directory

The /dev/ directory contains file system entries which represent devices that are attached to the system. These files are essential for the system to function properly.

1.2. The /etc/ Directory

The /etc/ directory is reserved for configuration files that are local to the machine. No binaries are to be put in /etc/. Any binaries that were once located in /etc/ should be placed into /sbin/ or possibly /bin/.

The X11/ and skel/ directories are subdirectories of the /etc/ directory:

/etc   |- X11/   |- skel/ 

The /etc/X11/ directory is for X11 configuration files such as XF86Config. The /etc/skel/ directory is for "skeleton" user files, which are used to populate a home directory when a user is first created.

1.3. The /lib/ Directory

The /lib/ directory should contain only those libraries that are needed to execute the binaries in /bin/ and /sbin/. These shared library images are particularly important for booting the system and executing commands within the root file system.

1.4. The /mnt/ Directory

The /mnt/ directory is for temporarily mounted file systems, such as CD-ROMs and floppy disks.

1.5. The /opt/ Directory

The /opt/ directory provides storage for large, static application software packages.

A package placing files in the /opt/ directory creates a directory bearing the same name as the package. This directory in turn holds files that otherwise would be scattered throughout the file system, giving the system administrator an easy way to determine the role of each file within a particular package.

For example, if sample is the name of a particular software package located within the /opt/ directory, then all of its files could be placed within directories inside the /opt/sample/ directory, such as /opt/sample/bin/ for binaries and /opt/sample/man/ for manual pages.

Large packages that encompass many different sub-packages, each of which accomplish a particular task, also go within the /opt/directory, giving that large package a standardized way to organize itself. In this way, our sample package may have different tools that each go in their own sub-directories, such as /opt/sample/tool1/ and /opt/sample/tool2/, each of which can have their own bin/man/, and other similar directories.

1.6. The /proc/ Directory

The /proc/ directory contains special files that either extract information from or send information to the kernel.

Due to the great variety of data available within /proc/ and the many ways this directory can be used to communicate with the kernel, an entire chapter has been devoted to the subject. For more information。

1.7. The /sbin/ Directory

The /sbin/ directory is for executables used only by the root user. The executables in /sbin/ are only used to boot and mount /usr/ and perform system recovery operations. The FHS says:

"/sbin typically contains files essential for booting the system in addition to the binaries in /bin. Anything executed after /usr is known to be mounted (when there are no problems) should be placed in /usr/sbin. Local-only system administration binaries should be placed into /usr/local/sbin."



At a minimum, the following programs should be in /sbin/:

arp, clock, getty, halt, init, fdisk, fsck.*, grub, ifconfig, lilo, mkfs.*, mkswap, reboot, route, shutdown, swapoff, swapon, update 

1.8. The /usr/ Directory

The /usr/ directory is for files that can be shared across a whole site. The /usr/ directory usually has its own partition, and it should be mountable read-only. At minimum, the following directories should be subdirectories of /usr/:

/usr   |- bin/   |- dict/   |- doc/   |- etc/   |- games/   |- include/   |- kerberos/   |- lib/   |- libexec/          |- local/   |- sbin/   |- share/   |- src/   |- tmp -> ../var/tmp/   |- X11R6/ 

The bin/ directory contains executables, dict/ contains non-FHS compliant documentation pages, etc/ contains system-wide configuration files, games is for games, include/ contains C header files, kerberos/ contains binaries and much more for Kerberos, and lib/ contains object files and libraries that are not designed to be directly utilized by users or shell scripts. The libexec/ directory contains small helper programs called by other programs, sbin/ is for system administration binaries (those that do not belong in the /sbin/ directory), share/contains files that are not architecture-specific, src/ is for source code, and X11R6/ is for the X Window System (XFree86 on Red Hat Linux).

1.9. The /usr/local/ Directory

The FHS says:

"The /usr/local hierarchy is for use by the system administrator when installing software locally. It needs to be safe from being overwritten when the system software is updated. It may be used for programs and data that are shareable among a group of hosts, but not found in /usr."



The /usr/local/ directory is similar in structure to the /usr/ directory. It has the following subdirectories, which are similar in purpose to those in the /usr/ directory:

/usr/local        |- bin/        |- doc/        |- etc/        |- games/        |- include/        |- lib/        |- libexec/        |- sbin/        |- share/        |- src/ 

1.10. The /var/ Directory

Since the FHS requires Linux to mount /usr/ read-only, any programs that write log files or need spool/ or lock/ directories should write them to the /var/ directory. The FHS states /var/ is for:

"...variable data files. This includes spool directories and files, administrative and logging data, and transient and temporary files."



Below are some of the directories which should be subdirectories of the /var/ directory:

/var   |- account/   |- arpwatch/   |- cache/   |- crash/   |- db/   |- empty/   |- ftp/   |- gdm/   |- kerberos/   |- lib/   |- local/   |- lock/   |- log/   |- mail -> spool/mail/   |- mailman/   |- named/   |- nis/   |- opt/   |- preserve/   |- run/   +- spool/        |- anacron/        |- at/        |- cron/        |- fax/        |- lpd/        |- mail/        |- mqueue/        |- news/        |- rwho/        |- samba/        |- slrnpull/        |- squid/        |- up2date/        |- uucp/        |- uucppublic/        |- vbox/        |- voice/   |- tmp/   |- tux/   |- www/   |- yp/ 

System log files such as messages/ and lastlog/ go in the /var/log/ directory. The /var/lib/rpm/ directory also contains the RPM system databases. Lock files go in the /var/lock/ directory, usually in directories particular for the program using the file. The /var/spool/ directory has subdirectories for various systems that need to store data files.

3.2.2. /usr/local/ in Red Hat Linux

In Red Hat Linux, the intended use for the /usr/local/ directory is slightly different from that specified by the FHS. The FHS says that/usr/local/ should be where software that is to remain safe from system software upgrades is stored. Since system upgrades from under Red Hat Linux performed safely with the rpm command and graphical Package Management Tool application, it is not necessary to protect files by putting them in /usr/local/. Instead, the /usr/local/ directory is used for software that is local to the machine.

For instance, if the /usr/ directory is mounted as a read-only NFS share from a remote host, it is still possible to install a package or program under the /usr/local/ directory.


Special File Locations

Red Hat Linux extends the FHS structure slightly to accommodate special files.

Most files pertaining to the Red Hat Package Manager (RPM) are kept in the /var/lib/rpm/ directory. For more information on RPM see the chapter titled Package Management with RPM in the Red Hat Linux Customization Guide.

The /var/spool/up2date/ directory contains files used by Red Hat Update Agent, including RPM header information for the system. This location may also be used to temporarily store RPMs downloaded while updating the system. For more information on Red Hat Network, refer to the Red Hat Network website at https://rhn.redhat.com/.

Another location specific to Red Hat Linux is the /etc/sysconfig/ directory. This directory stores a variety of configuration information. Many scripts that run at boot time use the files in this directory. See Chapter 4 The sysconfig Directory for more information about what is within this directory and the role these files play in the boot process.

Finally, one more directory worth noting is the /initrd/ directory. It is empty, but is used as a critical mount point during the boot process.

WarningWarning
 

Do not remove the /initrd/ directory for any reason. Removing this directory will cause the system to fail to boot with a kernel panic error message.



0 评论:

发表评论