LPI Linux Certification in a Nutshell (27 page)

Read LPI Linux Certification in a Nutshell Online

Authors: Adam Haeder; Stephen Addison Schneiter; Bruno Gomes Pessanha; James Stanger

Tags: #Reference:Computers

BOOK: LPI Linux Certification in a Nutshell
2.02Mb size Format: txt, pdf, ePub
Name

xfs_info

Syntax
xfs_info
device
Description

XFS is a filesystem type that was originally designed
for use on the IRIX operating system. It has been ported to Linux
and is a popular choice among Linux users for its large filesystem
capacity and robust feature set. The
xfs_info
program will print out information about the XFS partition.

Examples

Create an XFS filesystem on
/dev/sdb1
:

#
mkfs.xfs –q /dev/sdb1

Query the filesystem for information:

#
xfs_info /dev/sdb1
meta-data=/dev/sdb1 isize=256 agcount=4, agsize=490108 blks
= sectsz=512 attr=2
data = bsize=4096 blocks=1960432, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=0
realtime =none extsz=4096 blocks=0, rtextents=0
Name

fsck

Syntax
fsck [
options
] [-t
type
] [
fs-options
]
filesystems
Description

Check
filesystems
for
errors and optionally correct them. By default,
fsck
assumes the
ext2
filesystem type and runs interactively, pausing to ask for
permission before applying fixes.

Frequently used options for fsck
-A

Run checks on all filesystems specified in
/etc/fstab
. This option is intended for
use at boot time, before filesystems are mounted.

-N

Don’t execute, but show what would be done.

-t
type

Specify the type of filesystem to check; the default is
ext2
. The value of
type
determines which
filesystem-specific checker is called.

Frequently used options for e2fsck
-b
superblock

Use an alternative copy of the superblock. In
interactive mode,
e2fsck
automatically
uses alternative superblocks. Typically, you’ll try
-b 8193
in noninteractive mode to restore a
bad superblock.

-c

Check for bad blocks.

-f

Force a check, even if the filesystem looks
clean.

-p

Automatically repair the filesystem without
prompting.

-y

Answers “yes” to all interactive prompts, allowing
e2fsck
to be used
noninteractively.

Example 1

Check the
ext3
filesystem on
/dev/sda1
, which is not mounted:

#
fsck /dev/sda1
fsck 1.41.4 (27-Jan-2009)
e2fsck 1.41.4 (27-Jan-2009)
/boot: clean, 48/50200 files, 41926/200780 blocks

The partition was clean, so
fsck
didn’t
really check it.

Example 2

Force a check:

#
fsck -f /dev/sda1
fsck 1.41.4 (27-Jan-2009)
e2fsck 1.41.4 (27-Jan-2009)
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
/boot: 48/50200 files (22.9% non-contiguous), 41926/200780 blocks
Example 3

Force another check, this time with verbose output:

#
fsck -fv /dev/sda1
fsck 1.41.4 (27-Jan-2009)
e2fsck 1.41.4 (27-Jan-2009)
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
48 inodes used (0.10%)
11 non-contiguous files (22.9%)
0 non-contiguous directories (0.0%)
# of inodes with ind/dind/tind blocks: 22/12/0
41926 blocks used (20.88%)
0 bad blocks
0 large files
32 regular files
6 directories
0 character device files
0 block device files
0 fifos
0 links
1 symbolic link (1 fast symbolic link)
0 sockets
--------
39 files
Example 4

Allow
fsck
to automatically perform all
repairs on a damaged filesystem by specifying the
-y
option to run the command
automatically:

#
fsck -y /dev/sda1
fsck 1.41.4 (27-Jan-2009)
e2fsck 1.41.4 (27-Jan-2009)
Couldn't find ext2 superblock, trying backup blocks...
/dev/sda1 was not cleanly unmounted, check forced.
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
Block bitmap differences: +1 +2 +3 +4
Fix? yes
Inode bitmap differences: +1 +2 +3 +4 +5 +6
Fix? yes
/dev/sda1: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sda1: 1011/34136 files (0.1% non-contiguous), 4360/136521 blocks

When Linux boots, the kernel performs a check of all
filesystems in
/etc/fstab
using the
-A
option to
fsck
(unless
the
/etc/fstab
entry contains the
noauto
option). Any filesystems that were not
cleanly unmounted are checked. If that check finds any significant
errors, the system drops into single-user mode so you can run
fsck
manually. Unfortunately, unless you have
detailed knowledge of the inner workings of the filesystem, there’s
little you can do other than to have
fsck
perform all of the repairs. As a result, it is common to use the
-y
option and hope for the best.

In some cases, a filesystem may be beyond repair or may even
trigger a bug in
e2fsck
. In these (thankfully
very
rare) situations, there are a few commands
that can help an
ext2
filesystem wizard debug
the problem. These commands are
e2image,
dumpe2fs
, and
debugfs
. For more
information on these tools, read their appropriate manpages.

Name

xfs_metadump

Syntax
xfs_metadump [
options
]
device
Description

xfs_metadump
is a debugging tool
that copies the metadata from an XFS filesystem to a file. This is
useful as a debugging tool when you suspect filesystem problems, or
as a backup tool. Images created by
xfs_metadump
can be restored to a filesystem
using the command
xfs_mdre
store
.

Frequently used options
-e

Stops the dump on a read error. Normally, it will ignore
read errors and copy all the metadata that is
accessible.

-g

Shows dump progress.

-w

Prints warnings of inconsistent metadata to
stderr
. Bad metadata is still
copied.

On the Exam

Familiarity with
du,
df
, and
fsck
is important. Be sure you
understand the differences between the commands and when each is
used.

Objective 3: Control Filesystem Mounting and Unmounting

As discussed in
Objective 1: Create Partitions and Filesystems
, the Linux directory
hierarchy is usually made up of multiple partitions, each joined to the
root filesystem. Filesystems on removable media, such as CD-ROMs, USB
flash drives, and floppy disks, are joined in the same way, but usually on
a temporary basis. Each of these separate filesystems is
mounted
to the parent filesystem as a
directory (or
mount point
) in the unified
hierarchy.

Directories intended as mount points usually don’t contain files or
other directories. Instead, they’re just empty directories created solely
to mount a filesystem. If a directory that already contains files is used
as a mount point, its files are obscured and unavailable until the
filesystem is unmounted. Typical mount points include the directories
/usr
,
/home
,
/var
, and others.

Managing the Filesystem Table

Since the Linux filesystem hierarchy is spread across
separate partitions and/or multiple drives, it is necessary to
automatically mount those filesystems at boot time. In addition,
removable media and filesystems on remote NFS servers may be used
regularly with recurring mount properties. All of this information is
recorded in the
/etc/fstab
file.
Filesystems defined in this file are checked and mounted when the system
boots. Entries in this file are consulted for default information when
users wish to mount removable media.

The
/etc/fstab
file (see
Example 7-1
) is plain text and
consists of lines with six fields:

Device

This field specifies the device file of the partition
holding the filesystem (for example,
/dev/hda1
). This may either be the device
name (like
/dev/hda1
), the UUID of the device
(like
UUID=35f8a3e0-9257-4b71-913d-407bef4eeb90
),
or the partition label (like
LABEL=/boot
).

Mount point

This field specifies the directory on which the filesystem
is to be mounted. For example, if
/dev/hda1
contains the root filesystem, it is mounted at
/
. The root filesystem will contain
additional directories intended as mount points for other
filesystems. For example,
/boot
may be an
empty directory intended to mount the filesystem that contains
kernel images and other information required at boot time.

Filesystem type

Next, the type of filesystem is specified. These may include
ext2
filesystems,
swap
,
nfs
,
iso9660
(CD-ROM),
and others.

Mount options

This field contains a comma-separated list of options. Some
options are specific to particular filesystem types. Options are
described later in this Objective.

Dump frequency

The
dump
program, a standard
Unix backup utility, will consult
/etc/fstab
for information on how often to dump each filesystem. This field
holds an integer, usually set to
1
for native Linux filesystems such as
ext2
, and to
0
for others.

Pass number for fsck

This field is used by the
fsck
utility when the
-A
option is specified,
usually at boot time. It is a flag that may contain only the
values
0
,
1
, or
2
.

  • A
    1
    should be entered
    for the root filesystem and instructs
    fsck
    to check that filesystem
    first.

  • A
    2
    instructs
    fsck
    to check corresponding filesystems
    after those with a
    1
    .

  • A
    0
    instructs
    fsck
    not to check the filesystem.

Example 7-1. Sample /etc/fstab file

/dev/sda1      /                ext2    defaults        1 1
/dev/sda5 /boot ext2 defaults 1 2
/dev/sda9 /home ext2 defaults 1 2
/dev/sda6 /root ext2 defaults 1 2
/dev/sda10 /tmp ext2 defaults 1 2
/dev/sda8 /usr ext2 defaults 1 2
/dev/sda7 /var ext2 defaults 1 2
/dev/sda11 swap swap defaults 0 0
/dev/fd0 /mnt/floppy ext2 noauto,users 0 0
/dev/hdc /mnt/cdrom iso9660 noauto,ro,users 0 0
/dev/hdd /mnt/zip vfat noauto,users 0 0
fs1:/share /fs1 nfs defaults 0 0

The
fstab
in
Example 7-1
depicts a system with a
single SCSI disk,
/dev/sda
. The first partition,
/dev/sda1
, contains an
ext2
root filesystem. Partition
/dev/sda11
is swap.
Partitions
/dev/sda5
through
/dev/sda10
contain
ext2
filesystems for
/boot
,
/home
,
/root
,
/tmp
,
/usr
, and
/var
, respectively. All of the local
ext2
partitions are to be checked by
fsck
and dumped. Entries for the floppy disk
(
/dev/fd0
), CD-ROM (
/dev/hdc
), and IDE Zip drive
(
/dev/hdd
) hold appropriate mount properties,
making manual mounting of these devices simple. Finally, this example
shows a remote NFS mount of directory
/share
of
system
fs1
. It is mounted locally at
/fs1
.

The
/etc/fstab
file is automatically created
when Linux is installed and is based on the partitioning and mount point
configuration specified. This file can be changed at any time to add
devices and options, tailoring the filesystem to meet your specific
needs.

On the Exam

You should memorize the functions of each column in
/etc/fstab
and be prepared to
answer questions on each.

Mounting Filesystems

Filesystems are mounted using the
mount
command. At boot time, those filesystems with
a nonzero pass number in
/etc/fstab
are checked and
automatically mounted. Later, you can run
mount
manually to add other filesystems to the filesystem
hierarchy
.

Unmounting Filesystems

Filesystems can be unmounted using the
umount
command. When a filesystem is
unmounted, the buffers of the filesystem are synchronized with the
actual contents on disk and the filesystem is made unavailable, freeing
the
mount point. If the filesystem is busy,
umount
yields an error. This will happen, for
example, when the filesystem contains open files or when a process has a
working directory within the filesystem. Other less obvious errors can
occur when removable media are exchanged without being unmounted
first.

Other books

Divergence by Tony Ballantyne
A Trick of the Mind by Penny Hancock
Coming Home for Christmas by Fern Michaels
The Humanity Project by Jean Thompson
The Invasion Year by Dewey Lambdin
Fencing You In by Cheyenne McCray
The Inner Circle by Kevin George