Ubuntu 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 stay compliant with the FHS, which specifies the location and names of files and directories. Ubuntu 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 Ubuntu; 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 will 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. Knowing where to find configuration files as well as the location of key directories will help you fix your system faster when you have a problem. Viewing the Linux File SystemLook at the layout of a typical Ubuntu system by using the list directory contents command, ls, like this: $ ls / bin dev initrd lib mnt root sys var boot etc initrd.img lost+found opt sbin tmp vmlinuz cdrom home initrd.img.old media proc srv usr vmlinuz.old Note This section provides an overview of the Ubuntu 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," for more information on installing, upgrading, or removing software from your Linux system. To get a more detailed picture, install and 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 Ubuntu you have installed or if you have updated Ubuntu with a new kernel, and that not all subdirectories are listed): $ tree -dx / / |-- bin |-- boot | `-- grub |-- cdrom -> media/cdrom |-- dev |-- etc | |-- X11 | |-- acpi | |-- apt | |-- beagle | |-- cups | |-- gdm | |-- ppp |-- home | `-- andrew |-- initrd |-- lib | |-- modules |-- lost+found |-- media | |-- USB | |-- cdrom -> cdrom0 | |-- cdrom-1 | `-- cdrom0 |-- mnt |-- opt |-- proc |-- root |-- sbin |-- srv |-- sys |-- tmp |-- usr | |-- X11R6 | | |-- bin | | `-- lib | |-- bin | | `-- X11 -> ../bin | |-- games | |-- include | |-- lib | |-- local | |-- sbin | |-- share | `-- src | |-- linux-headers-2.6.15-22 | |-- linux-headers-2.6.15-22-386 | |-- linux-headers-2.6.15-23 | `-- linux-headers-2.6.15-23-386 `var This example (pruned from more than 18,000 directories) shows the higher-level directories and corresponds to the directories and descriptions in Table 5.1.
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 Ubuntu. Use Essential Commands from the /bin and /sbin DirectoriesThe /bin directory (about 4.1MB after a default 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 DirectoriesThe /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 35, "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 800 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
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 DirectoryMore than 2300 system configuration files and directories reside under the /etc directory if you carry out a default install of 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
Protect the Contents of User Directories/homeThe 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 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 KernelThe 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: 1036096 1022940 13156 0 121780 476892 -/+ buffers/cache: 424268 611828 Swap: 0 0 0 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: 1036096 kB MemFree: 12024 kB Buffers: 121808 kB Cached: 477672 kB SwapCached: 0 kB Active: 609764 kB Inactive: 286756 kB HighTotal: 131008 kB HighFree: 168 kB LowTotal: 905088 kB LowFree: 11856 kB SwapTotal: 0 kB SwapFree: 0 kB Dirty: 4 kB Writeback: 0 kB Mapped: 403412 kB Slab: 103856 kB CommitLimit: 518048 kB Committed_AS: 771220 kB PageTables: 2432 kB VmallocTotal: 114680 kB VmallocUsed: 10596 kB VmallocChunk: 103800 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. 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. Other ways to use the /proc directory include
Work with Shared Data in the /usr DirectoryThe /usr directory (nearly 2GB in size if you do a default 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. Note Although there is a /usr/X11R6 directory, it actually links through to /usr/bin. The reason for this round robin approach is to maintain compatibility with applications that still expect X to reside under /usr/X11R6. X11R7 does away with a separate directory under /usr hence why this link is in place. Temporary File Storage in the /tmp DirectoryAs 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.) Ubuntu 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 DirectoryThe /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 23, "Remote File Serving with FTP"), and the Apache web server's initial home page directory for the system, /var/www/html. (See Chapter 20, "Apache Web Server Management," for more information on using Apache.) |