-->
Page 313
This hour continues with the basics of system administration and introduces you to handling files under Linux. You'll learn how to mount filesystems, manage the filesystem table (fstab), and format floppies. You'll see how you can protect files and directories.
You will use this knowledge to help you administer your Linux
system. Knowing how to manage file ownership is an important Linux skill and can
help you overcome problems later on.
One great reason to get up to speed about file access and ownership has to do with security. There are some important files in your Linux system that, as root operator, you don't want all users to have access to. If you've set up your system to handle dial-in calls, you'll want to make sure that important files, and even other mounted filesystems, such as DOS or Windows, are protected. If you share your computer, you normally wouldn't want other users to have access to your files, but on the other hand, you might want to share files with other people, but don't know how.
This hour starts with a discussion of the Linux file system.
Page 314
There's a difference between a file system and a filesystem. A file system is the layout of the directories and hierarchy of files on a partition. A filesystem is the layout of the lower-level format of a storage device. Linux recognizes a number of filesystems. You can find a list in the fstab, or filesystem table, manual page under the /usr/man/man5 directory, but it's best to look at the current list of supported systems in the mount command manual page. Why? Because the mount command is used to mount the filesystem at a mount point, or a path you specify. For now, take a look at the Linux file system.
The software that comes with the Linux kernel is from a variety of different UNIX systems. Some programs, utilities, and commands, like mail or printing, come from a UNIX distribution, called the Berkeley Software Distribution, or BSD. Other programs and methods of organizing software, such as startup scripts and organization of files used during startup, come from either AT&T System V UNIX or later variants. Because of this mixed heritage, Linux has a mix of directories, and although most pundits say Linux leans towards being System V-ish, you'll find elements of BSD and System V.
To give you a better idea, Listin 21.1 contains an edited directory listing, courtesy of the tree command.
Listing 21.1. The basic Linux file system, or directory tree.
/ - the root directory |-- bin - programs considered necessary |-- boot - Linux boot image |-- dev - devices, like serial ports, printers, hard drives |-- etc - configuration files for network, X11, mail, etc. |-- home - where users live (including sysadmin) |-- lib - software libraries |-- lost+found - recovered files (from e2fsck) |-- mnt - where you mount other filesystems | |-- cdrom | |-- dos | |-- flash | ´-- floppy |-- proc - kernel, device, process status files |-- root - where the sysadmin works, but doesn't live |-- sbin - system binaries (many root-only) |-- tmp - temp files stored, deleted from here |-- usr - hosts much, much software, libraries | |-- X11R6 - X Window System software | |-- bin - more software | |-- dict - dictionaries | |-- doc - FAQs, HOW-TOs, software documentation | |-- etc - software configuration files
Page 315
| |-- games - fun, fun, fun! | |-- i486-linuxaout | |-- include - header files for programming | |-- info - GNU information | |-- lib - more software libraries | |-- libexec | |-- local - programs not on CD-ROM | | |-- bin | | |-- doc | | |-- etc | | |-- games | | |-- info | | |-- lib | | |-- man | | |-- sbin | | ´-- src - source code to programs | |-- man - manual pages | | |-- man1..9n | |-- sbin | |-- share | |-- src - source for Linux!!! | | |-- linux -> linux-2.0.30 | | |-- linux-2.0.30 | ´-- tmp -> ../var/tmp ´-- var - system logs, compressed manual pages
As you can see, the main directory structure is not that complicated. What is important to understand here is that you should know where you are as you navigate the file system. When you install software, especially without the benefit of using Red Hat's rpm package-management command (which you'll learn about in Hour 22, "Red Hat Tools"), you should know where different software should reside on your system. Many programs will also require different software components to be installed in different parts of the directory.
If you look at the file system listing, you'll see a /mnt, or mount, directory. Although you don't have to use this directory as a gateway to other filesystems, this is traditionally where other systems are mounted. The next section discusses how to have these other systems appear under the mount directory.
The mount command, found under the /bin directory, is an essential program used not only by sysadmins, but also by Linux during startup and shutdown. This command is used to mount filesystems and make them available in the directory tree. During startup, the primary Linux partition, an ext2 filesystem, is mounted at the root filesystem, or /, directory.
Page 316
You can also have other filesystems automatically mounted when Linux starts, or you mount and unmount filesystems, using the mount and the umount commands, while you work. The Linux mount command recognizes and will mount (depending on how your kernel is configured) more than a dozen different filesystems. This section concentrates on the most common, such as ext2 for Linux, msdos for DOS or Windows, and iso9660 for CD-ROMs.
When you start Linux, one of the first scripts to run is the rc.sysinit script under the /etc/rc.d directory. This script mounts your Linux partition as read-write after it checks the partition for errors. Then, if everything is OK, it will mount all filesystems described in the filesystem table, fstab, under the /etc directory with the following command:
# mount -a -t nonfs
This mounts all filesystems described in the /etc/fstab (except for NFS filesystems; see the mount command manual page for details). The /etc/fstab file is a short text file:
# <device> <mountpoint> <filesystemtype> <options> <dump> <fsckorder> /dev/hda3 / ext2 defaults,usrquota 1 1 /dev/hdb /mnt/cdrom ignore 0 0 0 /dev/cdrom /mnt/cdrom iso9660 noauto,ro 0 0 /dev/hda1 /mnt/dos msdos defaults 0 0 /dev/hdc1 /mnt/flash msdos defaults 0 0 /dev/fd0 /mnt/floppy ext2 noauto 0 0 none /proc proc defaults /dev/hda2 none swap sw
The fstab columns show the device, where the filesystem will be mounted, the type of filesystem, any mount options, whether or not the dump command (discussed in Hour 23, "Archiving") needs to check for files to be archived, and the order in which the filesystem is checked during reboot.
The fstab rows show a Linux ext2 filesystem, which you configured to support quotas in the last hour; two CD-ROM devices (/dev/cdrom is a symbolic link to /dev/hdb); a DOS filesystem partition on the same hard drive as the Linux ext2 partition; a DOS filesystem on a flash RAM card; the floppy drive; the /proc directory (used internally by the Linux kernel); and finally, the Linux swap filesystem.