Filesystems


Table 12-1 lists some of the types of filesystems available under Linux.

Table 12-1. Filesystems

Filesystem

Features

adfs

Advanced Disc Filing System. Used on Acorn computers. The word Advanced differentiated this filesystem from its predecessor, DFS, which did not support advanced features such as a hierarchical filesystem.

affs

Amiga Fast Filesystem (FFS).

autofs

Automounting filesystem (page 690).

coda

CODA distributed filesystem (developed at Carnegie Mellon).

devpts

A pseudofilesystem for pseudoterminals (page 449).

ext2

A standard filesystem for Red Hat systems, usually with the ext3 extension.

ext3

A journaling (page 1039) extension to the ext2 filesystem. It greatly improves recovery time from crashes (it takes a lot less time to run fsck), promoting increased availability. As with any filesystem, a journaling filesystem can lose data during a system crash or hardware failure.

GFS

Global Filesystem. GFS is a journaling, clustering filesystem. It enables a cluster of Linux servers to share a common storage pool.

hfs

Hierarchical Filesystem: used by older Macintosh systems. Newer Macintosh systems use hfs+.

hpfs

High-Performance Filesystem: the native filesystem for IBM's OS/2.

iso9660

The standard filesystem for CD-ROMs.

minix

Very similar to Linux, the filesystem of a small operating system that was written for educational purposes by Andrew S. Tanenbaum (www.minix3.org).

msdos

The filesystem used by DOS and subsequent Microsoft operating systems. Do not use msdos for mounting Windows filesystems; it does not read VFAT attributes.

ncpfs

Novell NetWare NCP Protocol Filesystem: used to mount remote filesystems under NetWare.

nfs

Network Filesystem. Developed by Sun Microsystems, this protocol allows a computer to access remote files over a network as if they were local (page 673).

ntfs

NT Filesystem: the native filesystem of Windows NT.

proc

An interface to several Linux kernel data structures (page 1028) that behaves like a filesystem (page 457).

qnx4

QNX 4 operating system filesystem.

reiserfs

A journaling (page 1039) filesystem, based on balanced-tree algorithms. See ext3 for more on journaling filesystems.

romfs

A dumb, readonly filesystem used mainly for RAM disks (page 1051) during installation.

smbfs

Samba Filesystem (page 695).

software RAID

RAID implemented in software. Refer to "RAID Filesystem" on page 473.

sysv

System V UNIX filesystem.

ufs

Default filesystem under Sun's Solaris operating system and other UNIXs.

umsdos

A full-feature UNIX-like filesystem that runs on top of a DOS FAT filesystem.

vfat

Developed by Microsoft, a standard that allows long filenames on FAT partitions.

xfs

SGI's journaled filesystem (ported from Irix).


mount: Mounts a Filesystem

The mount utility connects directory hierarchiestypically filesystemsto the Linux directory hierarchy. These directory hierarchies can be on remote and local disks, CDs, and floppy diskettes. Linux also allows you to mount virtual filesystems that have been built inside ordinary files, filesystems built for other operating systems, and the special /proc filesystem (page 457), which maps useful Linux kernel information to a pseudodirectory.

Mount point


The mount point for the filesystem/directory hierarchy that you are mounting is a directory in the local filesystem. This directory must exist before you can mount a filesystem; its contents disappear as long as a filesystem is mounted on it and reappear when you unmount the filesystem.

Without any arguments, mount lists the currently mounted filesystems, showing the physical device holding each filesystem, the mount point, the type of filesystem, and any options set when each filesystem was mounted:

$ mount proc on /proc type proc (rw) /dev/hdb1 on / type ext2 (rw) /dev/hdb4 on /tmp type ext2 (rw) /dev/hda5 on /usr type ext3 (rw) /dev/sda1 on /usr/X386 type ext2 (rw) /dev/sda3 on /usr/local type ext2 (rw) /dev/hdb3 on /home type ext3 (rw) /dev/hda1 on /dos type msdos (rw,umask=000) tuna:/p04 on /p04 type nfs (rw,addr=192.168.0.8) /dev/scd0 on /mnt/cdrom type iso9660 (ro,noexec,nosuid,nodev)


The mount utility gets this information from the /etc/mtab file (page 453). This section covers mounting local filesystems; refer to page 673 for information on using NFS to mount remote directory hierarchies.

The first entry in the preceding example shows the /proc pseudofilesystem (page 457). The next six entries identify disk partitions holding standard Linux ext2 and ext3 filesystems. These partitions are found on three disks: two IDE disks (hda, hdb) and one SCSI disk (sda). Disk partition /dev/hda1 has a DOS (msdos) filesystem mounted at the directory /dos in the Linux filesystem. You can access the DOS files and directories on this partition as if they were Linux files and directories, using Linux utilities and applications. The line starting with tuna shows a mounted, remote NFS filesystem. The last line shows a CD mounted on a SCSI CD drive (/dev/scd0).

If the list of filesystems in /etc/mtab is not correct, see the tip on page 453.

When you add a line for a filesystem to the /etc/fstab file (page 451), you can mount that filesystem by giving the associated mount point (or the device) as the argument to mount. For example, the SCSI CD listed earlier was mounted using the following command:

$ mount /mnt/cdrom


Caution: Do not mount anything on root ( / )

Always mount network directory hierarchies and removable devices at least one level below the root level of the filesystem. The root filesystem is mounted on /; you cannot mount two filesystems in the same place. If you were to try to mount something on /, all files, directories, and filesystems that were under the root directory would no longer be available, and the system would crash.


This command worked because /etc/fstab contains the additional information needed to mount the file:

/dev/scd0             /mnt/cdrom             iso9660 user,noauto,ro 0 0


You can also mount filesystems that do not appear in /etc/fstab. For example, when you insert a floppy diskette that holds a DOS filesystem into the floppy diskette drive, you can mount that filesystem using the following command:

# mount t msdos /dev/fd0 /mnt/floppy


The t msdos specifies a filesystem type of msdos. You can mount DOS filesystems only if you have configured the Linux kernel (page 525) to accept DOS filesystems. You do not need to mount a DOS filesystem to read from and write to it, such as when you use mcopy (page 139). However, you do need to mount a DOS filesystem to use Linux commands (other than Mtools commands) on files on the filesystem (which may be on a diskette).

Mount Options

The mount utility takes many options, which you can specify on the command line or in the /etc/fstab file (page 469). For a complete list of mount options for local filesystems, see the mount man page; for remote directory hierarchies, see the nfs man page.

The noauto option causes Linux not to mount the filesystem automatically. The nosuid option forces mounted setuid executables to run with regular permissions (no effective user ID change) on the local system (the system that mounted the filesystem).

Security: Mount removable devices with the nosuid option

Always mount removable devices with the nosuid option so that a malicious user does not, for example, put a setuid copy of bash on a disk and have a root shell.


Unless you specify the user, users, or owner option, only Superuser can mount and unmount a filesystem. The user option means that any user can mount the filesystem, but the filesystem can be unmounted only by the same user who mounted it; users means that any user can mount and unmount the filesystem. These options are frequently specified for CD and floppy drives. The owner option, which is used only under special circumstances, is similar to the user option except that the user mounting the device must own the device.

Mounting a Linux Floppy Diskette

Mounting a Linux floppy diskette is similar to mounting a partition of a hard disk. Put an entry similar to the following in /etc/fstab for a diskette in the first floppy drive:

/dev/fd0    /mnt/floppy     auto    noauto,users               0 0


Specifying a filesystem type of auto causes the system to probe the filesystem to determine its type and allows users to mount a variety of diskettes. Create the /mnt/floppy directory if necessary. Insert a diskette and try to mount it. The diskette must be formatted (use fdformat). In the following examples, the error message following the first command usually indicates there is no filesystem on the diskette. Use mkfs (page 419) to create a filesystembut be careful, because mkfs destroys all data on the diskette:

# mount /dev/fd0 mount: you must specify the filesystem type # mkfs /dev/fd0 mke2fs 1.38 (30-Jun-2005) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) 184 inodes, 1440 blocks 72 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=1572864 1 block group 8192 blocks per group, 8192 fragments per group 184 inodes per group Writing inode tables: done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 24 mounts or 180 days, whichever comes first.  Use tune2fs -c or -i to override.


Try the mount command again:

# mount /dev/fd0 # mount ... /dev/fd0 on /mnt/floppy type ext2 (rw,noexec,nosuid,nodev) # df -h /dev/fd0 Filesystem            Size  Used Avail Use% Mounted on /dev/fd0              1.4M   19K  1.3M   2% /mnt/floppy


The mount command without any arguments and df h /dev/fd0 show the floppy is mounted and ready for use.

umount: Unmounts a Filesystem

The umount utility unmounts a filesystem as long as it does not contain any files or directories that are in use (open). For example, a logged-in user's working directory must not be on the filesystem you want to unmount. The next command unmounts the CD mounted earlier:

$ umount /mnt/cdrom


Unmount a floppy or a remote directory hierarchy the same way you would unmount a partition of a hard drive.

The umount utility consults /etc/fstab to get the necessary information and then unmounts the appropriate filesystem from its server. When a process has a file open on the filesystem that you are trying to unmount, umount displays a message similar to the following:

umount: /home: device is busy


Tip: When you cannot unmount a device because it is in use

When a process has a file open on a device you need to unmount, use fuser to determine which process has the file open and to kill it. For example, when you want to unmount the floppy diskette, give the command fuser ki /mnt/floppy (substitute the mount point for the diskette on the local system for /mnt/floppy. After checking with you, this command kills the process using the diskette.


Use the a option to umount to unmount all filesystems, except for the one mounted at /, which can never be unmounted. You can combine a with the t option to unmount filesystems of a given type (ext3, nfs, or others). For example, the following command unmounts all mounted nfs directory hierarchies that are not being used:

# umount -at nfs


fstab: Keeps Track of Filesystems

The system administrator maintains the /etc/fstab file, which lists local and remote directory hierarchies, most of which the system mounts automatically when it boots. The fstab file has six columns; a hyphen keeps the place of a column that has no value:

  1. Name The name of the block device (page 463) or remote directory hierarchy. A remote directory hierarchy appears as hostname:pathname, where hostname is the name of the host that houses the filesystem, and pathname is the absolute pathname of the directory that is to be mounted. You can substitute the volume label of a local filesystem by using the form LABEL=xx, where xx is the volume label. Refer to e2label on page 418.

  2. Mount point The name of a directory file that the filesystem/directory hierarchy is to be mounted on. If it does not already exist, create this directory with mkdir.

  3. Type The type of filesystem/directory hierarchy that is to be mounted. Local filesystems are generally of type ext2 or ext3, and remote directory hierarchies are of type nfs. Table 12-1 on page 464 provides a list of filesystem types.

  4. Mount options A comma-separated list of mount options, such as whether the filesystem is mounted for reading and writing (rw, the default) or readonly (ro). Refer to the mount and nfs man pages for lists of options.

  5. Dump Used by dump (page 545) to determine when to back up the filesystem.

  6. Fsck Specifies the order in which fsck checks filesystems. Root (/) should have a 1 in this column. Filesystems that are mounted to a directory just below the root directory should have a 2. Filesystems that are mounted on another mounted filesystem (other than root) should have a 3. For example, if local is a separate filesystem from /usr and local is mounted on /usr (as /usr/local), then local should have a 3. Filesystems and directory hierarchies that do not need to be checked (for example, remotely mounted directory hierarchies or a CD) should have a 0.

The following example shows a typical fstab file:

# cat /etc/fstab LABEL=/1                /                       ext3    defaults         1 1 LABEL=/boot1            /boot                   ext3    defaults         1 2 devpts                  /dev/pts                 devpts  gid=5,mode=620  0 0 tmpfs                   /dev/shm                tmpfs   defaults         0 0 LABEL=/home1            /home                   ext3    defaults         1 2 proc                    /proc                   proc    defaults         0 0 sysfs                   /sys                    sysfs   defaults         0 0 LABEL=SWAP-hda5         swap                    swap    defaults         0 0 /dev/hda3               /oldhome                ext3    defaults         0 0 tuna:/p04               /p04                    nfs     defaults         0 0 /dev/fd0                /mnt/floppy             auto    noauto,users     0 0


fsck: Checks Filesystem Integrity

The fsck (filesystem check) utility verifies the integrity of filesystems and, if possible, repairs any problems it finds. Because many filesystem repairs can destroy data, particularly on a nonjournaling filesystem (page 1039), such as ext2, by default fsck asks you for confirmation before making each repair.

Caution: Do not run fsck on a mounted filesystem

Do not run fsck on a mounted filesystem (except /). When you attempt to check a mounted filesystem, fsck warns you and asks you whether you want to continue. Reply no. You can run fsck with the N option on a mounted filesystem as it will not write to the filesystem; as a result, no harm can come of running it.


The following command checks all unmounted filesystems that are marked to be checked in /etc/fstab (page 451) except for the root filesystem:

# fsck -AR


You can check a specific filesystem with a command similar to one of the following:

# fsck /home


or

# fsck /dev/hda6


Crash flag


The /etc/rc.d/rc.sysinit start-up script looks for two flags in the root directory of each partition to determine whether fsck needs to be run on that partition before it is mounted. The .autofsck flag (the crash flag) indicates that the partition should be checked. By default, the person bringing up the system has 5 seconds to respond to a prompt with a y; if no response is made, the check is skipped. When the other flag, forcefsck, is set, the user is given no choice; fsck is automatically run on the partition. These checks are in addition to those established by tune2fs (see next section). The .autofsck flag is present while the system is running and is removed when the system is properly shut down. When the system crashes, the flag is present when the system is brought up. The forcefsck flag is placed on the filesystem when the disk contains an error and must be checked.

tune2fs: Changes Filesystem Parameters

The tune2fs utility displays and modifies filesystem parameters on ext2 filesystems and on ext3 filesystems, as they are modified ext2 filesystems. This utility can also set up journaling on an ext2 filesystem, turning it into an ext3 filesystem. With the introduction of increasingly more reliable hardware and software, systems are rebooted less frequently, so it is important to check filesystems regularly. By default, fsck is run on each partition while the system is brought up, before the partition is mounted. (The checks scheduled by tune2fs are separate and scheduled differently from the checks that are done following a system crash or hard disk error [see the previous section].) Depending on the flags, fsck may do nothing more than display a message saying that the filesystem is clean. The larger the partition, the more time it takes to check it, assuming a nonjournaling filesystem. These checks are often unnecessary. The tune2fs utility helps you to find a happy medium between checking filesystems each time you reboot the system and never checking them. It does so by scheduling when fsck checks a filesystem (these checks occur only when the system is booted).[1] You can use two scheduling patterns: time elapsed since the last check and number of mounts since the last check. The following command causes /dev/hda6 to be checked when fsck runs after it has been mounted eight times or after 15 days have elapsed since its last check, whichever happens first:

[1] For systems whose purpose in life is to run continuously, this kind of scheduling does not work. You must develop a schedule that is not based on system reboots but rather on a clock. Each filesystem must be unmounted periodically, checked with fsck (preceding section), and then remounted.

# tune2fs -c 8 -i 15 /dev/hda3 tune2fs 1.38 (30-Jun-2005) Setting maximal mount count to 8 Setting interval between checks to 1296000 seconds


The next tune2fs command is similar but works on a different partition and sets the current mount count to 4. When you do not specify a current mount count, it is set to zero:

# tune2fs -c 8 -i 15 -C 4 /dev/hda3 tune2fs 1.38 (30-Jun-2005) Setting maximal mount count to 8 Setting current mount count to 4 Setting interval between checks to 1296000 seconds


The l option displays a list of information about the partition. You can combine this option with others. Below the Maximum mount count is 1, which means that fsck and the kernel ignore the mount count information. A maximum mount count of 0 works the same way:

# tune2fs -l /dev/hda3 tune2fs 1.38 (30-Jun-2005) Filesystem volume name:    /home Last mounted on:          <not available> Filesystem UUID:          70929327f5d2486abe446f7b677ab6b6 Filesystem magic number:  0xEF53 Filesystem revision #:    1 (dynamic) Filesystem features:      has_journal ext_attr resize_inode dir_index         filetype needs_recovery sparse_super large_file Default mount options:    (none) Filesystem state:          clean Errors behavior:          Continue Filesystem OS type:        Linux Inode count:               2560864 Block count:               2560359 ... Last mount time:           Wed Jan 25 08:33:30 2006 Last write time:           Wed Jan 25 10:13:27 2006 Mount count:               4 Maximum mount count:       8 Last checked:              Tue Jun 28 03:03:55 2005 Check interval:            1296000 (2 weeks, 1 day) ...


Set the filesystem parameters on the local system so that they are appropriate to the way you use it. Using the C option to stagger the checks ensures that all checks do not occur at the same time. Always check new and upgraded filesystems to make sure that they have checks scheduled as you desire.

To change an ext2 filesystem to an ext3 filesystem, you must put a journal (page 1039) on the filesystem, and the kernel must support ext3 filesystems. Use the j option to set up a journal on an unmounted filesystem:

# tune2fs -j /dev/hda7 tune2fs 1.38 (30-Jun-2005) Creating journal inode: done This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first.  Use tune2fs -c or -i to override.


Before you can use fstab (page 451) to mount the changed filesystem, you must modify its entry in the fstab file to reflect its new type. Change the third column to ext3.

The following command changes an unmounted ext3 filesystem to an ext2 filesystem:

# tune2fs -O ^has_journal /dev/hda7 tune2fs 1.38 (30-Jun-2005)


Refer to the tune2fs man page for more details.

RAID Filesystem

RAID (Redundant Arrays of Inexpensive/Independent Disks) spreads information across several disks to combine several physical disks into one larger virtual device. RAID improves performance and creates redundancy. More than six types of RAID configurations exist. Using Red Hat tools, you can set up software RAID. Hardware RAID requires hardware that is designed to implement RAID and is not covered here.

Caution: Do not replace backups with RAID

Do not use RAID as a replacement for regular backups. If your system experiences a catastrophic failure, RAID will be useless. Earthquake, fire, theft, or another disaster may leave your entire system inaccessible (if your hard drives are destroyed or missing). RAID does not take care of something as simple as replacing a file when you delete it by accident. In these cases a backup on a removable medium (that has been removed) is the only way you will be able to restore a filesystem.


RAID can be an effective addition to a backup. Red Hat offers RAID software that you can install either when you install a Red Hat system or as an afterthought. The Linux kernel can automatically detect RAID disk partitions at boot time if the partition ID is set to 0xfd, which fdisk recognizes as Linux raid autodetect.

Software RAID, as implemented in the kernel, is much cheaper than hardware RAID. Not only does this software avoid specialized RAID disk controllers, but it also works with the less expensive IDE disks as well as SCSI disks. For more information refer to the Software-RAID HOWTO.




A Practical Guide to Red Hat Linux
A Practical Guide to Red HatВ® LinuxВ®: Fedoraв„ў Core and Red Hat Enterprise Linux (3rd Edition)
ISBN: 0132280272
EAN: 2147483647
Year: 2006
Pages: 383

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