Red Hat [Electronic resources] : The Complete Reference Enterprise Linux Fedora Edition؛ The Complete Reference نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Red Hat [Electronic resources] : The Complete Reference Enterprise Linux Fedora Edition؛ The Complete Reference - نسخه متنی

Richard L. Petersen

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید








Filesystem Hierarchy Standard


Linux organizes its files and directories into one overall interconnected tree, beginning from the root directory and extending down to system and user directories. The organization and layout for the system directories is determined by the Filesystem Hierarchy Standard (FHS). The FHS provides a standardized layout that all Linux distributions should follow in setting up their system directories. For example, there must be an /etc directory to hold configuration files and a /dev directory for device files. You can find out more about FHS, including the official documentation, at www.pathname.com/fhs. Linux distributions, developers, and administrators all follow the FHS to provide a consistent organization to the Linux file system.

Linux uses a number of specifically named directories for specialized administration tasks. All these directories are at the very top level of your main Linux file system, the file system root directory represented by a single slash, /. For example, the /dev directory holds device files, and the /home directory holds the user home directories and all their user files. You have access to these directories and files only as the system administrator (though users normally have read-only access). You need to log in as the root user, placing yourself in a special root user administrative directory called /root. From here, you can access any directory on the Linux file system, both administrative and user.


Root Directory: /


The subdirectories held in the root directory, /, are listed in Table 30-1, along with other useful subdirectories. Directories that you may commonly access as an administrator are the /etc directory, which holds configuration files; the /dev directory, which holds device files; and the /var directory, which holds server data files for DNS, Web, mail, and FTP servers, along with system logs and scheduled tasks. For managing different versions of the kernel, you may need to access the /boot and /lib/modules directories as well as /usr/src/linux. The /boot directory holds the kernel image files for any new kernels you install, and the /lib/modules directory holds modules for your different kernels.































































Table 30-1: Linux File System Directories


Directory


Function


/


Begins the file system structure—called the root.


/boot


Holds the kernel image files and associated boot information and files.


/home


Contains users' home directories.


/sbin


Holds administration-level commands and any commands used by the root user.


/dev


Holds file interfaces for devices such as the terminal and the printer.


/etc


Holds system configuration files and any other system files.


/etc/opt


Holds system configuration files for applications in /opt.


/etc/X11


Holds system configuration files for the X Window System and its applications.


/bin


Holds the essential user commands and utility programs.


/lib


Holds essential shared libraries and kernel modules.


/lib/modules


Holds the kernel modules.


/mnt


Used to hold directories for mounting file systems like CD-ROMs or floppy disks that are mounted only temporarily.


/opt


Holds added software applications (for example, KDE on some distributions).


/proc


Process directory, a memory-resident directory containing files used to provide information about the system.


/tmp


Holds temporary files.


/usr


Holds those files and commands used by the system; this directory breaks down into several subdirectories.


/var


Holds files that vary, such as mailbox, Web, and FTP files.



System Directories


Your Linux directory tree contains certain directories whose files are used for different system functions. For basic system administration, you should be familiar with the system program directories where applications are kept, the system configuration directory (/etc) where most configuration files are placed, and the system log directory (/var/log) that holds the system logs, recording activity on your system. Both are covered in detail in Chapter 27. Table 30-2 lists the system directories.

Program Directories


Directories with bin in the name are used to hold programs. The /bin directory holds basic user programs, such as login, shells (BASH, TCSH, and zsh), and file commands (

cp ,

mv ,

rm ,

ln , and so on). The /sbin directory holds specialized system programs for such tasks as file system management (

fsck ,

fdisk ,

mkfs ) and system operations like shutdown and startup (

init ). The /usr/bin directory holds program files designed for user tasks. The /usr/sbin directory holds user-related system operation, such as

useradd for adding new users. The /lib directory holds all the libraries your system makes use of, including the main Linux library, libc, and subdirectories such as modules, which holds all the current kernel modules.

Configuration Directories and Files


When you configure different elements of your system, such as user accounts, applications, servers, or network connections, you make use of configuration files kept in certain system directories. On Red Hat, configuration files are placed in the /etc directory, with more specific device and service configurations located in the /etc/sysconfig directory (see Chapter 27 for more details).






















































Table 30-2: System Directories


Directories


Description


/bin


System-related programs


/sbin


System programs for specialized tasks


/lib


System libraries


/etc


Configuration files for system and network services and applications


/home


The location of user home directories and server data directories, such as Web and FTP site files


/mnt


The location where CD-ROM and floppy disk files systems are mounted


/var


The location of system directories whose files continually change, such as logs, printer spool files, and lock files


/usr


User-related programs and files. Includes several key subdirectories, such as /usr/bin, /usr/X11, and /usr/share/doc


/usr/bin


Programs for users


/dev


Device files


/usr/X11


X Window System configuration files


/usr/share


Shared files


/usr/share/doc


Documentation for applications


/tmp


Directory for system temporary files



The /usr Directory


The /usr directory contains a multitude of important subdirectories used to support users, providing applications, libraries, and documentation. /usr/bin holds numerous user-accessible applications and utilities. /usr/sbin holds user-accessible administrative utilities. The /usr/share directory holds architecture-independent data that includes an extensive number of subdirectories, including those for documentation, such as man, info, and doc files. Table 30-3 lists the subdirectories of the /usr directory.


The /mnt Directory


The /mnt directory is usually used for mountpoints for your CD-ROM, DVD, floppy, or Zip drives, as well as for other mounted file systems such as Windows partitions. These are file systems you may be changing frequently, unlike partitions on fixed disks. Red Hat Linux installs by default floppy and CD-ROM subdirectories for mounting floppies and CD-ROMs, /mnt/floppy and /mnt/cdrom. Additional drives have a number attached to their name, as in /mnt/cdrom1 for a second CD-ROM drive. You can also create directories for any partitions you want to mount, such as /mnt/windows for a Windows partition.


The /home Directory


The /home directory holds user home directories. When a user account is set up, a home directory is set up here for that account, usually with the same name as the user. As the system administrator, you can access any user's home directory, and so you have control over their files.


The /var Directory


The /var directory holds subdirectories for tasks whose files change frequently, such as lock files, log files, Web server files, or printer spool files. For example, the /var directory holds server data directories, such as /var/www for the Apache Web server Web site files or /var/ftp for your FTP site files, as well as /var/named for the DNS server. The /tmp directory is simply a directory to hold any temporary files programs may need to perform a particular task.










































Table 30-3: /usr Directories


Directory


Description


/usr/bin


Holds most user commands and utility programs.


/usr/sbin


Holds administrative applications.


/usr/lib


Holds libraries for applications, programming languages, desktops, and so on.


/usr/games


Holds games and educational programs.


/usr/include


Holds C programming language header files (.h).


/usr/doc


Holds Linux documentation.


/usr/local


Holds locally installed software.


/usr/share


Holds architecture-independent data such as documentation.


/usr/src


Holds source code, including the kernel source code.


/usr/X11R6


Holds X Window System–based applications and libraries.


The /var directories are designed to hold data that changes with the normal operation of the Linux system. For example, spool files for documents that you are printing are kept here. A spool file is created as a temporary printing file and is removed after printing. Other files, such as system log files, are changed constantly. Table 30-4 lists the subdirectories of the /var directory.































































Table 30-4: /var Subdirectories


Directory


Description


/var/account


Processes accounting logs.


/var/cache


Holds application cache data for Man pages, Web proxy data, fonts, or application-specific data.


/var/crash


Holds system crash dumps.


/var/games


Holds varying games data.


/var/lib


Holds state information for particular applications.


/var/local


Used for data that changes for programs installed in /usr/local.


/var/lock


Holds lock files that indicate when a particular program or file is in use.


/var/log


Holds log files such as /var/log/messages that contain all kernel and system program messages.


/var/mail


Holds user mailbox files.


/var/opt


Holds variable data for applications installed in /opt.


/var/run


Holds information about system's running processes.


/var/spool


Holds application's spool data such as that for mail, news, and printer queues, as well as

cron and

at jobs.


/var/tmp


Holds temporary files that should be preserved between system reboots.


/var/yp


Holds Network Information Service (NIS) data files.


/var/www


Holds Web server Web site files.


/var/ftp


Holds FTP server FTP files.


/var/named


Holds DNS server domain configuration files.



The /proc File System


The /proc file system is a special file system that is generated in system memory. It does not exist on any disk. /proc contains files that provide important information about the state of your system. For example, /proc/cpuinfo holds information about your computer's CPU processor. /proc/devices lists those devices currently configured to run with your kernel. /proc/filesystems lists the file systems. /proc files are really interfaces to the kernel, obtaining information from the kernel about your system. Table 30-5 lists the /proc subdirectories and files.































































Table 30-5: /proc Subdirectories and Files


Files


Description


/proc/num


There is a directory for each process labeled by its number. /proc/1 is the directory for process 1.


/proc/cpuinfo


Contains information about the CPU, such as its type, make, model, and performance.


/proc/devices


Lists the device drivers configured for the currently running kernel.


/proc/dma


Displays the DMA channels currently used.


/proc/filesystems


Lists file systems configured into the kernel.


/proc/interrupts


Displays the interrupts in use.


/proc/ioports


Shows the I/O ports in use.


/proc/kcore


Holds an image of the physical memory of the system.


/proc/kmsg


Contains messages generated by the kernel.


/proc/ksyms


Holds the symbol table for the kernel.


/proc/loadavg


Lists the system load average.


/proc/meminfo


Displays memory usage.


/proc/modules


Lists the kernel modules currently loaded.


/proc/net


Lists status information about network protocols.


/proc/stat


Contains system operating statistics, such as page fault occurrences.


/proc/uptime


Displays the time the system has been up.


/proc/version


Displays the kernel version.






Tip

You can use redhat-config-proc, the Kernel Tuning tool (More System Tools menu), to set proc file values you are allowed to change, like the maximum number of files, or turning on IP forwarding.



Device Files: /dev


To mount a file system, you have to specify its device name. The interfaces to devices that may be attached to your system are provided by special files known as device files. The names of these device files are the device names. Device files are located in the /dev directories and usually have abbreviated names ending with the number of the device. For example, fd0 may reference the first floppy drive attached to your system. The prefix sd references SCSI hard drives, so sda2 would reference the second partition on first SCSI hard drive. In most cases, you can use the

man command with a prefix to obtain more detailed information about this kind of device. For example,

man

sd displays the Man pages for SCSI devices. A complete listing of all device names can be found in the devices file located in the linux/doc/device-list directory at the www.kernel.org Web site, and in the devices.txt file in the /etc/usr/linux-2.4/Documentation directory on your Red Hat system. Table 30-6 lists several of the commonly used device names.











































































Table 30-6: Device Name Prefixes


Device Name


Description


hd


IDE hard drives; 1–4 are primary partitions; 5 and up are logical partitions


sd


SCSI hard drives


scd


SCSI CD-ROM drives


fd


Floppy disks


st


SCSI tape drives


nst


SCSI tape drives, no rewind


ht


IDE tape drives


tty


Terminals


lp


Printer ports


pty


Pseudoterminals (used for remote logins)


js


Analog joysticks


midi


Midi ports


ttyS


Serial ports


md


RAID devices


rd/cndn


The directory that holds RAID devices is rd; cn is the RAID controller and dn is the RAID disk for that controller


cdrom


Link to your CD-ROM device file


cdwriter


Link to your CD-R or CD-RW device file


modem


Link to your modem device file


floppy


Link to your floppy device file


tape


Link to your tape device file


scanner


Link to your scanner device file


Floppy Devices


The device name for your floppy drive is fd0; it is located in the directory /dev. /dev/fd0 references your floppy drive. Notice the numeral 0 after fd. If you have more than one floppy drive, additional drives are represented by fd1, fd2, and so on.

Hard Disk Devices


IDE hard drives use the prefix hd, whereas SCSI hard drives use the prefix sd. RAID devices, on the other hand, use the prefix md. The prefix for a hard disk is followed by a letter that labels the hard drive and a number for the partition. For example, hda2 references the second partition on the first IDE hard drive, where the first hard drive is referenced with the letter a, as in hda. The device sdb3 refers to the third partition on the second SCSI hard drive (sdb). RAID devices, however, are numbered from 0, like floppy drives. Device md0 references the first RAID device, and md1 references the second. On an IDE hard disk device, Linux supports up to four primary IDE hard disk partitions, numbered 1 through 4. You are allowed any number of logical partitions. To find the device name, you can use

df to display your hard partitions or examine the /etc/fstab file.

CD-ROM Devices


The device name for your CD-ROM drive varies depending on the type of CD-ROM you have. The device name for an IDE CD-ROM has the same prefix as an IDE hard disk partition, hd, and is identified by a following letter that distinguishes it from other IDE devices. For example, an IDE CD-ROM connected to your secondary IDE port may have the name hdc. An IDE CD-ROM connected as a slave to the secondary port may have the name hdd. The actual name is determined when the CD-ROM is installed, as happened when you installed your Linux system. SCSI CD-ROM drives use a different nomenclature for their device names. They begin with scd for SCSI drive and are followed by a distinguishing number. For example, the name of a SCSI CD-ROM could be scd0 or scd1. The name of your CD-ROM was determined when you installed your system. You can find out what it is by examining the /etc/fstab file.


Mounting File Systems


Attaching a file system on a storage device to your main directory tree is called mounting the device. The file system is mounted to an empty directory on the main directory tree. You can then change to that directory and access those files. If the directory does not yet exist, you have to create it. The directory in the file structure to which the new file system is attached is referred to as the mountpoint. For example, to access files on a CD-ROM, first you have to mount the CD-ROM.

Mounting file systems can be done only as the root user. This is a system administration task and cannot be performed by a regular user. As the root user, you can, however, make a particular device, like a CD-ROM, user-mountable. In this way, any user could mount a CD-ROM. You could do the same for a floppy drive.





Tip

On GNOME, you can use the Disk Management tool on the System Settings window and menu to mount and unmount file systems, including floppy disks and CD-ROMs. On KDE, you can use the KDiskFree utility (More System Tools menu), which also lists your mountable file systems as well as their disk usage.


Even the file systems on your hard disk partition must be explicitly mounted. When you install your Linux system and create the Linux partition on your hard drive, however, your system is automatically configured to mount your main file system whenever it starts. When your system shuts down, they are automatically unmounted. You have the option of unmounting any file system, removing it from the directory tree, and possibly replacing it with another, as is the case when you replace a CD-ROM.

Once a file system it actually mounted, an entry for it is made by the operating system in the /etc/mstab file. Here you will find listed all file systems currently mounted.


File System Information


The file systems on each storage device are formatted to take up a specified amount of space. For example, you may have formatted your hard drive partition to take up 3GB. Files installed or created on that file system take up part of the space, while the remainder is available for new files and directories. To find out how much space you have free on a file system, you can use the

df command or, on GNOME, you can use either the Procman System Monitor or the KDE DiskFree utility (More System Tools menu). For the Procman System Monitor (System Tools menu), click the System Monitor tab to display a bar graph of the free space on your file systems. KDE DiskFree displays a list of devices showing how much space is free on each partition, and the percentage used.

df


The

df command reports file system disk space usage. It lists all your file systems by their device names, how much disk space they take up, and the percentage of the disk space used, as well as where they are mounted. With the

-h option, it displays information in a more readable format; such as measuring disk space in megabytes instead of memory blocks. The

df command is also a safe way to obtain a listing of all your partitions, instead of using

fdisk (with

fdisk you could erase partitions).

df shows only mounted partitions, however, whereas

fdisk shows all partitions.

$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hda3 9.7G 2.8G 6.4G 31% /
/dev/hda2 99M 6.3M 88M 7% /boot
/dev/hda2 22G 36M 21G 1% /home
/dev/hdc 525M 525M 0 100% /mnt/cdrom

You can also use

df to tell you to what file system a given directory belongs. Enter

df with the directory name or

df

. for the current directory.

$ df .
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/hda3 297635 169499 112764 60% /

e2fsck and fsck


To check the consistency of the file system and repair it if it is damaged, you can use file system checking tools.

fsck checks and repairs a Linux file system.

e2fsck is designed to support ext2 and ext3 file systems, whereas the more generic

fsck also works on any other file systems. The ext2 and ext3 file systems are the file systems normally used for Linux hard disk partitions and floppy disks. Linux file systems beginning with Red Hat 7.3 are normally ext3, which you would use

e2fsck to check.

fsck and

e2fsck take as their argument the device name of the hard disk partition that the file system uses.

fsck   device-name

Before you check a file system, be sure that the file system is unmounted.

e2fsck should not be used on a mounted file system. To use

e2fsck , enter

e2fsck and the device name that references the file system. The

-p option automatically repairs a file system without first requesting approval from the user for each repair task. The following examples check the disk in the floppy drive and the primary hard drive:

# e2fsck /dev/fd0
# e2fsck /dev/hda1

With

fsck , the

-t option lets you specify the type of file system to check, and the

-a option automatically repairs systems, whereas the

-r option first asks for confirmation. The

-A option checks all systems in the /etc/fstab file.





Tip

In earlier distribution versions,

fsck and

e2fsck were also used to recover file systems after disk crashes or reset-button reboots. With recent releases, journaling capabilities were introduced with file systems like ext3 and ReiserFS. Journaling provides for fast and effective recovery in case of disk crashes, so recovering with

fsck or

e2fsck is no longer necessary.



/ 328