0216-0218.html

来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 388 行

HTML
388
字号


<HTML>

<HEAD>

<TITLE>Developer.com - Online Reference Library - 0672311739:RED HAT LINUX 2ND EDITION:Filesystems, Disks, and Other Devices</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=11 //-->

<!-- PAGES=0195-0228 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->









<P><CENTER>

<a href="0213-0215.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0219-0221.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-216"><P>Page 216</P></A>













<P>disk caching scheme, which provides most of the speed benefit of a ramdisk but not the

fixed cost in memory.

</P>









<P>The most common use for ramdisks, then, is to serve as a root filesystem while Linux is

being installed. A compressed filesystem image is loaded into a ramdisk, and the installation

process is run from this disk. The ramdisk's filesystem can be larger than a single floppy, because

the image is compressed on the floppy.

</P>









<P>Although ramdisks are useful with operating systems lacking effective disk buffering, they

offer little performance advantage under Linux. Should you want to try out a ramdisk, they

work just like any other block device. For example, to mount a ramdisk as

/tmp, you would add

</P>





<!-- CODE SNIP //-->

<PRE>

/dev/ram    /tmp        ext2    defaults    0 0

</PRE>

<!-- END CODE SNIP //-->











<P>to /etc/fstab and then create and mount an ext filesystem with the following:

</P>





<!-- CODE SNIP //-->

<PRE>

/sbin/mkfs -t ext2 /dev/ram

mount /tmp

</PRE>

<!-- END CODE SNIP //-->











<P>Any performance benefits from doing this are hard to find, but you might find that this

helps in unusual circumstances.

</P>









<P>The principal advantage of ramdisks is that they enable great flexibility in the boot

process. Although it is possible to recompile a kernel including support for your hardware, this

makes the initial installation process difficult. Historically, this problem has been worked around

by the provision of dozens of different installation boot disks, each providing support for one

or two items of boot hardware (SCSI cards and CD-ROM drives, for example).

</P>









<P>A simpler solution is to exploit loadable kernel modules. Instead of having separate boot

disks for each type of hardware, all containing different kernels, it is simple to provide just one

boot disk containing a modular kernel and the module utilities themselves.

</P>









<P>A compressed filesystem is loaded from the floppy disk into a ramdisk by the kernel

loader, LILO, at the same time the kernel is loaded. The kernel mounts this filesystem and runs

a program (/linuxrc) from it. This program then mounts the &quot;real&quot; root filesystem and

exits, enabling the kernel to remount the real root filesystem on

/. This system is convenient to set up, and the process of creating initial ramdisks had been automated by Red Hat Software

(see the manual page for mkinitrd). Red Hat Linux systems whose root filesystem is on a SCSI

device have a modular kernel and boot by this method.

</P>









<H4><A NAME="ch11_ 20">

Zip Drives



</A></H4>









<P>Zip drives are drives providing removable 100MB cartridges. They come in three

varieties: parallel port (PPA), IDE, and SCSI. All are supported, but the parallel port version is

slowest; it is also a SCSI drive but with a proprietary parallel port interface, for which the Linux

kernel provides a driver. Hence, both kinds of drive appear as SCSI disks.

</P>









<P>Because they're just standard (but removable) SCSI or IDE disks, most aspects of their use

are just as for other block devices. Red Hat Linux 4.2 comes with support for both the SCSI

and

</P>



<A NAME="PAGENUM-217"><P>Page 217</P></A>













<P>PPA varieties. Further information can be found in the Zip-Drive mini-HOWTO

(which explains how to install your Zip drive), and the Zip-Install mini-HOWTO, which

explains how to install Red Hat Linux onto a Zip drive.

</P>









<H3><A NAME="ch11_ 21">

Character Devices

</A></H3>









<P>Character devices offer a flow of data that must be read in order. Whereas block devices

enable a seek to select the next block of data transferred, for example, from one edge or the other of

a floppy disk, character devices represent hardware that doesn't have this capability. An

example is a terminal, for which the next character to be read is whatever key you type at the keyboard.

</P>









<P>In fact, because there are only two basic types of devices, block and character, all hardware

is represented as one or the other, rather like the animal and vegetable kingdoms of

biological classification. Inevitably, this means that there are a few devices that don't quite fit into

this classification scheme. Examples include tape drives, generic SCSI devices, and the

special memory devices such as /dev/port and

/dev/kmem.

</P>

<P>

<P>



<CENTER>

<TABLE BGCOLOR="#FFFF99">

<TR><TD><B>

NOTE

</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

Network interfaces are represented differently; see Chapter 13.

</BLOCKQUOTE></TD></TR>

</TABLE></CENTER>

</P>



<H4>

Parallel Ports

</H4>









<P>Parallel ports are usually used for communicating with printers, although they are

versatile enough to support other things too&#151;for example, Zip drives, CD-ROM drives, and

even networking.

</P>









<P>The hardware itself offers character-at-a-time communication. The parallel port can

provide an interrupt to notify the kernel that it is now ready to output a new character, but

because printers are usually not performance-critical on most PCs, this interrupt is often borrowed

for use by some other hardware, often sound hardware. This has an unfortunate consequence:

The kernel often needs to poll the parallel hardware, so driving a parallel printer often requires

more CPU work than it should.

</P>









<P>The good news, though, is that if your parallel printer interrupt is not in use by some

other hardware, it can be enabled with the printer driver configuration program,

tunelp. The -i option for tunelp sets the IRQ for use with each printer device. You might set the IRQ for

the printer port to 7 like this:

</P>





<!-- CODE SNIP //-->

<PRE>

# /usr/sbin/tunelp /dev/lp1 -i 7

/dev/lp1 using IRQ 7

</PRE>

<!-- END CODE SNIP //-->







<A NAME="PAGENUM-218"><P>Page 218</P></A>











<P>If this results in the printer ceasing to work, going back to the polling method is easy:

</P>





<!-- CODE SNIP //-->

<PRE>

# /usr/sbin/tunelp /dev/lp1 -i 0

/dev/lp1 using polling

</PRE>

<!-- END CODE SNIP //-->











<P>The best way to test a printer port under Red Hat Linux is from the Control Panel's

Printer Configuration tool (/usr/bin/printtool). The Tests menu offers the option of printing a

test page directly to the device rather than via the normal printing system. This is a good

starting point. More information on setting up printers can be found

in Chapter 12, &quot;Printing with Linux.&quot;

</P>









<H4><A NAME="ch11_ 22">





Tape Drives

</A></H4>









<P>Tape drives provide I/O of a stream of bytes to or from the tape. While most tape drives can

be repositioned (that is, rewound and wound forward like audio or video tapes), this operation

is very slow by disk standards. While access to a random part of the tape is at least feasible, it

is very slow, and so the character device interface is workable for using tape drives.

</P>









<P>For most UNIX workstations, the interface of choice for tape drives is SCSI

because this fits in well with the SCSI disks and so on. SCSI provides the ability to just plug in a new device

and start using it. (Of course, you can't do this with the power on.) SCSI has traditionally

been more expensive than most other PC technologies, so it wasn't used for many tape drives

developed for use with PCs. There have been several interfaces used for tape drives for IBM

PCs, and these include the following:

</P>



<BR>





<TABLE WIDTH="360">



<TR><TD>

<B>Type</B>

</TD><TD>

<B>Device Names</B>

</TD><TD>

<B>Major Number</B>

</TD></TR>

<TR><TD>

SCSI

</TD><TD>

/dev/st*

</TD><TD>

9

</TD></TR>

<TR><TD>

Floppy

</TD><TD>

/dev/rft*

</TD><TD>

27

</TD></TR>

<TR><TD>

QIC-02

</TD><TD>

/dev/rmt

</TD><TD>

12

</TD></TR>

<TR><TD>

IDE

</TD><TD>

/dev/ht*

</TD><TD>

37

</TD></TR>

<TR><TD>

Parallel Port

</TD><TD>

(Currently unsupported)

</TD></TR>

</TABLE>













<P>All these tape drives have the feature that when the device is closed, the tape is rewound.

All these drives except the QIC-02 drive have a second device interface with a name prefixed

with n&#151;for example /dev/nst0, /dev/nst3, or

/dev/nht0. All these devices support the magnetic tape control

program, mt, which is used for winding tapes past files, rewinding them, and

so on. Many commands, particularly the more advanced

mt commands, are only available for SCSI tape drives.

</P>









<P>Apart from the mt command for the basic control of a tape drive, there are many

commands that you can use for storing and retrieving data on tape. Because the character devices are

&quot;just files,&quot; you could use cat to store data on the tape, but this is not very

flexible. There are a great many programs particularly or partly designed with tape drives in mind, including the

following:

</P>



<P><CENTER>

<a href="0213-0215.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0219-0221.html">Next</A>

</CENTER></P>









</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

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