579-582.html
来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 124 行
HTML
124 行
<HTML>
<HEAD>
<TITLE>Linux Unleashed, Third Edition:System Administration Basics</TITLE>
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!--ISBN=0672313723//-->
<!--TITLE=Linux Unleashed, Third Edition//-->
<!--AUTHOR=Tim Parker//-->
<!--PUBLISHER=Macmillan Computer Publishing//-->
<!--IMPRINT=Sams//-->
<!--CHAPTER=32//-->
<!--PAGES=579-582//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="576-579.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="582-582.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>If the floppy is full before the entire archive has been copied, <TT>tar</TT> prompts you for another one. It’s important to keep the arguments in the right order. You see that the <TT>f</TT> is before the <TT>k</TT>, so the device name must be before the capacity. All the argument keyletters are gathered together instead of being issued one at a time followed by their value, which is one aspect of <TT>tar</TT> that can be very confusing.</P>
<P>As a last issue in backing up to floppy, it is sometimes necessary to tell the <TT>tar</TT> program about the blocking used (blocking identifies how many blocks are used for each chunk of information on the device). A floppy usually has a blocking factor of 4, so the command becomes the following:</P>
<!-- CODE SNIP //-->
<PRE>
tar cvfkb /dev/fd0 1440 4 /usr/tparker
</PRE>
<!-- END CODE SNIP //-->
<P>A final problem with <TT>tar</TT> is that it can’t always handle a generic device such as <TT>/dev/fd0</TT> and must be specifically told the disk type.</P>
<P>For more complete information on all the options used by <TT>tar</TT>, check the man pages or, even better, a good system administration book.</P>
<P>You can use <TT>tar</TT> to archive compressed files, too, in the same manner. You can also compress a <TT>tar</TT> file without any problems. In these cases, you might get filenames such as the following:</P>
<!-- CODE SNIP //-->
<PRE>
<I>filename</I>.tar.gz
</PRE>
<!-- END CODE SNIP //-->
<P>Filenames such as this show that you should run <TT>gunzip</TT> first to recover the <TT>tar</TT> file, and then run <TT>tar</TT> to extract the files in the archive. You can run the commands together with pipes:</P>
<!-- CODE SNIP //-->
<PRE>
gunzip <I>filename</I>.tar.gz | tar xvf -
</PRE>
<!-- END CODE SNIP //-->
<P>The hyphen representing the <TT>tar</TT> filename after the pipe symbol is standard UNIX terminology for taking the input from the pipe (<TT>stdin</TT>). The <TT>tar</TT> command has a lot of other options, many of which are obsolete or seldom used. We look at <TT>tar</TT> in more detail in Chapter 45, “Backups.”</P>
<H3><A NAME="Heading15"></A><FONT COLOR="#000077">Backups</FONT></H3>
<P>The three rules of system administration are back up, back up, and back up. This might sound silly and trite, but a backup can save you whenever you do something silly to the file system or when problems occur. With UNIX, most backups are made to a tape device using <TT>tar</TT>, although many Linux users don’t have tape units available and have to resort to floppies.</P>
<P>Backups are made with the <TT>tar</TT> utility, as mentioned earlier. The procedure is exactly the same as shown earlier. To back up the entire system on floppy, the command is as follows:</P>
<!-- CODE SNIP //-->
<PRE>
tar cvfbk /dev/fd0 1440 4 /
</PRE>
<!-- END CODE SNIP //-->
<P>To back up to a high-capacity tape device larger than the file system (and hence not needing a capacity limit), called <TT>/dev/rct0</TT>, the command is</P>
<!-- CODE SNIP //-->
<PRE>
tar cvfk /dev/rct0 20 /
</PRE>
<!-- END CODE SNIP //-->
<P>In many cases, you won’t want to back up the entire system, because it’s easier to reinstall off a CD-ROM. However, you should back up your user files by either backing up the entire <TT>/usr</TT> directory or specifically backing up your own home directory.</P>
<P>To restore a backup, you use the <TT>tar</TT> command again:</P>
<!-- CODE SNIP //-->
<PRE>
tar xvf /dev/rct0
</PRE>
<!-- END CODE SNIP //-->
<P>This recovers all files from the tape device <TT>/dev/rct0</TT>. You can explicitly restore specific files if you need to.</P>
<P>Several commercial products offer automated backups, although you can do this quite easily with the <TT>cron</TT> command.</P>
<H3><A NAME="Heading16"></A><FONT COLOR="#000077">Setting Up Your System</FONT></H3>
<P>You can perform several little tasks to tweak or optimize your Linux system, although in many cases they are dependent on the version you are running and other applications coexisting. We can look at a few of the miscellaneous tasks here.
</P>
<H4 ALIGN="LEFT"><A NAME="Heading17"></A><FONT COLOR="#000077">Setting the System Name</FONT></H4>
<P>The system name is contained in a file called <TT>/etc/HOSTNAME</TT>. It is simply the name the system calls itself for identification, which is especially useful if you are networking your Linux machine with others. Your system name (also called a host name) is what other machines will identify your machine as, so make it a unique and descriptive name. You can call the system anything you want.</P>
<P>To set your system name, you can either edit the system files (which should be followed by a reboot to make the changes effective) or use the <TT>hostname</TT> command. The following command sets the machine’s name to <TT>hellfire</TT>:</P>
<!-- CODE SNIP //-->
<PRE>
hostname hellfire
</PRE>
<!-- END CODE SNIP //-->
<H4 ALIGN="LEFT"><A NAME="Heading18"></A><FONT COLOR="#000077">Using a Maintenance Disk</FONT></H4>
<P>Every system should have a maintenance disk that enables you to check the <TT>root</TT> file system, recover from certain disk problems, and solve simple problems such as forgetting your <TT>root</TT> password. The emergency disks, also called the boot/root floppies, are created with the setup program in most distributions of Linux when the configuration is changed.</P>
<P>You can usually create an emergency boot disk from the CD-ROM that the system came on, as well as obtain the necessary files from FTP sites.</P>
<P>After you have booted your machine with the emergency disk, you can mount the disk partitions with the <TT>mount</TT> command.</P>
<H4 ALIGN="LEFT"><A NAME="Heading19"></A><FONT COLOR="#000077">Forgetting the root Password</FONT></H4>
<P>This is an embarrassing and annoying problem, but one luckily easily fixed with Linux. (If only other UNIX systems were so easy!) To recover from a problem with the <TT>root</TT> password, use a boot floppy and boot the system. Mount the <TT>root</TT> partition, and edit the <TT>/etc/passwd</TT> file to remove any password for <TT>root</TT>; then, reboot from the hard disk.</P>
<P>After the system has booted, you can set a password again.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>Warning: </B><BR>This points out one major security problem with Linux: Anyone with a boot floppy can get unrestricted access to your system!<HR></FONT>
</BLOCKQUOTE>
<H4 ALIGN="LEFT"><A NAME="Heading20"></A><FONT COLOR="#000077">Setting the Login Message</FONT></H4>
<P>If you have more than one user on the system, you can display information about the system, its maintenance, or changes in a file called <TT>/etc/motd</TT> (message of the day). The contents of this file are displayed whenever someone logs in.</P>
<P>To change the <TT>/etc/motd</TT> file, use any text editor and save the contents as ASCII. You can make the contents as long as you want, but readers usually appreciate brevity. The <TT>/etc/motd</TT> file is useful for informing users of downtime, backups, or new additions. You can also use it to give a more personal feel to your system.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="576-579.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="582-582.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?