Working with the Linux File System

 < Day Day Up > 

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 for other operating systems, such as BSD. Red Hat has stated that it is committed to stay 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 (while keeping /mnt as a temporary mount point). udev has also been added to Fedora; although it's 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 universal layout of directories and file locations for Linux is extremely helpful for individual developers or companies creating distributions, packaging applications, and crafting system administration utilities. For example, knowing that the useradd command is always found under the /usr/sbin directory can simplify the creation of administrative shell scripts designed to be used by system administrators. This information can also help you if you use other Unix-like operating systems or other Linux distributions and need to troubleshoot software installation, or plan the addition of major software packages onto your Fedora system.

To gain the full benefits of this universal layout, you must know how Linux-based operating systems are organized, what the contents are of files and directories on your system, and where files and software should be installed. Understanding the Linux file system is part of learning how to administer and use Linux. As the root operator, you should know the name and proper location of all files (aside from user data) not only to ensure a smoothly running system, but also especially for security reasons.

Viewing the Linux File System

Look at the layout of Fedora Core Linux 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 Core file system. You might find fewer or more 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, or 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 |   |-- X11 |   |-- cron.d |   |-- ppp |   |-- rc.d |   |-- ssh |   |-- sysconfig |-- home |   `-- bball |-- lib |   `-- modules |-- lost+found |-- media |   |-- cdrom |   |-- floppy |-- misc |-- mnt |   |-- cdrom |   `-- floppy |-- opt |-- proc |-- root |-- sbin |-- tftpboot |-- tmp |-- usr |   |-- X11R6 |   |   |-- bin |   |   |-- include |   |   |-- lib |   |-- bin |   |-- doc |   |-- include |   |-- lib |   |-- local |   |-- sbin |   |-- share |   |-- src |   |   |-- redhat |   |   `-- sys | `-- 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 filesystem check)

/media

Mount point for removable media such as CD-ROMs and floppy disks

/mnt

Usual mount point for local, remote filesystems

/opt

Add-on software packages

/proc

Kernel information, process control

/root

Superuser (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 will 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 linked meaning 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.


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 38, "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 note that follows 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 of which are IDE, whereas others 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 17, "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 system filesystem 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 37, "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 14, "Automating Tasks." See the section "Starting X" located in Chapter 6 to learn more about changing inittab to boot to a graphical interface. Chapter 18, "Internet Connectivity," in the section "Configuring a Dial-In PPP Server" 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 38). The contents of this file are used during boot time, and the file can be manually edited or automatically updated by Red Hat's kudzu hardware management server (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 Linux Printing" in Chapter 11, "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/amd |-- /etc/sysconfig/apm-scripts |   `-- /etc/sysconfig/apm-scripts/apmscript |-- /etc/sysconfig/apmd ... |-- /etc/sysconfig/clock |-- /etc/sysconfig/console ... |-- /etc/sysconfig/dhcpd |-- /etc/sysconfig/dhcrelay ... |-- /etc/sysconfig/grub |-- /etc/sysconfig/harddisks |-- /etc/sysconfig/hidd |-- /etc/sysconfig/httpd |-- /etc/sysconfig/hwconf ... |-- /etc/sysconfig/init ... |-- /etc/sysconfig/keyboard |-- /etc/sysconfig/kudzu |-- /etc/sysconfig/lm_sensors |-- /etc/sysconfig/mouse |-- /etc/sysconfig/named |-- /etc/sysconfig/netdump ... |-- /etc/sysconfig/network |-- /etc/sysconfig/network-scripts |   |-- /etc/sysconfig/network-scripts/ifcfg-eth0 ... |   |-- /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/ntpd |-- /etc/sysconfig/pand |-- /etc/sysconfig/pcmcia ... |-- /etc/sysconfig/redhat-config-users |-- /etc/sysconfig/redhat-logviewer |-- /etc/sysconfig/rhn |   |-- /etc/sysconfig/rhn/rhnsd |   |-- /etc/sysconfig/rhn/up2date |   `-- /etc/sysconfig/rhn/up2date-keyring.gpg |-- /etc/sysconfig/samba |-- /etc/sysconfig/sendmail |-- /etc/sysconfig/spamassassin |-- /etc/sysconfig/squid |-- /etc/sysconfig/syslog ... |-- /etc/sysconfig/ups |-- /etc/sysconfig/vncservers |-- /etc/sysconfig/xinetd `-- /etc/sysconfig/yppasswdd 

For brevity, not all directories and files are discussed here or listed in the example. /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 Red Hat or 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're new to Linux, the system-config-mouse client is the best tool to use to configure a new mouse. You should only manually edit system hardware configuration files used by graphical management clients as a last resort.


Protect the Contents of User Directories /home

The most important data on a Linux system reside 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 filesystem 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 filesystem. For example, the free command obtains its information from a file named meminfo:

 $ free              total       used       free     shared    buffers     cached Mem:        223260     157800      65460          0      55400      58872 -/+ buffers/cache:      43528     179732 Swap:       491392        400     490992 

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         total:    used:    free:  shared: buffers:  cached: Mem:  228618240 161673216 66945024        0 56750080 60694528 Swap: 503185408   409600 502775808 MemTotal:       223260 kB MemFree:         65376 kB MemShared:           0 kB Buffers:         55420 kB Cached:          58872 kB SwapCached:        400 kB Active:         100328 kB Inact_dirty:     25044 kB Inact_clean:     19012 kB Inact_target:    28876 kB HighTotal:           0 kB HighFree:            0 kB LowTotal:       223260 kB LowFree:         65376 kB SwapTotal:      491392 kB SwapFree:       490992 kB Committed_AS:    51424 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 17 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 in tion under /proc/net/dev, routing information in /proc/net/route, and network statistics in /proc/net/netstat.

  • Retrieving filesystem information.

  • Reporting media mount point information via USB; for example, the Linux kernel will report 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 in the file /usr/src/linux-2.6/Documentation/filesystems/devfs/README 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 superseded in the upcoming 2.6 kernel by /proc/udev, 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), manual 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 top-most File Transfer Protocol (FTP) directory under /var/ftp (see Chapter 22, "Remote File Serving with FTP"), and the Apache web server's initial home page directory for the system, /var/www/html. (See Chapter 19, "Apache Web Server Management," for more information on using Apache).

     < Day Day Up > 


    Red Hat Fedora 4 Unleashed
    Red Hat Fedora 4 Unleashed
    ISBN: 0672327929
    EAN: 2147483647
    Year: 2006
    Pages: 361

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