⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch38.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
📖 第 1 页 / 共 3 页
字号:


that can be edited to provide boot information, while other versions of Linux configure



LILO during the installation process. If the latter is the case, you can change the



settings with the setup utility or with the liloconfig utility, located in the <TT>/sbin</TT>



directory. Some versions of Linux use the configuration file <TT>/etc/lilo.conf</TT>



instead of <TT>/etc/lilo</TT>.



<H4 ALIGN="CENTER"><A NAME="Heading7<FONT COLOR="#000077">Shutting Down Linux</FONT></H4>



<P>You can't just turn off the power switch! This can cause damage to the file system,



sometimes irreversibly. Because Linux keeps many files open at once, as well as several



processes, they must all be closed down properly before you cycle the power to the



unit.</P>



<P>There are a few ways to shut the Linux system down, but the formal method is to



use the <TT>shutdown</TT> command. The syntax for <TT>shutdown</TT> is<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">shutdown [minutes] [warning]



</FONT></PRE>



<P>where minutes is the number of minutes to wait before shutting the system down



and warning is an optional message displayed for all users currently logged in. Some



versions of <TT>shutdown</TT> allow the word <TT>now</TT> instead of a time, while



others require either no argument or the number <TT>0</TT> to shut the system down



immediately without waiting. You can have <TT>shutdown</TT> reboot the system after



the shutdown by adding the argument <TT>-r</TT> (for reboot).</P>



<P>Using <TT>shutdown</TT> is best if you have other users on your system, because



it gives them a warning that they should log out, and it prevents loss of information.



It can also be used to automate a shut-down much later (such as at midnight), with



messages just before that time warning any users still logged in.</P>



<P>If you can't wait and want to shut the system down immediately, use the <TT>halt</TT>



command or the &quot;three-finger salute&quot; of Ctrl-Alt-Delete. This immediately



shuts down all the processes and halts the system as quickly as possible. Then the



power can be shut off.







<DL>



	<DT></DT>



</DL>











<DL>



	<DD>



<HR>



<A NAME="Heading8<FONT COLOR="#000077"><B>WARNING: </B></FONT>Some Linux distributions



	don't support Ctrl-Alt-Delete, and a couple of older distributions use it to halt



	the system immediately without terminating processes properly. This can cause damage.



	Check the documentation or man pages for information.



<HR>







</DL>







<H3 ALIGN="CENTER"><A NAME="Heading9<FONT COLOR="#000077">Mounting File Systems</FONT></H3>



<P>File systems are not available until they are mounted onto the Linux main file



system. Even hard drives must be mounted, because only the <TT>root</TT> file system



is available in the <TT>/</TT> directory until the rest are mounted. The <TT>mount</TT>



command is used to mount a file system.</P>



<P>During the boot process, the <TT>mount</TT> command is used from the startup files



(such as the <TT>/etc/rc</TT> file or files under the <TT>/etc/rc.d</TT> directory)



to mount all the File Systems maintained in the file <TT>/etc/fstab</TT>. You can



look at the file to see the type of information maintained there. Every file system



that is mounted during the boot process has an entry giving its device name, its



mount directory (called the mount point), the type of file system it is, and any



options that apply.</P>



<P>You can add a new file system from a hard disk, a CD-ROM, a floppy, or any other



type of device that provides a file system supported by Linux, using the <TT>mount</TT>



command. The format is<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">mount filesystem mountpoint 



</FONT></PRE>



<P>where filesystem is the name of the device and mountpoint is where in the Linux



file system it should be mounted. For example, if you want to mount a SCSI CD-ROM



to the file system as <TT>/usr/cdrom</TT>, issue the following command:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">mount /dev/cd0 /usr/cdrom



</FONT></PRE>



<P>The directory <TT>/usr/cdrom</TT> must be created before the command is given,



or the <TT>mount</TT> command will generate an ambiguous error. You should replace



<TT>/dev/cd0</TT> with the name of your CD-ROM device driver (<TT>/dev/cd0</TT> for



most non-SCSI CD-ROM drives, and <TT>/dev/scd0</TT> for SCSI CD-ROM drivers). When



the file system has been mounted properly, changing to <TT>/usr/cdrom</TT> lets you



access all the files on the CD-ROM as if they were part of the normal file system.</P>



<P>If your <TT>/etc/fstab</TT> file doesn't have any entries in it already, you have



to mount the file system with a slightly different syntax:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">mount -t fstype filesystem mountpoint



</FONT></PRE>



<P>where fstype is the type of file system (such as ISO9660, MS-DOS, and so on).



The rest of the arguments are the same as the example above. The <TT>-t</TT> option



is used when the file system to be mounted doesn't already have an entry in the <TT>/etc/fstab</TT>



file.



<H4 ALIGN="CENTER"><A NAME="Heading10<FONT COLOR="#000077">Mounting a Floppy</FONT></H4>



<P>You can mount a floppy disk with a command similar to the one in the CD-ROM example



just discussed. To mount a floppy in the first floppy drive on the directory <TT>/mnt</TT>,



issue the following command:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">mount /dev/fd0 /mnt



</FONT></PRE>



<P>If the file system is not the default value used by Linux, the type of file system



must be specified. For example, to mount a floppy using the <TT>ext2</TT> file system,



use the <TT>-t</TT> option of the <TT>mount</TT> command:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">mount -t ext2 /dev/fd0 /mnt



</FONT></PRE>



<H4 ALIGN="CENTER"><A NAME="Heading11<FONT COLOR="#000077">Creating a New File



System</FONT></H4>



<P>To create a file system on a floppy (so it can be mounted), you should use the



utility <TT>mke2fs</TT> or the command <TT>mkdev fs</TT>, depending on the version



of Linux. To use <TT>mke2fs</TT>, for example, issue the command<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">mke2fs /dev/fd0 1440



</FONT></PRE>



<P>to create a floppy file system on a 1.44MB 3.5-inch diskette.



<H4 ALIGN="CENTER"><A NAME="Heading12<FONT COLOR="#000077">Unmounting File



Systems</FONT></H4>



<P>To detach a mounted file system from your Linux file system, use the <TT>umount</TT>



command with the name of the device. For example, to unmount a floppy in <TT>/dev/fd0</TT>,



issue the command<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">umount /dev/fd0



</FONT></PRE>



<P>and the floppy will be removed from the mounted point. Be sure to type <TT>umount</TT>



instead of <TT>unmount</TT>!</P>



<P>If you want to remove the current floppy and replace it with another, you can't



simply swap them. The current floppy must be unmounted, and then the new one must



be mounted. Failure to follow this process can result in corruption or erroneous



directory listings.



<H4 ALIGN="CENTER"><A NAME="Heading13<FONT COLOR="#000077">Checking File Systems</FONT></H4>



<P>Every now and again a file might get corrupted or a file system's inode table



might get out of sync with the disk's contents. For these reasons, it is a good idea



to check the file system at regular intervals. Several utilities can check file systems,



depending on the version of Linux. The utility <TT>fsck</TT> is available for some



systems, while the utility <TT>e2fsck</TT> is designed for Linux's <TT>ext2fs</TT>



file system. Many Linux versions include other utilities such as <TT>xfsck</TT> and



<TT>efsfck</TT> for different file systems. In many cases, the <TT>fsck</TT> command



is linked to the individual file system versions.</P>



<P>To use <TT>e2fsck</TT> to check a file system, issue the command with the device



name and the options <TT>a</TT> (automatically correct errors) and <TT>v</TT> (verbose



output):<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">e2fsck -av /dev/hda1



</FONT></PRE>



<P>This command checks and repairs any problems on the <TT>/dev/hda1</TT> (or whatever



device driver you specify) partition. If any corrections have been made to a partition,



you should reboot the machine as soon as possible to allow the system to resync its



tables.</P>



<P>Whenever possible, it is a good idea to unmount the file system before checking



it, because this can prevent problems with open files. Of course, you can't unmount



the primary <TT>root</TT> partition while running from it, so you can boot from a



boot floppy that contains the check utilities, and start them from the floppy.



<H4 ALIGN="CENTER"><A NAME="Heading14<FONT COLOR="#000077">Using a File as



Swap Space</FONT></H4>



<P>When you installed Linux, your setup program probably set up a partition specifically



for the swap space. You can, when the original installation has been completed, set



Linux to use a file instead of the partition, thus freeing up the partition's disk



space.</P>



<P>Generally, there is a performance degradation with using a file because the file



system is involved, although the effect can be small on fast disks and CPUs. However,



this is a useful technique when you need to add more swap space, such as when you



temporarily want to run a swap-space-intensive application such as a compiler.</P>



<P>To create a file used as the swap space, issue the following command:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">dd if=/dev/zero of=/swap bs=1024 count=16416



</FONT></PRE>



<P>This creates a file (called <TT>swap</TT>) for swap space that is about 16MB (in



this case, 16416 blocks). If you want a different size, replace the number after



<TT>count</TT> with the correct value in bytes. Next, physically create the file



swap file with the command<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">mkswap /swap 16416



</FONT></PRE>



<P>(the number should match the blocks determined earlier), and turn the swap space



on with the command<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">swapon /swap



</FONT></PRE>



<P>If you want to remove the swap file and use the swap partition, use the command<FONT



COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">swapoff /swap



</FONT></PRE>



<P>followed by a standard <TT>rm</TT> command to remove the file.</P>



<P>Swap files can't be larger than 16MB with most Linux versions, but you can have



up to eight swap files and partitions on your system.



<H3 ALIGN="CENTER"><A NAME="Heading15<FONT COLOR="#000077">Compressing Files



with gzip and compress</FONT></H3>



<P>Files abound on a UNIX system, adding up to a large chunk of disk real estate.



Instead of deleting files, an alternative is to compress them so that they take up



less space. Several compression utilities are available for UNIX and Linux systems.



The most commonly used are <TT>compress</TT> and the newer GNU <TT>gzip</TT>.</P>



<P>When run on a file, <TT>compress</TT> creates a smaller file with the extension



<TT>.Z</TT>, which immediately identifies the file as being compressed. To compress



a file, use the following command:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">compress filename



</FONT></PRE>



<P>You can also use wildcards to compress several files at once. <TT>compress</TT>



supports a number of options, but most aren't used often. By default, when a file



is compressed, the uncompressed original is deleted, although this can be changed



with a command-line option.</P>



<P>To uncompress a compressed file, run the <TT>uncompress</TT> program:<FONT COLOR="#0066FF"></FONT>



<PRE><FONT COLOR="#0066FF">uncompress filename



</FONT></PRE>



<P>Alternatively, you can use a wildcard such as <TT>*.Z</TT> to uncompress all the



compressed files. Remember to include the <TT>.Z</TT> suffix when specifying the



filename.</P>



<P>The <TT>gzip</TT> utility is a new compression tool that uses different algorithms



than <TT>compress</TT>. The <TT>gzip</TT> program has a few extra features that were



added since <TT>compress</TT> was released, such as adjustable compression (the more

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -