📄 0047-0049.html
字号:
<HTML>
<HEAD>
<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:System Startup and Shutdown</TITLE>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!-- ISBN=0672311739 //-->
<!-- TITLE=RED HAT LINUX 2ND EDITION //-->
<!-- AUTHOR=DAVID PITTS ET AL //-->
<!-- PUBLISHER=MACMILLAN //-->
<!-- IMPRINT=SAMS PUBLISHING //-->
<!-- PUBLICATION DATE=1998 //-->
<!-- CHAPTER=04 //-->
<!-- PAGES=0037-0052 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0044-0046.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0050-0052.html">Next</A>
</CENTER></P>
<A NAME="PAGENUM-47"><P>Page 47</P></A>
<H4><A NAME="ch04_ 19">
Running as Root
</A></H4>
<P>Don't use Linux as root all the time! Although you might be tempted, there are some very
good reasons not to. First, even though you might have aliased the
rm command to rm -i in your .bashrc file, a simple
# rm -fr /* will not only wipe out your Linux system, but also any
DOS or Windows partitions if mounted under /mnt. Instead, create a user for yourself and use the
su command when you need to do things as the root operator. If you have programs that need
to run SUID root, see Phil Hughes's article, "Safely Running Programs as
root," in the May 1997 issue of Linux Journal.
</P>
<H4><A NAME="ch04_ 20">
Creating a Boot Disk
</A></H4>
<P>One of the first things you should do following a clean install and setup is to make a boot
disk, using the current Linux kernel on your computer. You should always have a working copy
in case you screw up when recompiling the kernel. Here's one quick way to not only make a
copy of your current kernel, but also create an emergency boot disk. First, make sure your
kernel points to your root device. You can check this on a recently built kernel with
</P>
<!-- CODE SNIP //-->
<PRE>
# rdev zImage
</PRE>
<!-- END CODE SNIP //-->
<P>Next, format a disk in your floppy drive using
fdformat (assuming a 1.44MB drive A:):
</P>
<!-- CODE SNIP //-->
<PRE>
# fdformat /dev/fd0H1440
</PRE>
<!-- END CODE SNIP //-->
<P>Next, copy your kernel to the disk with
</P>
<!-- CODE SNIP //-->
<PRE>
# dd if=zImage of=/dev/fd0
</PRE>
<!-- END CODE SNIP //-->
<P>Now, assuming your computer is set to look at the floppy first, try rebooting with your
boot disk with
</P>
<!-- CODE SNIP //-->
<PRE>
# shutdown -r now
</PRE>
<!-- END CODE SNIP //-->
<P>But you should also have a backup set of emergency boot disks that include not just the
kernel, but also a minimal filesystem to get you started on the road to recovery. There are some
excellent guides, scripts, and software to help you do this. (See "For More Information" at the
end of this chapter.)
</P>
<P>Generally, the approach is to create two disks, with one containing a kernel, and the
other containing a compressed filesystem with a minimal directory of files, including file
utilities. But guess what? Because you're a Red Hat Linux user, you don't have to!
Read on to find out why.
</P>
<H5><A NAME="ch04_ 21">
Ackpht! Argggh! I've Deleted My Document!
</A></H5>
<P>If you accidentally delete a text file, don't panic! There's a handy tip, called "Desperate
person's text file undelete," from Paul Anderson's "The Linux Tips HOWTO," courtesy of
Michael Hamilton.
</P>
<A NAME="PAGENUM-48"><P>Page 48</P></A>
<P>Assuming you remember some of the text, know which partition the file was on, and have
a spare partition with some room, you should be able to recover a good portion of the
file. Hamilton's approach uses the egrep and
strings commands. For example, if you lose a 100-line file with the phrase "Xena," followed by "Lawless," and have room on your DOS
partition:
</P>
<!-- CODE SNIP //-->
<PRE>
# egrep -100 `Xena.+Lawless' /dev/hda3 > /mnt/dos/lucy
</PRE>
<!-- END CODE SNIP //-->
<P>Then you can look for the text with
</P>
<!-- CODE SNIP //-->
<PRE>
# strings /mnt/dos/lucy | less
</PRE>
<!-- END CODE SNIP //-->
<H4><A NAME="ch04_ 22">
Your File Toolbox
</A></H4>
<P>You should also learn about and know how to use some of the file tools included with Red
Hat Linux. While e2fsck is run automagically from the
rc.sysinit script, it can be helpful in diagnosing and fixing problems. Other
commands, such as dumpe2fs and debugfs, provide
detailed technical information concerning your Linux filesystem, while others, such as
badblocks, can be helpful if you have a non-IDE hard drive.
</P>
<P>Here's a list of just some of the programs available:
</P>
<H5><A NAME="ch04_ 23">
e2fsck
</A></H5>
<P>Most Linux users choose to use the second extended filesystem, and with good reason:
e2fs is robust, efficient, speedy, and relatively impervious to fragmentation. This command has
a plethora of options aimed at helping you check and repair your filesystem. For safety's
sake, unmount the partition and then try
</P>
<!-- CODE SNIP //-->
<PRE>
# e2fsck -p /dev/hda3
</PRE>
<!-- END CODE SNIP //-->
<P>to automatically repair the partition /dev/hda3.
</P>
<H5><A NAME="ch04_ 24">
badblocks
</A></H5>
<P>This command will search a device for bad blocks, and also has a number of options; but
beware of the -w option, as it is a "write-mode" test and will destroy data on a partition.
</P>
<H5><A NAME="ch04_ 25">
fsck
</A></H5>
<P>This command is similar to e2fsck, as it checks and repairs Linux filesystems. Be sure to
read its man page, as the -P option can be harmful.
</P>
<H5><A NAME="ch04_ 26">
dump and restore
</A></H5>
<P>The dump command can be used for filesystem backup, as it searches your files that need to
be backed up. dump will also do remote backups. The companion program is
restore, which also works across networks.
</P>
<A NAME="PAGENUM-49"><P>Page 49</P></A>
<H5><A NAME="ch04_ 27">
dumpe2fs
</A></H5>
<P>This command will dump your filesystem information. You'll get the inode count, block
count, block size, last mount, and write time. Running
dumpe2fs on a 450MB partition will generate a 26,000-character report. An interesting part of the report is the mount and maximum
mount count, which determines when e2fsck is run on a partition when Linux starts.
</P>
<H5><A NAME="ch04_ 28">
tune2fs
</A></H5>
<P>If you just have to mess with your system's performance, you can use this command to
adjust its tunable parameters—but only if you have an
ext2 filesystem. Use this command to adjust when
e2fsck is run on your partition, but don't do it when the partition is mounted!
</P>
<H5><A NAME="ch04_ 29">
mke2fs
</A></H5>
<P>Linux hackers will be familiar with this program, which creates a Linux second
extended filesystem on a partition. And you might need it too, if you want to create compressed
filesystems on emergency disks, or if you install a new hard drive.
</P>
<H5><A NAME="ch04_ 30">
debugfs
</A></H5>
<P>This is an ext2 filesystem debugger, with 34 built-in commands. If you call it with
</P>
<!-- CODE SNIP //-->
<PRE>
# debugfs /dev/hda3
</PRE>
<!-- END CODE SNIP //-->
<P>you can examine your filesystem in read-only mode.
</P>
<P>Each of these utilities can help you maintain, diagnose, and repair a filesystem. But what if
you can't boot? Read on!
</P>
<H4><A NAME="ch04_ 31">
Red Hat to the Rescue! When the System Won't Boot
</A></H4>
<P>There are a number of reasons why a Linux system might not boot. If you recall the
earlier example of making a boot disk, you know that the
rdev command is used to set the root device. Building a new kernel, and then trying to use LILO or
LOADLIN to load the new kernel, won't work unless you've done this. You'll also have problems if you've rebuilt the kernel
and hard-coded in the wrong root device.
</P>
<P>I told you earlier that you'll appreciate being a Red Hat user. Here's another good reason:
You get a set of emergency boot disks with your Red Hat distribution. If your system won't
boot, here's how to possibly recover your system:
</P>
<P>First, boot Linux from your Red Hat Linux boot disk. Next, at the
boot: prompt, type boot: rescue, which will load a kernel from the disk. Follow the
prompts, and when asked, insert
the second disk, called "Supplemental Disk." A bar graph will show loading progress of a
compressed filesystem, and you'll end up with a # prompt.
</P>
<P><CENTER>
<a href="0044-0046.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0050-0052.html">Next</A>
</CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -