Managing File Systems


The ability to manage the configuration and availability of file systems is an important system administration skill, particularly for systems heavily involved in a network's infrastructure. At various times, you might need to configure and add an additional hard drive to a server system or provide system services with access to files on a separate file server. For these types of tasks, you need to know how to create, mount, and unmount file systems.

Creating a file system refers to the process by which a hard drive or other storage device is made ready to store files (this process is often called formatting in other operating systems). Mounting a file system refers to the process of making the contents of a device or network share available to users and processes within the Linux file system. Unmounting a file system refers to the process of disconnecting a device or network share and its contents from the Linux file system.

These Sections Assume Knowledge of PC Hardware

Much of the rest of the "Managing File Systems" subsections assume that you have some familiarity with PC hardware, such as hard drives, removable storage devices, and SCSI hardware. If this is not the case, you might need to refer to additional sources of information about PC hardware to make use of the information presented here.


Creating File Systems

Before you can mount and use a new or empty storage device like a hard drive, Zip or Jaz disk, or other removable storage device with Linux, you must create a file system on it. For purposes of example, let's build an ext2 file system in this chapter.

Other Tools for Dealing with Linux File Systems

If you prefer to use metadata-journaled file systems, such as ext3 or reiserfs, or file systems associated with other operating systems, such as vfat or minix, you need to refer to the fdisk and mkfs commands and man pages instead of using parted. For most Linux users interested in general-purpose data storage, however, the ext2 file system and parted command work well.


Two major steps are involved in creating a new ext2 file system for use with Linux:

1.

Identify the name of the device where the new file system is to be created.

2.

Create a partition on the device and format that partition using the desired type of file system, such as a Linux ext3 file system or a Windows FAT32 file system.

The name of the device where the new file system and partition are to be created depends on the type of device and the type of connection through which the device communicates with your computer system. Most often, the device is connected either through an IDE channel or a SCSI controller.

  • For IDE devices, the name of the device is /dev/hda, /dev/hdb, /dev/hdc, or /dev/hdd, depending on whether the device is connected to the primary master, primary slave, secondary master, or secondary slave channels, respectively.

  • For SCSI devices, the name of the device is /dev/sda tHRough /dev/sdg (or higher) depending on two factorsthe position of the device in the SCSI ID chain and the number of earlier storage devices present. The first SCSI hard drive or random-writable (that is, not CD-R, CD-RW, or tape) device found is /dev/sda, the second is /dev/sdb, and so on, regardless of the absolute SCSI ID number.

After you identify the device on which you want to create a new file system for use with Linux, you call parted with the device name as an argument followed by the print option to display information about the device's size and any existing partitions that might reside on it:

 [root@workstation20 you]# /sbin/parted /dev/sdb print Disk geometry for /dev/sdb: 0.000-3992.717 megabytes Disk label type: msdos Minor  Start  End        Type     Filesystem Flags 1      0.031  3992.717   primary  FAT Information: Don't forget to update /etc/fstab, if necessary. [root@workstation20 ~]$ 

In this particular example, one existing partition of the FAT (Windows) type must be removed before a new partition or file system can be created. The first column indicates that this is partition 1 on the device /dev/sdb. To remove it, use parted with the rm option and the number of the partition to remove as an argument. Then call parted with the print option to verify that the partition has been removed:

 [root@workstation20 you]# /sbin/parted /dev/sdb rm 1 [root@workstation20 you]# /sbin/parted /dev/sdb print Disk geometry for /dev/sdb: 0.000-3992.717 megabytes Disk label type: msdos Minor  Start    End   Type   Filesystem Flags Information: Don't forget to update /etc/fstab, if necessary. [root@workstation20 you]# 

What If You Get an Unrecognized Disk Label Error?

If you are attempting to create a file system on a brand new disk, the print option of parted might give you an "unrecognized disk label" error. If this is the case, you need to run the following command first and then proceed with the print option and the rest of this section:

 /sbin/parted /dev/sdb mklabel msdos 

This command prepares the disk for use on a standard PC computer with Linux; you can then partition and create file systems on the disk as usual.


Deleting Partitions

When you are deleting partitions, be sure that you do not delete partitions on the wrong device. You don't want to lose valuable files on a device you're already using!


With existing partitions removed, you are free to create new partitions. This is done using the parted command as follows:

 parted device mkpartfs primary fstype begin end 

Replace device with the device name where you're creating a new file system, fstype with either fat (for a Windows file system) or ext2 (for a Linux file system), and begin and end with the begin and end positions of the new partition, in megabytes.

For example, to create a Linux file system the size of the entire disk shown in the examples thus far, you issue the following parted command:

 [root@workstation20 you]# /sbin/parted /dev/sdb mkpartfs primary ext2 0 3992.717 [root@workstation20 you]# /sbin/parted /dev/sdb print Disk geometry for /dev/sdb: 0.000-3992.717 megabytes Disk label type: msdos Minor  Start    End   Type     Filesystem Flags 1     0.031  3992.717 primary  ext2 Information: Don't forget to update /etc/fstab, if necessary. [root@workstation20 you]# 

You can create up to four partitions on any device using this technique; Linux and Windows partitions can be freely intermixed.

Don't Make Partitions That Overlap!

You must be sure that you do not cause partitions to overlap. For example, if you create a partition from 0300MB, your second partition must not begin earlier than 301MB. If you try to cause partitions to overlap, you receive an error message.


File systems you create this way are referred to by appending their partition number to the device name. For example, when you learn to mount file systems in the next section, you mount the first partition on /dev/sdb by referring to /dev/sdb1, the second partition by referring to /dev/sdb2, and so on.

Creating an ext3 Partition?

When you use parted, you create an ext2 filesystem. This basic Linux filesystem type is fast and very reliable, but is subject in very, very rare circumstances to filesystem corruption caused by brownouts or similar situations in which Linux is suddenly and improperly shut down.

The slower ext3 filesystem is nearly corruption-proof except in cases of hardware failure, and might thus be more appropriate for mission-critical and server environments. To create an ext3 filesystem once you have used parted to create a partition, use the mkfs.ext3 command in conjunction with the full device name of the partition you just created, as discussed earlier. For example, to make an ext3 filesystem on partition number 2 of /dev/sdb, enter

 /sbin/mkfs.ext3 /dev/sdb2 


For More Detailed parted Instructions…

For comprehensive documentation of the parted command, visit the online parted manual, which can be found in the alphabetically sorted online list of GNU manuals at http://www.gnu.org/manual/.


Mounting and Unmounting File Systems

Whether you want to access a newly created file system, the data on an existing device or file system, or the data on a network share, in the Linux operating system, you must first mount a data storage area before you are able to read from or write to it. Some more common data storage areas, like those on USB keys or CD-ROM drives, are automatically mounted by Fedora Core 4 and appear instantly on the desktop when connected. For those that aren't automatically mounted, however, the following four steps must be performed:

1.

You must create or identify a mountpoint. This is an empty directory somewhere in your existing Linux file system that you choose and/or create where the contents of the new data storage area will eventually be accessed.

2.

You must identify the device name or network source of the data area. If you have just created a file system on a disk device in the previous section and now want to mount it, you use a device name like /dev/hda1 or /dev/sda1. If you are mounting a network file system, this is supplied by your network administrator and is a hostname followed by a path, such as fileserver.mycompany.com:/pub/storagearea.

3.

You must identify the type of file system you are mounting. For nearly all Windows file systems, including removable devices such as floppy disks or Zip disks, this is vfat. For Linux file systems, this is usually ext2, ext3, or reiserfs. For networked file systems, this is usually nfs. For CD-ROM devices, this is iso9660, and for DVD devices, it's udf. If in doubt, contact your media provider or network administrator.

4.

You must issue a correctly formed mount command to supply all the following information to Linux so that the data or storage area can be available to you.

The format of the mount command is as follows:

 mount -t fstype [-o options] datasource mountpoint 

Replace fstype with the type of file system (vfat, ext2, ext3, reiserfs, nfs, iso9660, udf, or other type you have been instructed to use). Replace datasource with the device name (/dev/hda1, /dev/sda1, and so forth) or network path (address:/path). Replace mountpoint with the place in your local file system where this data or this storage area is to appear. The -o options option is not required but can be used to provide additional options, usually one of the following:

  • -o ro specifies that the file system should be mounted read-only. Any attempts to write to it by anyone (even the root user) will fail. Note that CD-ROM devices are always mounted read-only, whether or not you supply this option.

  • -o umask=0000 is used with Windows FAT32 file systems to allow all users to read and write any data on this device. Use this option with extreme caution; it allows any user to remove any file on the file system in question! This option is generally used on personal Linux computers that dual-boot with Windows, to allow all the Windows files on a mounted Windows hard drive to be accessed by normal user accounts.

Additional options can be found in the man page for the mount command.

To illustrate, if you want to mount the ext2 file system you created on /dev/sdb1 in the previous section to a new directory called /publicspace, you first create /publicspace and then issue the mount command supplying all three as arguments:

 [root@workstation20 you]# mkdir /publicspace [root@workstation20 you]# mount -t ext2 /dev/sdb1 /publicspace [root@workstation20 you]# 

The contents of the device /dev/sdb1 can now be accessed or modified by reading or writing to files or directories in the /publicspace tree. To verify that this is the case, you can print the list of mounted file systems by entering the mount command without arguments:

 [root@workstation20 you]# mount /dev/sda2 on / type ext3 (rw) none on /proc type proc (rw) usbdevfs on /proc/bus/usb type usbdevfs (rw) /dev/sda1 on /boot type ext3 (rw) none of /dev/pts type devpts (rw,gid=5,mode=620) none on /dev/shm type tmpfs (rw) /dev/sdb1 on /publicpsace type ext2 (rw) [root@workstation20 you]# 

When the mount command is called without arguments, each line of output contains the device or resource, the mountpoint, the file system type, and any options the device has been mounted with, in that order. Complete documentation for file system types and options can be found in the mount manual page.

How Much Space Is Left on This Disk?

Another command, df, tells you how much free space is available on each mounted device, as well as how much data has already been stored there. If you want to know how close you are to filling up one of your hard drives or another removable device, try using the df command without arguments to get a status report.


You can unmount a mounted file system with the umount command. The umount command simply needs one argument: either the name of the device or resource to unmount, or the name of the mountpoint where the device or resource was mounted. For example, considering the mount commands we've issued in this section, the following two umount commands are equivalent:

 umount /dev/sdb1 umount /publicspace 

After you unmount a device or resource, you can verify that it no longer appears in the mounted file systems list by using the mount or df commands without arguments.

What Is a Device Is Busy Error?

If, while attempting to unmount a file system, you get a device is busy error, it means that some process or some user's current working directory still resides within that file system, or some process is still using a file stored on that file system. Until the user or process changes the current working directory or the open file is closed, you cannot unmount the file system.


Maintaining the /etc/fstab File

The /etc/fstab file is a list of devices and resources, file system types, and mountpoints that control which file systems are mounted when the computer starts. This file also lists which file systems are mountable and unmountable by regular users. Each line in the /etc/fstab file represents one mounted or mountable file system, and each line is formatted as follows:

 device mountpoint fstype option1,option2,.. dump fscklvl 

Each of the fields in this file is described in Table 28.4.

Table 28.4. Fields in the /etc/fstab File

Field

Description

device

The name of the device or resource that contains the file system to which this line applies.

mountpoint

The place where the file system should be mounted within the local file system tree.

fstype

The type of file system, usually vfat (for Windows devices), nfs (for networked file systems), ext2, ext3, reiserfs, iso9660, or udf.

options

A comma-separated list of options, as listed in the man page for the mount command. Common options include user and owner, which let normal users mount and unmount the device; noauto, which prevents the device from being automatically mounted at start time; and defaults, which means that no special options are used.

dump

A value indicating whether this file system should be backed up by the dump command. This is a relic from Unix days gone by; because the dump command is obsolete as of Linux 2.4, this value should always be set to 0.

fscklvl

For all file systems other than the root file system, this should be set to 2. The root file system should be set to 1. File systems that don't require checking, such as reiserfs or iso9660, can be set to 0. If in doubt, this field should contain the value 2


If you would like to cause a file system such as the one created in the previous section to automatically be mounted when the system starts, add an entry to the bottom of the /etc/fstab file containing the device, mountpoint, file system type, and other information. Following the sample file system created in the previous section, you add the following line:

 /dev/sdb1 /publicspace ext2 defaults 0 2 

By editing the /etc/fstab file, you can cause Linux to automatically mount added storage devices or networked file systems each time you boot. You can also add additional removable storage devices so that users can mount and unmount them as needed.

For further documentation of the /etc/fstab file or the options that can be used in it, see the manual pages for fstab(5) and mount.



    SAMS Teach Yourself Red Hat(r) Fedora(tm) 4 Linux(r) All in One
    Cisco ASA and PIX Firewall Handbook
    ISBN: N/A
    EAN: 2147483647
    Year: 2006
    Pages: 311
    Authors: David Hucaby

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