• Nenhum resultado encontrado

Short options like -r are too limited for the ever-increasing number of mount options; there are too few letters in the alphabet to accommodate all possible options. Short options are also troublesome because it is difficult to determine an option's meaning based on a single letter. Many general options and all

filesystem-specific options use a longer, more flexible option format.

To use long options with mount on the command line, start with -o and supply some keywords. Here is a complete example with the long options in boldface:

mount -t vfat /dev/hda1 /dos -o ro,conv=auto

There are two long options here, ro and conv=auto. The ro option specifies read-only mode, and it is the same as the -r short option. The conv=auto option is a filesystem option telling the kernel to

automatically conv ert certain text files from the DOS newline format to the Unix style (which will be explained shortly).

The most useful long options are the following:

How Linux Works: What Every Super-User Should Know

by Brian Ward ISBN:1593270356

No Starch Press © 2004 (347 pages)

This guide describes the inner workings of a Linux system beginning with the file system and boot process and covering advanced topics such as networking, firewalls, development tools, device management, shell scripts, and sharing printers with Samba.

Table of Contents

How Linux Works—What Every Super-User Should Know Chapter 1 - The Basics

Chapter 2 - Devices, Disks, Filesystems, and the Kernel Chapter 3 - How Linux Boots

Chapter 4 - Essential System Files, Servers, and Utilities Chapter 5 - Configuring Your Network

Chapter 6 - Network Services

Chapter 7 - Introduction to Shell Scripts Chapter 8 - Development Tools

Chapter 9 - Compiling Software From Source Code Chapter 10- Maintaining the Kernel

Chapter 11- Configuring and Manipulating Peripheral Devices Chapter 12- Printing

Chapter 13- Backups

Chapter 14- Sharing Files with Samba Chapter 15- Network File Transfer Chapter 16- User Environments Chapter 17- Buying Hardware for Linux Chapter 18- Further Directions Appendix A- Command Classification Bibliography

Index List of Figures List of Tables List of Sidebars

exec, noexec Enables or disables execution of programs on the filesystem.

suid, nosuid Enables or disables setuid programs (see Section 1.17).

ro, rw Mounts the filesystem as read-only or read-write.

remount Reattaches a currently mounted filesystem at the same mount point. The only real reason to do this is to change mount options, and the most frequent case is making a read-only filesystem writable. An example of why you might use this is when the system leaves the root in read-only mode during crash recovery. The following command remounts the root in readwrite mode (you need the -n optio-n because the mou-nt comma-nd ca-n-not write to the system mou-nt database whe-n the root is read-only):

mount -n -o remount /

The preceding command assumes that the correct device listing for / is in /etc/fstab (explained in the next section). If it is not, you must specify the device.

norock, nojoliet (ISO9660 filesystem) Disables Rock Ridge (Unix) or Joliet (Microsoft) extensions.

Be warned that plain, raw ISO9660 is really ugly.

conv=rule (FAT-based filesystems) Conv erts the newline characters in files based on rule, which can be binary, text, or auto. The default is binary, which disables any character translation. To treat all files as text, use text. The auto setting converts files based on their extension. For example, a .jpg file gets no special treatment, but a .txt file does. Be careful with this option, because it can damage files. You may want to use it in read-only mode.

2.4.6 The /etc/fstab Filesystem Table

To mount filesystems at boot time and take the drudgery out of the mount command, Linux systems keep a permanent list of filesystems and options in /etc/fstab. This is a plain text file in a very simple format, as this example shows:

/dev/hda1 / ext2 defaults,errors=remount-ro 0 1 /dev/hda2 none swap sw 0 0 /dev/hda3 /usr ext2 defaults 0 2 proc /proc proc defaults 0 0 /dev/hdc /cdrom iso9660 ro,user,nosuid,noauto 0 0

Each line corresponds to one filesystem, broken into six fields:

The device. Notice that the /proc entry has a stand-in device.

The mount point.

The filesystem type. You may not recognize swap, for /dev/hda2. This is a swap partition (see Section 2.5).

Options.

Backup information for the dump command; dump does not see common use, but you should always specify this field with a 0.

The filesystem integrity test order (see the fsck command in Section 2.4.8). To ensure that fsck always runs on the root first, you should always set this to 1 for the root filesystem and 2 for any other filesystems on a hard disk. Use 0 to disable the bootup check for ev erything else, including CD-ROM drives, swap, and the /proc filesystem.

When using mount, you can take some shortcuts if the filesystem you want to work with is in /etc/fstab. For the example fstab above, to mount a CD-ROM, you need only run

mount /cdrom

You can also try to mount all entries in /etc/fstab that do not contain the noauto option at once, with

How Linux Works: What Every Super-User Should Know

by Brian Ward ISBN:1593270356

No Starch Press © 2004 (347 pages)

This guide describes the inner workings of a Linux system beginning with the file system and boot process and covering advanced topics such as networking, firewalls, development tools, device management, shell scripts, and sharing printers with Samba.

Table of Contents

How Linux Works—What Every Super-User Should Know Chapter 1 - The Basics

Chapter 2 - Devices, Disks, Filesystems, and the Kernel Chapter 3 - How Linux Boots

Chapter 4 - Essential System Files, Servers, and Utilities Chapter 5 - Configuring Your Network

Chapter 6 - Network Services

Chapter 7 - Introduction to Shell Scripts Chapter 8 - Development Tools

Chapter 9 - Compiling Software From Source Code Chapter 10- Maintaining the Kernel

Chapter 11- Configuring and Manipulating Peripheral Devices Chapter 12- Printing

Chapter 13- Backups

Chapter 14- Sharing Files with Samba Chapter 15- Network File Transfer Chapter 16- User Environments Chapter 17- Buying Hardware for Linux Chapter 18- Further Directions Appendix A- Command Classification Bibliography

Index List of Figures List of Tables List of Sidebars

this command:

mount -a

You may have noticed some new options in the preceding fstab listing, namely defaults, errors, noauto, and user. These aren't covered in Section 2.4.5 because they don't make any sense outside of the /etc/fstab file. The meanings are as follows:

defaults This uses the mount defaults — read-write mode, enable dev ice files, executables, the setuid bit, and so on. You should use this when you don't want to give the filesystem any special options, but you do want to fill all fields in /etc/fstab.

errors This ext2-specific parameter sets the system behavior if there is trouble mounting a filesystem. The default is normally errors=continue, meaning that the kernel should return an error code and keep running. To get the kernel to try again in read-only mode, use

errors=remount-ro. The errors=panic setting tells the kernel (and your system) to halt when there is a problem.

noauto This option tells a mount -a command to ignore the entry. Use this to prev ent a boot-time mount of a removable-media device, such as a CD-ROM or floppy drive.

user This option allows normal users to run mount on this entry. This can be handy for enabling access to CD-ROM driv es. Because users can put a setuid-root file on removable media with another system, this option also sets nosuid, noexec, and nodev (to bar special device files). The fstab example in this section explicitly sets nosuid.

2.4.7 Filesystem Capacity

To view the size and utilization of your currently mounted filesystems, use the df command. The output looks like this:

Filesystem 1024-blocks Used Available Capacity Mounted on /dev/hda1 1011928 71400 889124 7% /

/dev/hda3 17710044 9485296 7325108 56% /usr

The listing has the following fields:

Filesystem The filesystem device

1024-blocks The total capacity of the filesystem in blocks of 1024 bytes

Used The number of occupied blocks

Available The number of free blocks

Capacity The percentage of blocks in use

Mounted on The mount point

It is relatively easy to see that the two filesystems here are roughly 1GB and 17.5GB in size. Howev er, the capacity numbers may look a little strange because 71400 + 889124 does not equal 1011928, and

9485296 does not constitute 56 percent of 17710044. In both cases, 5 percent of the total capacity is unaccounted for. Nevertheless, the space is there. These hidden blocks are called the reserved blocks, and only the superuser may use the space if the rest of the partition fills up. This keeps system servers from immediately failing when they run out of disk space.

If your disk fills up and you need to know where all of those space-hogging, illegal MP3s are, use the du

How Linux Works: What Every Super-User Should Know

by Brian Ward ISBN:1593270356

No Starch Press © 2004 (347 pages)

This guide describes the inner workings of a Linux system beginning with the file system and boot process and covering advanced topics such as networking, firewalls, development tools, device management, shell scripts, and sharing printers with Samba.

Table of Contents

How Linux Works—What Every Super-User Should Know Chapter 1 - The Basics

Chapter 2 - Devices, Disks, Filesystems, and the Kernel Chapter 3 - How Linux Boots

Chapter 4 - Essential System Files, Servers, and Utilities Chapter 5 - Configuring Your Network

Chapter 6 - Network Services

Chapter 7 - Introduction to Shell Scripts Chapter 8 - Development Tools

Chapter 9 - Compiling Software From Source Code Chapter 10- Maintaining the Kernel

Chapter 11- Configuring and Manipulating Peripheral Devices Chapter 12- Printing

Chapter 13- Backups

Chapter 14- Sharing Files with Samba Chapter 15- Network File Transfer Chapter 16- User Environments Chapter 17- Buying Hardware for Linux Chapter 18- Further Directions Appendix A- Command Classification Bibliography

Index List of Figures List of Tables List of Sidebars

command. With no arguments, du prints the disk usage of every directory in the directory hierarchy, starting at the current working directory. (That's kind of a mouthful, so just run cd /; du to get the idea.

Press CONTROL-C when you get bored.) The du -s command turns on summary mode to print only the grand total. If you want to evaluate a particular directory, change to that directory and run du -s *.

Note 1024-byte blocks in df and du output is not the POSIX standard. Some systems insist on displaying the numbers in 512-byte blocks. To get around this, use the -k option (both utilities support this). The df program also supports the -m option to list capacities in one-megabyte blocks.

The following pipeline is a handy way to create a searchable output file (du_out) and see the results on the terminal at the same time.

du | tee du_out

2.4.8 Checking and Repairing Filesystems

The optimizations that Unix filesystems offer are made possible by a sophisticated database-like mechanism. For filesystems to work seamlessly, the kernel has to trust that there are no errors in a mounted filesystem. Otherwise, serious errors such as data loss and system crashes can happen.

The most frequent cause of a filesystem error is shutting down the system in a rude way (for example, with the power switch on the computer). The system's filesystem cache in memory may not match the data on the disk, and the system also may be in the process of altering the filesystem when you decide to give the computer a kick. Even though a new generation of filesystems supports journals to make filesystem corruption far less common, you should always shut the system down properly (see Section 3.1.5).

Furthermore, filesystem checks are still necessary ev ery now and then as sanity checks.

You need to remember one command name to check a filesystem: fsck. Howev er, there is a different version of this tool for each filesystem type that Linux supports. The information presented here is specific to second and third extended (ext2/ext3) filesystems and the e2fsck utility. You generally don't need to type e2fsck, though, unless fsck can't figure out the filesystem type, or you're looking for the e2fsck manual page.

To run fsck in interactive manual mode, use the device or the mount point (in /etc/fstab) as the argument. For example:

fsck /dev/hdd1

Warning Never use fsck on a mounted filesystem. The kernel may alter the disk data as you run the check, causing mismatches that can crash your system and corrupt files. There is only one exception. If you mount the root as read-only in single user mode, you may use fsck on the root filesystem.

In manual mode, fsck prints v erbose status reports on its passes, which should look something like this when there are no problems:

Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure

Pass 3: Checking directory connectivity Pass 4: Checking reference counts

Pass 5: Checking group summary information

/dev/hdd1: 11/1976 files (0.0% non-contiguous), 265/7891 blocks

If fsck finds a problem in manual mode, it stops and asks you a question relevant to fixing the problem.

These questions deal with the internal structure of the filesystem, such as reconnecting loose inodes and clearing blocks. The reconnection business means that fsck found a file that doesn't appear to have a name; reconnecting places the file in the lost+found directory filesystem as a number. You need to guess the name based on the content of the file.

In general, it's pointless to sit through the fsck process if you just made the mistake of an impolite

How Linux Works: What Every Super-User Should Know

by Brian Ward ISBN:1593270356

No Starch Press © 2004 (347 pages)

This guide describes the inner workings of a Linux system beginning with the file system and boot process and covering advanced topics such as networking, firewalls, development tools, device management, shell scripts, and sharing printers with Samba.

Table of Contents

How Linux Works—What Every Super-User Should Know Chapter 1 - The Basics

Chapter 2 - Devices, Disks, Filesystems, and the Kernel Chapter 3 - How Linux Boots

Chapter 4 - Essential System Files, Servers, and Utilities Chapter 5 - Configuring Your Network

Chapter 6 - Network Services

Chapter 7 - Introduction to Shell Scripts Chapter 8 - Development Tools

Chapter 9 - Compiling Software From Source Code Chapter 10- Maintaining the Kernel

Chapter 11- Configuring and Manipulating Peripheral Devices Chapter 12- Printing

Chapter 13- Backups

Chapter 14- Sharing Files with Samba Chapter 15- Network File Transfer Chapter 16- User Environments Chapter 17- Buying Hardware for Linux Chapter 18- Further Directions Appendix A- Command Classification Bibliography

Index List of Figures List of Tables List of Sidebars

shutdown. e2fsck has a -p option to automatically fix silly problems without asking you, aborting if there is a serious error. This is so common that Linux distributions run some v ariant of fsck -p at boot time (fsck -a is also common).

However, if you suspect that there is some major disaster, such as a hardware failure or device

misconfiguration, you need to decide on a course of action, because fsck can really mess up a filesystem with larger problems. A telltale sign of a serious problem is a lot of questions in manual mode.

If you think that something really bad happened, try running fsck -n to check over the filesystem without modifying anything. If there's some sort of problem with the device configuration (an incorrect number of blocks in the partition table, loose cables, whatev er) that you think you can fix, then fix it before running fsck for real. You're likely to lose a lot of data otherwise.

If you suspect that only the superblock, a key filesystem database component, is corrupt (for example, someone wrote to the beginning of the disk partition), you might be able to recover the filesystem with one of the superblock backups that mke2fs creates. Use fsck -b num to replace the corrupted superblock with an alternate at block num.

You may not know where to find a backup superblock, because you didn't write the numbers down when mke2fs ran. If the filesystem was created with the default values, you can try mke2fs -n on the device to view a list of superblock backup numbers without destroying your data (again, make dead sure that you're using -n, because you'll really tear up the filesystem otherwise).

If the device still appears to function properly except for a few small parts, you can run fsck -c before a manual fsck to search for bad blocks. Such a failure is somewhat rare.

No documento Introduction to Shell ScriptsChapter 8 (páginas 45-49)