UNIX / Linux Tutorial

2.4 Managing File Systems  |  2.4.1 Mounting File Systems
2.4.2 Device Driver Names  |  2.4.3 Checking File Systems
2.5 Using A Swap File

2.4 Managing File Systems

Another task of the system administrator is caring for file systems. Most of this job
entails periodically checking the file systems for damage or corrupted files. Many Linux
systems also automatically check the file systems at boot time.

2.4.1 Mounting File Systems

Before a file system is accessible to the system, it must be mounted on a directory.
For example, if you have a file system on a floppy, you must mount it under a directory
like /mnt in order to access the files on the floppy. After mounting the file
system, all of the files in the file system appear in that directory. After unmounting the file
system, the directory (in this case, /mnt) will be empty.

The same is true of file systems on the hard drive. The system automatically mounts file
systems on your hard drive at bootup time. The so-called "root file system" is mounted 
on the directory /. If you have a separate file system for /usr, it is mounted on /usr. If you
only have a root file system, all files (including those in /usr) exist on that file system.
mount and umount (not unmount) are used to mount and unmount file systems. The
command:

               mount     -av

is executed automatically by the file /etc/rc at boot time, or by the file
/etc/rc.d/boot on some Linux systems. The file /etc/fstab provides
information on file systems and mount points. An example /etc/fstab file is:

       # device           directory        type       options
       /dev / hda2        /                ext2       defaults
       /dev/hda3          /usr             ext2       defaults
       /dev / hda4        none             swap       sw
       /proc              /proc            proc       none

The first field, device, is the name of the partition to mount. The second field is the
mount point. The third field is the file system type, like ext2 (for ext2fs) or minix (for
Minix file systems). Table 4.1 lists the various file system types that are mountable under
Linux.

Not all of these file system types may be available on your system, because the
kernel must have support for them compiled in. 


This table is current as of kernel version 2.0.33.

File system                     Type name     Comment
Second Extended File system     ext2          Most common Linux file system.
Extended File system            ext           Superseded by ext2.
Minix File system               minix         Original Minix file system; rarely used.
Xia File system                 xia           Like ext2, but rarely used.
UMSDOS File system              umsdos        Used to install Linux on an MS-DOS partition.
MS-DOS File system              msdos         Used to access MS-DOS files.
/proc File system               proc          Provides process information for ps,etc.
ISO 9660 File system            iso9660       Format used by most CD-ROMs.
Xenix File system               xenix         Used to access files from Xenix.
System V File system            sysv          Used to access files from System V variants for
                                              the x86.
Coherent File system            coherent      Used to access files from Coherent.
HPFS File system                hpfs          Read-only access for HPFS partitions 
                                              (DoubleSpace).

                    Table 2.1: Linux File system Types

The last field of the fstab file are the mount options. This is normally set to
defaults.

Swap partitions are included in the /etc/fstab file. They have a mount directory
of none, and type swap.Theswapon -a command, which is executed from /etc/rc
or /etc/init.d/boot, is used to enable swapping on all of the swap devices that are
listed in /etc/fstab.

The /etc/fstab file contains one special entry for the /proc file system. The /proc file 
system is used to store information about system processes, available memory, and so on. 
If /proc is not mounted, commands like ps will not work.

The mount command may be used only by root. This ensures security on the system. 
You wouldn't want regular users mounting and unmounting file systems on a whim. Several
software packages are available which allow non-root users to mount and unmount file
systems, especially floppies, without compromising system security.

The mount -av command actually mounts all of the file systems other than the
root file system (in the table above, /dev/hda2). The root file system is automatically
mounted at boot time by the kernel.

Instead of using mount -av, you can mount a file system by hand. The command:

                        # mount -t ext2 /dev/hda3 /usr

is equivalent to mounting the file system with the entry for /dev/hda3 in the example
/etc/fstab file, above.

2.4.2 Device Driver Names

In addition to the partition names listed in the /etc/fstab file, Linux recognizes a
number of fixed and removable media devices. They are classified by type, interface, and
the order they are installed. For example, the first hard drive on your system, if it is an 
IDE or older MFM hard drive, is controlled by the device driver pointed to by /dev/hda.The
first partition on the hard drive is /dev/hda1, the second partition is /dev/hda2, the
third partition is /dev/hda3, and so on. The first partition of the second IDE drive is
often /dev/hdb1, the second partition /dev/hdb2, and so on. The naming scheme for
the most commonly installed IDE drives for Intel-architecture, ISA and PCI bus machines,
is given in Table 4.2.

                  Device driver          Drive
                  /dev/hda               Master IDE drive, primary IDE bus.
                  /dev/hdb               Slave IDE drive, primary IDE bus.
                  /dev/hdc               Master IDE drive, secondary IDE bus.
                  /dev/hdd               Slave IDE drive, secondary IDE bus.

           Table 2.2: IDE device driver names

CD-ROM and tape drives which use the extended IDE/ATAPI drive interface also use
these device names.

Many machines, however, including high-end personal computer workstations, and machines
based on Digital Equipment Corporation's Alpha processor, use the Small Computer
System Interface (SCSI). The naming conventions for SCSI devices are somewhat different
than that given above, due the greater flexibility of SCSI addressing. The first SCSI hard
drive on a system is /dev/sda, the second SCSI drive is /dev/sdb, and so on. 

Note that SCSI CD-ROM and tape drives are named differently than SCSI hard drives.
Removable SCSI media, like the Iomega Zip drive, follow naming conventions for non-
removable SCSI drives :

                   Device driver         Drive
                   /dev/sda              First SCSI hard drive.
                   /dev/sdb              Second SCSI hard drive.
                   /dev/st0              First SCSI tape drive.
                   /dev/st1              Second SCSI tape drive.
                   /dev/scd0             First SCSI CD-ROM drive.
                   /dev/scd1             Second SCSI CD-ROM drive.

Table 2.3: SCSI device drivers

Floppy disk drives use still another naming scheme, outlined elsewhere in this tutorial.

2.4.3 Checking File Systems

It is usually a good idea to check your file systems for damaged or corrupted files every
now and then. Some systems automatically check their file systems at boot time (with the
appropriate commands in /etc/rc or /etc/init.d/boot).

The command used to check a file system depends on the type of the file system. For
ext2fs file systems (the most commonly used type), this command is e2fsck. For example,
the command:

                    #  e2fsck   -av  /   dev  /  hda 2

checks the ext2fs file system on /dev/hda2 and automatically corrects any errors.

It is usually a good idea to unmount a file system before checking it, and necessary, if
e2fsck is to perform any repairs on the file system. The command:

                     # umount /dev/hda2

unmounts the file system on /dev/hda2. The one exception is that you cannot unmount
the root file system. In order to check the root file system when it's unmounted, you should
use a maintenance boot/root diskette. You also cannot unmount a file system if any of the 
files which it contains are "busy"—that is, in use by a running process. 
For example, you cannot unmount a file system if any user's current working directory is on
that file system. You will instead receive a "Device busy" error message.

Other file system types use different forms of the e2fsck command, like efsck and
xfsck. On some systems, you can simply use the command fsck, which automatically
determines the file system type and executes the appropriate command.

If e2fsck reports that it performed repairs on a mounted file system, you must reboot 
the system immediately. You should give the command shutdown -r to perform the
reboot. This allows the system to re-synchronize the information about the file system after
e2fsck modifies it.

The /proc file system never needs to be checked in this manner. /proc is a memory
file system and is managed directly by the kernel.

2.5 Using A Swap File

Instead of reserving a separate partition for swap space, you can use a swap file. However,
you need to install Linux and get everything running before you create the swap file.

With Linux installed, you can use the following commands to create a swap file. The
command below creates a swap file of size 8208 blocks (about 8 Mb) :

                       # dd if=/dev/zero of=/swap bs=1024 count=8208

This command creates the swap file, /swap.The"count=" parameter is the size of the
swap file in blocks :

                      # mkswap /swap 8208

This command initializes the swap file. Again, replace the name and size of the swapfile
with the appropriate values :

                      # sync

                      # swapon /swap

Now the system is swapping on the file /swap.The sync command ensures that the file
has been written to disk.

One major drawback to using a swap file is that all access to the swap file is done
through the file system. This means the blocks which make up the swap file may not be
contiguous. Performance may not be as good as a swap partition, where the blocks are
always contiguous and I/O requests are made directly to the device.

Another drawback of large swap files is the greater chance that the file system will be
corrupted if something goes wrong. Keeping the regular file systems and swap partitions
separate prevents this from happening.

Swap files can be useful if you need to use more swap space temporarily. If you're
compiling a large program and would like to speed things up somewhat, you can create a
temporary swap file and use it in addition to the regular swap space.

To remove a swap file, first use swapoff, as in:

                     #  swapoff  / swap

Then the file can be deleted:

                    #  rm  / swap

Each swap file or partition may be as large as 128 megabytes, but you may use up to 8
swap files or partitions on your system.

HOME

1.1 Introduction   1.2.10 Referring To Home Directories   1.3.4  Copying Files

1.6 Exploring The File System   1.8   Wildcards   1.9.3 Pipes   1.10.3 Permissions Dependencies

1.12.4  Stopping And Restarting Jobs   1.13.3 Inserting Text   1.13.9 Including Other Files

1.14.3 Shell Initialization Scripts   System Administration   2.3.1 The /etc/imitate file

2.4 Managing File Systems   2.6 Managing Users  2.6.5 Groups   2.7.2 gzip and compress

2.8.3 Making Backups To Tape Devices   2.9.1 Upgrading The Kernel   

2.9.3 Installing A Device Driver Module

BOOK: LINUX QUICK COMMAND REFERENCE

http://personal.atl.bellsouth.net/~psadler

© copyright KnowledgeWorks, Inc. (2001)