Exploring the Default Directories

If this is your first introduction to Linux, you might be surprised by the way the file system is organized. In this section, you'll read about the default directories that are used by almost all Linux systems.

First, if you want to grasp the way a Linux file system is organized, you must understand that in the Linux file system structure, a clear distinction is made between files that are accessible to ordinary users and files that are accessible to the system administrator. If these are program files, you will find the former in a directory called bin (binary) and the latter in a directory called sbin (system binaries). You will find these directories at different levels in the file system.

Second, you need to understand that on a Linux server it is quite usual to work with more than one partition. This is because your server is hosting a multitude of files for the services that it offers. Linux also has different file systems that all have their own advantages; for example, you could use a different file system for the volume where your mail server stores its files than for the volume where your company database is stored. In Chapter 8 you will learn more about the organization of your server in different partitions.

No matter how many partitions you use, the start of the file system structure on any Linux system is the root partition. This is the partition on which you will find the root directory, and it is referred to with a slash (/).

Tip Don't confuse the root directory with the directory /root. The root directory (/) is the starting point of your file system under which you'll find all other directories. The directory /root is one of these directories. /root is the home directory for the user root, the administrator of your system.

As I said before, it is possible to separate the contents from different directories from this root partition and split off other partitions or volumes. (Chapter 8 covers the difference between these two.) The reason why you want to do this is obvious: if you have separated, for example, the directory /home in which you will find user home directories from the rest of the directory structure, it is impossible for a user who has no limitations set to fill up the entire file system. Also, different types of files need different types of file systems than you've just read about.

Now, it is good to work with more than one partition, but it also implies a certain risk. It could, for example, happen that one of these partitions is damaged and impossible to mount when you start your server. For this reason, you will find program files on many levels. Most essential utilities that are needed to maintain and repair your system are directly in the root partition. You will find, however, less critical programs and utilities one level lower, under /usr, for example. This /usr directory also has the subdirectories bin and sbin (and some others), and you can find them under the root of the file system.

On SUSE Linux Enterprise Server, you'll find the following default directories:

/bin: This is the location where you'll find binaries accessible to all users. These are essential binaries that must be available at all times, even if other partitions on your system have a problem. For that reason, the directory /bin is always on the root partition. In it you will find essential utilities and commands such as /bin/bash (the shell), cp (used to copy files), and many more. Some of the more complicated items, however, are elsewhere on your system.

/sbin: In this directory you will find binaries for system administration. These are critical binaries that must be available at all times in case you need to repair your system. You will also find commands and utilities you'd rather not see in the hands of your users, such as the launcher for the general system management tool yast2 or the partitioning tool fdisk.

/boot: The directory /boot contains your secondary boot loader. A boot loader consists of two parts. The first part of it is installed in the master boot record and—depending on your configuration—in the boot sector of an active partition. The second part, the so-called secondary boot loader, is in the directory/boot. For more details on its contents, read Chapter 10. The directory /boot is critical for booting your system, so don't touch it. Under normal circumstances, there is absolutely no need to modify anything in this directory.

/dev: On a Linux system, all the hardware you work with corresponds to a file on your system. If you want to address the hardware, you have to address the corresponding file. You can find these device files in the directory /dev. You will find, for example, a device called /dev/fd0 that refers to a floppy drive, if that is present in your system. On SUSE Linux you will have the device file only if the device is really present on your server. Amongst the properties of these device files are the so-called major and minor numbers. You will find them if you look at the properties of the file by using the command ls -l (see Figure 2-3). These major and minor numbers indicate to the kernel what device it actually is. Apart from the major and minor numbers, all devices are of a certain type. The most common types are block and character devices. Whether a device is a block or a character device is indicated with a b or a c in the properties of the device file. You can see these properties by using the command ls -l.

Tip One of the nice features of Linux is its flexibility. I once lost my device /dev/hdc, which I needed to address my CD drive. I did, however, find out from another Linux system that the associated major and minor numbers were 22 and 0. If you have this information, you can use the command mknod to create your own devices. In this case, I used mknod /dev/hdc b 22 0 to restore access to my CD drive. You can even use mknod to create entirely new devices.

Figure 2-3. A device has some special properties that help the kernel understand what the device's purpose is.

/etc: Most services running on Linux use an ASCII text file to store all necessary configuration information (although more services have started using XML also). These text files are kept in the directory /etc. In this directory, you will find some important configuration files such as /etc/passwd, which contains the database of local Linux users (see Figure 2-4). You will also find configuration files for all other important services such as dhcpd.conf, which stores the configuration of your DHCP server. In /etc you will find a lot of subdirectories. If a service uses more than one configuration file, it will usually create a subdirectory in which all these files are stored. For example, the Apache 2 web server configuration is in the subdirectory /etc/ apache2/.

hacluster:x:90:90:heartbeat processes:/var/lib/heartbeat/cores/hacluster :/bin/false suse-Dcc:x:102:104:Hovell Customer Center User :/var/lib/YaST2/suse-nGC-fakehome:/bin/bash

Figure 2-4. Important configuration files such as the user database /etc/passwd are stored in /etc or one of its subdirectories.

/home: Every server must have a place for the user home directories. On Unix, the directory /home is used for this purpose. To prevent a user from filling up the entire file system by accident, in most cases a separate partition is created for this directory.

/lib: Many programs that are used in a Linux environment share some of their code. This shared code is stored in different library files. All the libraries needed by binaries that are in a subdirectory of your file system root are in the directory /lib. You will also find some other important modules in this directory, such as the driver modules that are used by the kernel of your server.

Tip You want to know which modules are used by a certain binary? Use ldd. For example, you can find out exactly which libraries are used by /bin/bash by typing ldd /bin/bash. This will show you that all the libraries it uses are in /lib (see Figure 2-5).

Figure 2-5. With ldd you can find out exactly which libraries are used by a certain command.

/media: On a Linux system, to access files that are not on the hard disk of your computer, you need to mount the media they are on. When you mount, for example, a CD, you connect it to a directory on your file system. This must be a directory that exists before you start mounting anything. The default directory that is used for regular mounts is /media. In this directory, a subdirectory is created automatically when a new removable device is detected. CDs, DVDs, and USB sticks will appear here (and on the graphical desktop) once they are mounted with the label of the device used as the name of the directory where the device is mounted. Check Chapter 4 for more information about mounting devices.

/mnt: On older Linux systems, /mnt was the default directory for mounting devices. On more recent systems, this has been replaced by the /media directory. However, /mnt still has a purpose: it is used for mounts that don't occur often, such as a mount to a server that has to be accessed only once.

/usr: The directory /usr is probably the largest directory on your system. In it you'll find almost all the user-accessible files. Because so many files appear in this directory, you will find an entire structure of subdirectories in this directory. There is, for example, /usr/bin, where most programs are stored; /usr/X11R6, where your graphical user environment resides; and /usr/ src, where you can put the source files of the open source programs and kernel you use. Because there are so many files in /usr, it is usual to put /usr on its own partition.

Tip Have you always wanted to find out how much space a directory occupies on your hard disk? Use du -hs from a console environment. It will show you the disk usage of a specified directory. The normal output of this command is in blocks; the parameter -h presents the output in a human-readable form, and the parameter -s summarizes a directory's totals instead of showing individual subdirectory entries. Use, for example, du -h /usr to find out exactly how much space /usr occupies.

/opt: In /usr you will find a lot of binaries. Many of these are small software packages. Usually large software installations, such as office suites, are stored in /opt. On SUSE Linux Enterprise Server, you will find, for example, the GNOME graphical interface and the Oracle database (if installed) as subdirectories of this directory.

/proc: The directory /proc is a strange directory. This is because it doesn't really exist on the hard disk of your computer. /proc is an interface to the memory of your server; consider it the location where the operating system gives information about how it works to the user. An advanced administrator can use it to tune how the server works and get information about its current status. You can find a lot of information about your server in the files in this directory. Try, for example, the command cat /proc/cpuinfo to show the contents of the text file /proc/ cpuinfo (you must be root to do this). This command will show you a lot of information about the processors in your server (see Figure 2-6).

/root: Ordinary users have their home directories in /home. A system administrator is not a normal user; in a Unix environment, a system administrator is therefore respectfully called the superuser. Since this user may have some important tools in the home directory, this directory is not in /home with those of the other users. Instead, the user root uses /root as the home directory. This is for good reason: on many servers, the directory /home is on a separate partition. If, for any reason, you cannot access this partition anymore, at least user root has still access to the home directory, which probably contains some important files.

/srv:You will find all the files from some important services in this directory. This directory is, for example, used to store your entire web server and FTP server file structures. If you want to configure your server as an installation server, /srv is the place to put the installation files needed by this server.

/sys:You can use the directory /sys to store information about the state of your system. Its use is like the use of /proc, with the difference that the information in /sys is kept on the hard disk of your server, so it is still available after you have rebooted it. The information in /sys is more directly related to the hardware you are using on your server, whereas /proc is used to store information about the current state of the kernel.

/tmp: As the name suggests, /tmp is used for temporary files. This is the only directory on the entire system that every user can write to. This is a bad idea, however, because the content of this directory can be wiped automatically by any process or root without any warning being issued before that happens.

Figure 2-6. You can get a lot of information about your system from the files in /proc.

/var: The last directory you will find on any Linux server is /var. This directory contains mostly files that are created by your server and whose content can grow very fast; think of the mail folders of users when the server is used as a mail server. Because /var is so dynamic, it is a good idea to keep /var on a separate partition. The exact contents of /var depend on what you have installed on your system. In most cases, you will find a directory called /var/spool in which print jobs are spooled before they are processed by your server. Another important subdirectory of /var is the directory /log in which you will find several log files, such as the main system log file in /var/log/messages.

Was this article helpful?

0 0

Post a comment