Working with the Linux File System


Fedora uses a file system, or layout of hierarchical directories similar to that used by other UNIX variants (such as Mac OS X). Nearly all Linux distributions use a similar directory structure, and Linux distribution vendors have generally agreed on the naming and location of critical Linux files and directories.

Note

The effort to build a consensus regarding the Linux directory structure began in 1993 with the Filesystem Hierarchy Standard (FHS), a draft proposal that addressed not only Linux issues, but also those of other operating systems, such as BSD. Red Hat has stated that it is committed to staying compliant with the FHS, which specifies the location and names of files and directories.

Fedora uses the current 2.3 standard. Key additions to this include the creation of a /media directory for removable storage devices such as DVD drives and zip disks (although keeping /mnt as a temporary mount point). udev has also been added to Fedora; although it is not a part of FHS 2.3, it enables /dev to become a dynamically managed folder allowing the hot-plugging of devices onto the system and the creation (on demand) of device nodes.


The commonality of how the Linux directory structure is laid out is very useful for open source developers because it cuts down the amount of work they have to do to get their programs to work with different distributions. For a programmer to know, for example, that the useradd command is always under /usr/sbin means that he can create shell scripts and other utilities that take advantage of this, and know that they will work universally. Perhaps unsurprisingly, given the ancestry of Linux, you will find that other UNIX-like operating systems follow the same directory organization. Of course, you do not get the most of knowing this secret unless you actually learn a little about how the directories are organized, along with the contents of files and directories, and where software should be installed and files stored.

A good knowledge of the Linux file system pays dividends to pretty much every system administrator. Because you have full control (through the root or super-user account), this information is invaluable in keeping your system running smoothly and securely.

Viewing the Linux File System

Look at the layout of a typical Fedora system by using the list directory contents command, ls, like this:

$ ls / bin   dev  home    lib         media  mnt   proc  sbin     srv    tftpboot  usr boot  etc  initrd  lost+found  misc   opt   root  selinux  sys    tmp       var


Note

This section provides an overview of the Fedora file system. You might find a fewer or greater number of directories than discussed here in your own system. When some software packages are installed, they create new directories. Updating software packages might also remove or change the name of some directories. See Chapter 7, "Managing Software and System Resources," for more information on installing, upgrading, and removing software from your Linux system.


To get a more detailed picture, use the TRee command to show the root or base directory layout, along with associated subdirectories, like this (note that your system's /usr/src directory might be somewhat different, depending on the version of Fedora you have installed or if you have updated Fedora with a new kernel, and that not all subdirectories are listed):

$ tree -dx / / |-- bin |-- boot |-- dev |-- etc |   |-- 4Suite |   |-- X11 |   |-- cron.d |   |-- ppp |   |-- rc.d |   |-- selinux |   |-- sysconfig |-- home |   '-- andrew |-- lib |   |-- modules |-- lost+found |-- media |   |-- cdrom |   '-- floppy |-- misc |-- mnt |   '-- hgfs |-- net |-- opt |-- proc |-- root |-- sbin |-- selinux |-- srv |-- sys |-- tmp |-- usr |   |-- X11R6 |   |   |-- bin |   |   |-- lib |   |-- bin |   |-- include |   |-- lib |   |-- local |   |-- sbin |   |-- share |   |-- src |   |   |-- kernels |   |   '-- redhat '-- var     |-- ftp     |-- log     '-- spool


This example (pruned from more than 30,000 directories) shows the higher-level directories and corresponds to the directories and descriptions in Table 5.1.

Table 5.1. Basic Linux Directories

Name

Description

/

The root directory

/bin

Essential commands

/boot

Boot loader files, Linux kernel

/dev

Device files

/etc

System configuration files

/home

User home directories

/initrd

Initial RAM disk boot support (used during boot time)

/lib

Shared libraries, kernel modules

/lost+found

Directory for recovered files (if found after a file system check)

/media

Mount point for removable media such as DVDs and floppy disks

/mnt

Usual mount point for local, remote file systems

/opt

Add-on software packages

/proc

Kernel information, process control

/root

Super-user (root home)

/sbin

System commands (mostly root only)

/selinux

Holds the data for SELinux, the security component of Fedora

/sys

Real-time information on devices used by the kernel

/tftpboot

Network boot support

/tmp

Temporary files

/usr

Secondary software file hierarchy

/var

Variable data (such as logs); spooled files


Some of the important directories in Table 5.1, such as those containing user and root commands or system configuration files, are discussed in the following sections. You use and edit files under these directories when you use Fedora.

Use Essential Commands from the /bin and /sbin Directories

The /bin directory (about 5MB if you do a full install) contains essential commands used by the system when running and booting Linux. In general, only the root operator uses the commands in the /sbin directory. Many (though not all) of these commands are statically linked; such commands do not depend on software libraries residing under the /lib or /usr/lib directories. Nearly all the other applications on your system are dynamically linkedmeaning that they require external software libraries (also known as shared libraries) in order to run.

Tip

Because the system contains dynamically linked applications, you might sometimes get dependency errors when installing or upgrading software packages; in those situations, a supporting library (or application) might not be present. See Chapter 7 for more information on working with dynamically linked applications and other methods of avoiding such problems. Thankfully, "dependency hell" is largely a thing of the past due to programs such as yum.


Store the Booted Kernel and View Stored Devices in the /boot and /dev Directories

The /boot directory contains a compressed version of the Linux kernel (loaded at boot time), along with other files that describe the kernel or provide information for booting Linux. When you rebuild or install a new kernel, the kernel and related files are placed in this directory (see Chapter 39, "Kernel and Module Management," for more information on rebuilding or installing a kernel).

Linux device files are contained under the /dev directory. Note that under Linux, nearly everything on your system is a file. This means that (with the exception of network interfaces; see the note that follows the upcoming list) regular files; directories; hard drive partitions; serial, printer, or USB ports; and video and sound devices all are files!

The /dev directory contains more than 7,500 files representing devices that may or may not be in use on your system. Some of the most commonly used devices in this directory include

  • IDE (Integrated Drive Electronics) hard drives, such as /dev/hda and /dev/hdb

  • CD-ROM drives; some which are IDE, others which are CD-RW (CD read/write) drives emulated as SCSI (Small Computer Systems Interface) devices, such as /dev/scd0

  • Serial ports, such as /dev/ttyS0 for COM1, /dev/ttyS1 for COM2, and so on

  • Pointing devices, including /dev/input/mice and others

  • Printers, such as /dev/lp0

Note

Network interfaces (such as eth0 or ppp0) are not represented by Linux device files, but are created in memory when activated. See Chapter 18, "Network Connectivity," for more information.


Use and Edit Files in the /etc Directory

More than 65MB of system configuration files and directories reside under the /etc directory if you install all the software included with this book. Some major software packages, such as Apache, OpenSSH, and xinetd, have directories of configuration files under /etc. Other important system-related configuration files in /etc are

  • fstab The file system table is a text file listing each hard drive, CD-ROM, floppy, or other storage device attached to your PC. The table indexes each device's partition information with a place in your Linux file system (directory layout) and lists other options for each device when used with Linux (see Chapter 38, "Managing the File System"). Nearly all entries in fstab can be manipulated by root using the mount command.

  • inittab The system initialization table defines the default runlevel, also known as run-control level or system state. Changes to this file can determine whether your system boots to a graphical or text login, as well as whether dial-up remote access is enabled. (You learn about default runlevels in the section "System Services and Runlevels" located in Chapter 15, "Automating Tasks." See the section "Starting X," located in Chapter 6, to learn more about changing inittab to boot to a graphical interface. The section "Configuring a Dial-In PPP Server" in Chapter 18 discusses editing inittab to enable dial-up remote access.)

  • modprobe.conf This configuration file contains directions and options used when loading kernel modules to enable various types of hardware, such as sound, USB, networking, and so on (discussed in the section "Managing Modules" in Chapter 39). The contents of this file are used during boot time, and the file can be manually edited or automatically updated by Fedora's kudzu hardware management tool (if enabled, as you learn later in this section).

  • passwd The list of users for the system, along with user account information. The contents of this file can be changed by various programs, such as useradd or chsh.

  • printcap The system's printer capabilities database (discussed in the section "Overview of Fedora Printing" in Chapter 12, "Printing with Fedora").

  • shells A list of approved shells (command-line interfaces).

One of the most important directories under /etc for Fedora is sysconfig. This directory contains network activation scripts and hardware- and software-related information:

$ tree -afx /etc/sysconfig /etc/sysconfig |-- /etc/sysconfig/apm-scripts |   '-- /etc/sysconfig/apm-scripts/apmscript |-- /etc/sysconfig/apmd |-- /etc/sysconfig/auditd |-- /etc/sysconfig/authconfig |-- /etc/sysconfig/autofs |-- /etc/sysconfig/bluetooth |-- /etc/sysconfig/clock |-- /etc/sysconfig/console |-- /etc/sysconfig/crond |-- /etc/sysconfig/desktop |-- /etc/sysconfig/diskdump |-- /etc/sysconfig/dund |-- /etc/sysconfig/firstboot |-- /etc/sysconfig/grub |-- /etc/sysconfig/harddisks |-- /etc/sysconfig/hidd |-- /etc/sysconfig/httpd |-- /etc/sysconfig/hwconf |-- /etc/sysconfig/i18n |-- /etc/sysconfig/init |-- /etc/sysconfig/installinfo |-- /etc/sysconfig/iptables |-- /etc/sysconfig/iptables-config |-- /etc/sysconfig/irda |-- /etc/sysconfig/kernel |-- /etc/sysconfig/keyboard |-- /etc/sysconfig/kudzu |-- /etc/sysconfig/lm_sensors |-- /etc/sysconfig/modules |-- /etc/sysconfig/mouse |-- /etc/sysconfig/mouse.BeforeVMwareToolsInstall |-- /etc/sysconfig/named |-- /etc/sysconfig/netdump |-- /etc/sysconfig/netdump_id_dsa |-- /etc/sysconfig/netdump_id_dsa.pub |-- /etc/sysconfig/network |-- /etc/sysconfig/network-scripts |   |-- /etc/sysconfig/network-scripts/ifcfg-eth0 |   |-- /etc/sysconfig/network-scripts/ifcfg-lo |   |-- /etc/sysconfig/network-scripts/ifdown -> ../../../sbin/ifdown |   |-- /etc/sysconfig/network-scripts/ifdown-aliases |   |-- /etc/sysconfig/network-scripts/ifdown-bnep |   |-- /etc/sysconfig/network-scripts/ifdown-eth |   |-- /etc/sysconfig/network-scripts/ifdown-ippp |   |-- /etc/sysconfig/network-scripts/ifdown-ipsec |   |-- /etc/sysconfig/network-scripts/ifdown-ipv6 |   |-- /etc/sysconfig/network-scripts/ifdown-isdn -> ifdown-ippp |   |-- /etc/sysconfig/network-scripts/ifdown-post |   |-- /etc/sysconfig/network-scripts/ifdown-ppp |   |-- /etc/sysconfig/network-scripts/ifdown-sit |   |-- /etc/sysconfig/network-scripts/ifdown-sl |   |-- /etc/sysconfig/network-scripts/ifup -> ../../../sbin/ifup |   |-- /etc/sysconfig/network-scripts/ifup-aliases |   |-- /etc/sysconfig/network-scripts/ifup-bnep |   |-- /etc/sysconfig/network-scripts/ifup-eth |   |-- /etc/sysconfig/network-scripts/ifup-ippp |   |-- /etc/sysconfig/network-scripts/ifup-ipsec |   |-- /etc/sysconfig/network-scripts/ifup-ipv6 |   |-- /etc/sysconfig/network-scripts/ifup-ipx |   |-- /etc/sysconfig/network-scripts/ifup-isdn -> ifup-ippp |   |-- /etc/sysconfig/network-scripts/ifup-plip |   |-- /etc/sysconfig/network-scripts/ifup-plusb |   |-- /etc/sysconfig/network-scripts/ifup-post |   |-- /etc/sysconfig/network-scripts/ifup-ppp |   |-- /etc/sysconfig/network-scripts/ifup-routes |   |-- /etc/sysconfig/network-scripts/ifup-sit |   |-- /etc/sysconfig/network-scripts/ifup-sl |   |-- /etc/sysconfig/network-scripts/ifup-wireless |   |-- /etc/sysconfig/network-scripts/init.ipv6-global |   |-- /etc/sysconfig/network-scripts/network-functions |   '-- /etc/sysconfig/network-scripts/network-functions-ipv6 |-- /etc/sysconfig/networking |   |-- /etc/sysconfig/networking/devices |   |    '-- /etc/sysconfig/networking/devices/ifcfg-eth0 |   '-- /etc/sysconfig/networking/profiles |       '-- /etc/sysconfig/networking/profiles/default |           |-- /etc/sysconfig/networking/profiles/default/hosts |           |-- /etc/sysconfig/networking/profiles/default/ifcfg-eth0 |           '-- /etc/sysconfig/networking/profiles/default/resolv.conf |-- /etc/sysconfig/ntpd |-- /etc/sysconfig/pand |-- /etc/sysconfig/pcmcia |-- /etc/sysconfig/prelink |-- /etc/sysconfig/rhn |   |-- /etc/sysconfig/rhn/clientCaps.d |   |-- /etc/sysconfig/rhn/rhn-applet |   |-- /etc/sysconfig/rhn/rhnsd |   |-- /etc/sysconfig/rhn/sources |   |-- /etc/sysconfig/rhn/up2date |   |-- /etc/sysconfig/rhn/up2date-keyring.gpg |   '-- /etc/sysconfig/rhn/up2date-uuid |-- /etc/sysconfig/samba |-- /etc/sysconfig/saslauthd |-- /etc/sysconfig/selinux -> /etc/selinux/config |-- /etc/sysconfig/sendmail |-- /etc/sysconfig/spamassassin |-- /etc/sysconfig/squid |-- /etc/sysconfig/syslog |-- /etc/sysconfig/system-config-securitylevel |-- /etc/sysconfig/system-config-users |-- /etc/sysconfig/tux |-- /etc/sysconfig/vncservers '-- /etc/sysconfig/xinetd 10 directories, 94 files


For brevity, not all directories and files are discussed here. /etc/sysconfig contains many different hardware and software settings critical to the operation of your Fedora system. Knowing the location and contents of these files can be helpful if you need to troubleshoot new hardware configurations.

The settings in various files under /etc/sysconfig (such as keyboard, mouse, sound, and so on) are usually created automatically by a related Fedora graphical or console-based configuration utility.

These contents might dynamically change if you use the kudzu hardware configuration service. The kudzu service also prompts you at boot time to remove, configure, or ignore a related setting if kudzu detects new or different hardware (such as a new USB keyboard, network card, or monitor). kudzu creates a file called hwconf that contains a hardware profile of your PC's current state. Note that if kudzu is not enabled or running, you can use device-specific configuration utilities such as system-config-keyboard, or you can manually edit configuration files.

Information about the type of pointing device attached to the PC, for example, is contained in the file /etc/sysconfig/mouse:

MOUSETYPE="ps/2" XMOUSETYPE="PS/2" FULLNAME="Generic 3 Button Mouse (PS/2)" XEMU3=no


If a different mouse, say a three-button USB device, is attached to the computer, you can edit this information to reflect the hardware change:

MOUSETYPE="ps/2" XMOUSETYPE="IMPS/2" FULLNAME="Generic 3 Button Mouse (USB)" XEMU3=no


Caution

If you are new to Linux, the system-config-mouse client is the best tool to use to configure a new mouse. You should manually edit system hardware configuration files used by graphical management clients only as a last resort.


Protect the Contents of User Directories/home

The most important data on a Linux system resides in user's directories, found under the /home directory. Segregating the system and user data can be helpful in preventing data loss and making the process of backing up easier. For example, having user data reside on a separate file system or mounted from a remote computer on the network might help shield users from data loss in the event of a system hardware failure.

Use the Contents of the /proc Directory to Interact with the Kernel

The content of the /proc directory is created from memory and only exists while Linux is running. This directory contains special "files" that either extract information from or send information to the kernel. Many Linux utilities extract information from dynamically created directories and files under this directory, also known as a virtual file system. For example, the free command obtains its information from a file named meminfo:

$ free              total       used       free     shared    buffers      cached Mem:        255040     250752       4288          0       1716       90964 -/+ buffers/cache:     158072      96968 Swap:       524280        760     523520


This information constantly changes as the system is used. You can get the same information by using the cat command to see the contents of the meminfo file:

$ cat /proc/meminfo MemTotal:       255040 kB MemFree:          4412 kB Buffers:          2164 kB Cached:          90580 kB SwapCached:          0 kB Active:         208884 kB Inactive:         8976 kB HighTotal:           0 kB HighFree:            0 kB LowTotal:       255040 kB LowFree:          4412 kB SwapTotal:      524280 kB SwapFree:       523520 kB Dirty:              48 kB Writeback:           0 kB Mapped:         201520 kB Slab:            24772 kB CommitLimit:    651800 kB Committed_AS:   341544 kB PageTables:       2880 kB VmallocTotal:   770040 kB VmallocUsed:      3432 kB VmallocChunk:   762312 kB HugePages_Total:     0 HugePages_Free:      0 Hugepagesize:     4096 kB


The /proc directory can also be used to dynamically alter the behavior of a running Linux kernel by echoing numerical values to specific files under the /proc/sys directory. For example, to turn on kernel protection against one type of denial of service (DOS) attack known as SYN flooding, use the echo command to send the number 1 (one) to the following /proc path:

# echo 1 >/proc/sys/net/ipv4/tcp_syncookies


Note

The Linux kernel has a number of built-in protections, but good system administration security policies and a secure firewall protecting your gateway, router, or Internet-connected system are the best protection you can use. See the section "Securing Your Network" in Chapter 18 for an overview of firewalling and examples of how to implement Red Hat's network security tools included with Fedora.


Other ways to use the /proc directory include

  • Getting CPU information, such as the family, type, and speed from /proc/cpuinfo.

  • Viewing important networking information under /proc/net, such as active interfaces information under /proc/net/dev, routing information in /proc/net/route, and network statistics in /proc/net/netstat.

  • Retrieving file system information.

  • Reporting media mount point information via USB; for example, the Linux kernel reports what device to use to access files (such as /dev/sda) if a USB camera or hard drive is detected on the system. You can use the dmesg command to see this information or find information about these devices under the Device File System directory /proc/devfs (see the Linux Devfs FAQ at http://www.atnf.csiro.au/~rgooch/linux/docs/devfs.html if the source code for the Linux kernel is installed). The file /usr/src/linux-2.6/Documentation/usb/proc_usb_info.txt contains general information about USB and the /proc directory, as well as what to expect in files under this directory. Note that devfs might be supported, but will generally be obsolete in the 2.6 kernel because /proc/udev replaces it as a way of managing hot-plug devices on your system.

  • Getting the kernel version in /proc/version, performance information such as uptime in /proc/uptime, or other statistics such as CPU load, swap file usage, and processes in /proc/stat.

Work with Shared Data in the /usr Directory

The /usr directory (nearly 5GB in size if you do a full install) contains software applications, libraries, and other types of shared data for use by anyone on the system. Many Linux system administrators give /usr its own partition. A number of subdirectories under /usr contain the X Window System (/usr/X11R6), man pages (/usr/share/man), software package shared files (/usr/share/name_of_package, such as /usr/share/emacs), additional application or software package documentation (/usr/share/doc), and an entire subdirectory tree of locally built and installed software, /usr/local.

Temporary File Storage in the /tmp Directory

As its name implies, the /tmp directory is used for temporary file storage; as you use Linux, various programs create files in this directory. The /tmp directory is cleaned of stale files each day by the tmpwatch command. (A stale file is any file not used after 10 days.) Fedora is configured by default to use tmpwatch to check /tmp each day by settings in your system's scheduling table, /etc/crontab.

Access Variable Data Files in the /var Directory

The /var directory contains subdirectories used by various system services for spooling and logging. Many of these variable data files, such as print spooler queues, are temporary, whereas others, such as system and kernel logs, are renamed and rotated in use. Incoming electronic mail is usually directed to files under /var/spool/mail.

Linux also uses /var for other important system services. These include the topmost File Transfer Protocol (FTP) directory under /var/ftp (see Chapter 24, "Remote File Serving with FTP"), and the Apache web server's initial home page directory for the system, /var/www/html. (See Chapter 21, "Apache Web Server Management," for more information on using Apache.)



Red Hat Fedora 5 Unleashed
Red Hat Fedora 5 Unleashed
ISBN: 067232847X
EAN: 2147483647
Year: 2004
Pages: 362

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net