Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Linux+ Certification Bible.pdf
Скачиваний:
46
Добавлен:
15.03.2015
Размер:
3.78 Mб
Скачать

Chapter 9 General Linux Administration 311

as the chown command. The chgrp command allows group ownership of a file to be changed independent of the permissions on the file or ownership of the file.

Mounting and Managing File Systems

4.5 Manage and navigate the Linux hierarchy (e.g., /etc, /usr, /bin, /var)

4.8 Mount and manage filesystems and devices (e.g., /mnt, /dev, du, df, mount, umount)

The Linux system administrator must daily mount and manage the file systems. This task also includes the mounting and un-mounting of devices. The administrator must determine the available resources in order to manage the file systems properly. The administrator can perform these tasks by using the tools provided by the Linux operating system.

Mount

The mount command is a powerful tool used to mount directories and devices on a Linux system. The simplest application of the mount command is to use it with no options or arguments. If the command is used on its own, it will return information similar to the following:

[user@dhcppc1 user]$ mount /dev/hda1 on / type reiserfs (rw) none on /proc type proc (rw)

none on /dev/pts type devpts (rw,mode=0620)

/mnt/cdrom on /mnt/cdrom type supermount (rw,fs=iso9660,dev=/dev/cdrom) /mnt/floppy on /mnt/floppy type supermount (rw,fs=vfat,dev=/dev/fd0) /dev/hda6 on /usr type reiserfs (rw)

/dev/hda7 on /var type reiserfs (rw)

/proc/bus/usb on /proc/bus/usb type usbdevfs (rw,devmode=0664,devgid=43)

This example shows the currently mounted devices and directories. Notice that the first device, hda1, is the primary IDE controller-master device, which contains the / or root directory. Mounts for the CD-ROM drive, FDD, /usr directory, /var directory, and USB on /proc/bus/usb are also available to the system. The mount command shows all the mounted devices on the system, and the hardware path for file systems, such as /var on partition /dev/hda7. This partition is commonly used to determine currently mounted devices and directories. The options available for the mount command are listed in Table 9-15.

312 Part IV Administration

 

Table 9-15

 

Options for mount

 

 

Option

Description

 

 

-a

Mount all filesystems mentioned in fstab of a given type.

 

 

-F

Fork off a new incarnation of mount for each device. This will perform the

 

mounts on different devices or different NFS servers in parallel and is

 

used in conjunction with the -a option.

 

 

-f

This ``fakes’’ mounting the file system by performing the mount without

 

making the actual system call.

 

 

-h

Provides the help file information.

 

 

-L label

Mount a partition that has the specified label.

 

 

-n

Mount without writing information in /etc/mtab.

 

 

-r

Mount the file system as read-only.

 

 

-s

Allows incorrect or sloppy mount options rather than failing.

 

 

-t vfstype

Used to indicate file system type. More on this option in the -t option

 

section.

 

 

-u uuid

Mount the partition that has the specified uuid and requires the file

 

/proc/partitions, available since Linux 2.1.116.

 

 

-V

Display mount version.

 

 

-v

Use verbose mode.

 

 

-w

Mount the file system read/write. This is the default.

 

 

-o argument

Options are specified with a -o flag followed by a comma separated string

 

of options. More on this option in the -o option section.

 

 

These options are used to mount a device. The following is a common command, which is used to mount the diskette drive on a Linux system.

[root@dhcppc1 user]# mount -v /mnt/floppy

/mnt/floppy on /mnt/floppy type supermount (rw,fs=vfat,dev=/dev/fd0)

Notice that the file system type is listed and can be assigned by the -t option.

The -t option

The -t option is used to indicate the file system type to be mounted. This allows you to mount other types of file system formats, such as msdos and vfat for Microsoft Windows. For most types, the mount program issues a simple mount system call; no detailed knowledge of the filesystem type is required because the mount command will probe the file system. If the probe fails, then the file /etc/filesystems is checked and those file types are attempted.

Chapter 9 General Linux Administration 313

The -o option

The -o option has many available arguments that allow it to provide the mount command more flexibility, as shown in Table 9-16.

 

Table 9-16

 

Arguments for the -o Option

 

 

Argument

Description

 

 

async

All I/O to the file system should be done asynchronously.

 

 

atime

Update inode access time for each access. This is the default.

 

 

auto

Can be mounted with the -a option.

 

 

defaults

Use default options: rw, suid, dev, exec, auto, nouser, and async.

 

 

dev

Interpret character or block special devices on the file system.

 

 

exec

Permit the execution of binaries.

 

 

noatime

Do not update inode access times on this file system.

 

 

noauto

Can only be mounted explicitly.

 

 

nodev

Do not interpret character or block special devices on the file system.

 

 

noexec

Do not allow execution of any binaries on the mounted file system.

 

 

nosuid

Do not allow set-user-identifier or set-group-identifier bits to take effect.

 

 

nouser

Forbid a non-root user to mount the file system. This is the default.

 

 

remount

Attempt to remount an already-mounted file system.

 

 

ro

Mount the file system read-only.

 

 

rw

Mount the file system read-write.

 

 

suid

Allow set-user-identifier or set-group-identifier bits to take effect.

 

 

sync

All I/O to the file system should be done synchronously.

 

 

user

Allow an ordinary user to mount the file system.

 

 

Umount

The opposite of mounting a drive is to unmount it, so that it cannot be accessed. Use the umount command to unmount a file system. If a floppy diskette drive is mounted, unmount the diskette before removing it. To perform this task, use the following umount command :

[root@dhcppc1 user]# umount -v /mnt/floppy /mnt/floppy umounted

314 Part IV Administration

The umount command uses the normal structure of umount [options] argument. The arguments are devices, directories, or -t [file system type]. The options available for the umount command are shown in Table 9-17.

 

Table 9-17

 

Options for umount

 

 

Option

Description

 

 

-a

Un-mount all file systems mentioned in /etc/mtab.

 

 

-h

Provides the help file information.

 

 

-n

Un-mount without writing information in /etc/mtab.

 

 

-r

In case umount fails attempt to mount the file system as read-only.

 

 

-t vfstype

Used to indicate file system type. More on this option in the -t option

 

section.

 

 

-V

Display umount version.

 

 

-v

Use verbose mode.

 

 

Mounted file systems

One of the main reasons for adding a new mounted file system is that the current file systems don’t provide the required resources for the users. Before adding a new file system via the mount command, however, you should view the systems that are currently being used. Linux has several ways to view this information — the most common are the du and df commands.

The du command

The du command is used to summarize disk usage of each file and recursively for directories. This command provides an extensive list of all the files and their usage of storage space. You may use the du command to determine the space used on a diskette as shown in the following:

[root@dhcppc1 floppy]# ls picture.bmp* [root@dhcppc1 floppy]# du 769 .

The picture file uses 769 kilobytes of the space on the diskette. The available options for the du command are shown in Table 9-18.

Chapter 9 General Linux Administration 315

 

 

Table 9-18

 

 

Options for du

 

 

Option

Description

 

 

 

-a

--all

Write counts for all files, not just directories.

 

 

--block-size=SIZE

Use SIZE-byte blocks.

 

 

 

-b

--bytes

Print size in byte.

 

 

 

-c

--total

Provide a grand total.

 

 

 

-D

--dereference-args

De-reference PATHs when symbolic link.

 

 

 

-h

--human-readable

Print sizes in human readable format, such as M for MB.

 

 

 

-H

--si

Print sizes in human readable format but uses powers of

 

 

1000 instead of 1024, which the -h option uses.

 

 

 

-k

--block-size=<size>

Used to assign the block size, normally 1024 but maybe

 

 

assigned 512 or 256 and so on.

 

 

 

-l

--count-links

Count sizes many times if hard linked.

 

 

 

-L

--dereference

De-reference all symbolic links.

 

 

 

-m

--megabytes

Sets block-size=1048576.

 

 

 

-S

--separate-dirs

Do not include size of subdirectories.

 

 

 

-s

--summarize

Display only a total for each argument.

 

 

 

-x

--one-file-system

Skip directories on different file systems.

 

 

-X FILE --exclude-from=FILE

Exclude files that match any pattern in FILE.

 

 

--exclude=PAT

Exclude files that match PAT.

 

 

--max-depth=N

Print the total for a directory (or file, with --all) only if it is N

 

 

or fewer levels below the command line argument.

 

 

--help

Provide help with the program.

 

 

--version

Provides version information about the program.

 

 

 

You can use the du command to estimate the free space used in the directory, as shown in the following.

[root@dhcppc1 /]# du /home/user

0/home/user/tmp

0/home/user/.kde/share/apps/RecentDocuments

0/home/user/.kde/share/apps/konqiconview/kpartplugins

316 Part IV Administration

1/home/user/.kde/share/apps/konqiconview

8/home/user/.kde/share/apps/konqueror/dirtree/remote/

8/home/user/.kde/share/apps/konqueror/dirtree/remote/

25

/home/user/.kde/share/apps/konqueror/dirtree/remote

46

/home/user/.kde/share/apps/konqueror/dirtree

62

/home/user/.kde/share/apps/konqueror

64

/home/user/.kde/share/apps

4/home/user/.kde/share/fonts/override

5/home/user/.kde/share/fonts

0/home/user/.kde/share/icons/favicons

1/home/user/.kde/share/icons

28

/home/user/.kde/share/config

99

/home/user/.kde/share

8

/home/user/.kde/Autostart

108

/home/user/.kde

16

/home/user/.netscape/cache

4/home/user/.netscape/xover-cache/host-localhost

5/home/user/.netscape/xover-cache

0/home/user/.netscape/archive

467 /home/user/.netscape

0/home/user/mydir

4/home/user/Desktop/Trash

57 /home/user/Desktop

0/home/user/nsmail

0/home/user/.bluefish/projects 5 /home/user/.bluefish

3764 /home/user

Although the du command is capable of much more, it is ideal for determining the file usage in a single directory, such as how much space and which files are using what space in a user’s home directory.

The df comand

The df command is similar to the du command but provides information about the amount of disk space available on the file system. The following is an example of the information provided by the df command:

[root@dhcppc1 /]# df -m

 

 

 

Filesystem 1M-blocks Used

Available Use% Mounted on

/dev/hda1

248

77

171

31%

/

/dev/hda6

913

687

226

75%

/usr

/dev/hda7

453

59

394

13%

/var

The additional options available to the df command are shown in Table 9-19.

Chapter 9 General Linux Administration 317

 

 

Table 9-19

 

 

Options for df

 

 

Option

Description

 

 

 

-a

--all

Include file systems having 0 blocks.

 

 

--block-size=SIZE

Use SIZE-byte blocks.

 

 

 

-h

--human-readable

Print sizes in human readable format, such as M for MB.

 

 

 

-H

--si

Print sizes in human readable format but uses powers of

 

 

1000 instead of 1024, which the -h option uses.

 

 

 

-i

 

List inode information instead of block usage.

 

 

 

-k

--block-size=<size>

Used to assign the block size, normally 1024 but maybe

 

 

assigned 512 or 256 and so on.

 

 

 

-l

--local

Used to limit listing to local file systems.

 

 

 

-m

--megabytes

Sets block-size=1048576.

 

 

--no-sync

Do not invoke sync before getting usage info, the default.

 

 

 

-p

--portability

Use the POSIX output format.

 

 

--sync

Invoke sync before getting usage info.

 

 

 

-t

--type=TYPE

Limit the listing to file systems of type TYPE.

 

 

 

-T

--print-type

Print the file system type.

 

 

 

-x

--exclude-type=TYPE

Limit the listing to file systems not of type TYPE.

 

 

 

-v

 

Ignored.

 

 

--help

Provide help with the program.

 

 

--version

Provides version information about the program.

 

 

 

The ability to easily check usage of the created partitions with the df command is a valuable tool for anyone using the Linux system.

Most current systems have plenty of disk space, but you can use the df command to verify the current usage of that space displayed by percentage of used space.

Соседние файлы в предмете Операционные системы