Tải bản đầy đủ (.pdf) (6 trang)

Tài liệu 7 More Red Hat® Linux™ Tips and Tricks docx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (878.65 KB, 6 trang )

7 More Red Hat
®
Linux

Tips and Tricks
1-800-COURSES
www.globalknowledge.com
Expert Reference Series of White Papers
Written and Provided by

Introduction
Are you looking for a quick and simple reference guide to help you navigate Red Hat® Linux
T
M
systems?
Look no further. Global Knowledge and Red Hat have assembled a second set of Tips and Tricks written by Red
Hat Certified Engineers
®
(RHCEs) to give you an edge on managing these systems:
1.
If a file has a link count greater than 1, is there a simpler w
ay to find out what other file names are
hard-linked to it?
2. Which interface is eth0?
3. Quick-and-dirty automounts
4. How can I make dd give me a progress report?
5.
Tar vs. Star—The battle of xattrs
6. New default mount options in Red Hat
®
Enterprise Linux


®
5
7. How do I enable logging so that I can see all the queries on my DNS server?
1. If a file has a link count greater than 1, is there a simpler
way to find out what other file names are hard-linked to it?
by Steve Bonneville, Red Hat Certified Engineer
®
T
he obvious answer is that you can’t by just looking at the inode;
the inode only contains a link count, not a
list of the file names that are hard-linked to the inode. So you need to walk through the filesystem looking for
files that have the same inode number as the file of interest.
The not so obvious solution is that the find command can do this searching for you, once you’ve determined
the inode number for the file with ls -i.
F
or example
,
find /home -mount -inum 78442
works nicely to find all file names using inode 78442 on the filesystem mounted on /home. The
-mount option is necessary to avoid accidentally searching other filesystems mounted on subdirectories of
the
/home filesystem, since inode numbers are only unique within a given filesystem. It is also very important
to start the find at the mount point for the filesystem being searched,
or some files might be missed by
find.
7 More Red Hat
®
Linux
TM
Tips and

Tricks
Copyright ©2007 Global Knowledge T
raining LLC. All rights reserved.
Page 2
2.Which interface is eth0?
by Paul Morgan, Red Hat Certified Engineer
®
If you’re not sure which physical interface is eth0 and which is eth1 (or eth2), run:
ethtool -p eth0 5
This blinks the LED on the interface for five seconds—without interrupting network traffic.
3. Quick-and-dirty automounts
by Joshua Hoffman, Red Hat Certified Engineer
®
1. Enable the /net map in /etc/auto.master.
2. Create a new directory to hold your network mounts:
mkdir /network
3. Create links for the mounts you want:
cd /network
ln -s /net/server1/var/ftp/pub/Server Server
4. Now you can just use the links:
cd /network/Server
5. Best of all, this always works:
ls /network
6.
This trick even works for NIS user homedirs:
cd /home
ln -s /net/server1/home/guests guests
4. How can I make dd give me a progress report?
by Andrew C. Dingman, Red Hat Certified Engineer
®

If you’ve been working with Linux very long, you’ve probably encountered dd, the deceptively simple utility
for copying a stream of data from here to there. You may have used it to zero a disk before letting it leave the
building,
to benchmark IO hardw
are by writing a certain number of bytes, to put a disk image on a floppy or
USB drive, or even to back up an entire disk.
Like many commands,
dd doesn’t generate much output as long as things are going well. This is great for
scripting, but can be frustrating when you run it interactively. On large transfers, such as wiping or imaging a
disk,
it can be a total mystery how much longer you have to wait.
Also like many other commands,
dd has some tricks up its sleeve that it will show off if it gets the right sig-
nal. In particular
,
dd will respond to the USR1 signal with a status report on TDERR.
It is the same data you’
d
normally get at the very end of the transfer and will look something like this:
Copyright ©2007 Global Knowledge T
raining LLC. All rights reserved.
Page 3
$
dd if=/dev/zero of=/tmp/demo bs=1M count=1536
33+0 records in
33+0 records out
34603008 bytes (35 MB) copied, 0.355191 seconds, 97.4 MB/s
So how do we send this signal? Using your choice of kill, killall, or pkill. All of these will, by
default, send a
TERM signal (15), which is not what we want at all. Instead, use the following to send the

USR1 signal to all processes you own named dd.
$ pkill -USR1 ^dd$
kill and killall support the -USR1 option in the same manner.
If you want a periodic status report, you can extend the same idea with watch in another terminal. Since
we’re just sending a signal,
there won’t be any output in the display from watch, but it’s a nice shortcut for
periodic execution.
$ watch -n5 -- pkill -USR1 ^dd$
Will send signal USR1 to any dd process you own every five seconds, triggering dd to tell you where it is in
the transfer and how fast it’s going. Remember, look at
dd’s terminal for the output!
$ dd if=/dev/zero of=/tmp/demo bs=1M count=1536
137+0 records in
137+0 records out
143654912 bytes (144 MB) copied, 5.66717 seconds, 25.3 MB/s
249+0 records in
249+0 records out
261095424 bytes (261 MB) copied, 11.5736 seconds, 22.6 MB/s
388+0 records in
387+0 records out
5.Tar vs. Star – The battle of xattrs
by Forrest Taylor, Red Hat Certified Engineer
®
In Red Hat
®
Enterprise Linux
®
4, tar could not handle the extra information stored in ext2 and ext3 file sys
-
tems called Extended

Attributes (EAs or xattrs).
T
his is a potential problem for backups
,
because SELinux and
ACLs use these Extended Attributes to store the security contexts and access control lists respectively.
star
shone brightly as it has options for backing up and restoring each of these attributes
.
Great strides have taken place in rebuilding tar to acknowledge these Extended Attributes, and with Red Hat
®
Enterprise Linux
®
5 comes a new tar with options for xattrs. tar now has three options for creating
an archive with
xattrs in mind:
--selinux Archive the SELinux attributes of the files and directories
--acls Archive the
A
CL attributes of files and directories
--xattrs Archive all Extended Attributes of files and directories.
Copyright ©2007 Global Knowledge T
raining LLC. All rights reserved.
Page 4
T
his includes both SELinux and ACL attributes, as well as any other
x
attr
.
Optionally, if you don’t want to use the xattrs there are three other options:

--no-selinux Do not use the SELinux attributes
--no-acls Do not use the ACL attributes
--no-xattrs Do not use any xattrs, including SELinux and ACL.
By default, tar does not archive the
xattrs, thus the previous three options are normally used at the time
of restore.
Additionally, newly created file systems in Red Hat Enterprise Linux 5 now contain the
acl and
user_xattr default mount options, so these tar options are necessary for good backups.
6. New default mount options in Red Hat Enterprise
Linux 5
by Forrest Taylor, Red Hat Certified Engineer
®
Newly created file systems in Red Hat
®
Enterprise Linux
®
5 now have new default mount options. For instance,
if I created /boot at install time on /dev/sda1, I can view these new mount options using tune2fs:
# tune2fs -l /dev/sda1
tune2fs 1.39 (29-May-2006)
Filesystem volume name: /boot
Last mounted on: <not available>
Filesystem UUID: ea84e45d-ba84-4346-bf7c-1988c123a4a5
Filesystem magic number: 0xEF53
Filesystem revision #: 1 (dynamic)
Filesystem features: has_journal ext_attr resize_inode
dir_index
filetype needs_recovery sparse_super large_file
Default mount options: user_xattr acl

Filesystem state: clean
Errors behavior: Continue
Filesystem OS type: Linux
...
W
e are interested in this line:
Default mount options: user_xattr acl
These options apply for the file system at mount time. Thus, these newly created file systems will be able to
use access control lists (ACL) and user extended attributes with no additional options.
A
CLs are used to give multiple users and groups permissions to files and directories
.
T
his extends the standard
Linux permissions of having one user permission, one group permission, and a permission for all others.
Copyright ©2007 Global Knowledge T
raining LLC. All rights reserved.
Page 5

×