
<chapter id="hw">
	<title>Interaction with system hardware</title>

	<blockquote>
		<attribution>Daniel Pead</attribution>
		<para>
		"In the UNIX world, people tend to interpret `non-technical user' as meaning someone who's only ever written one device driver."
		</para>
	</blockquote>

	<section id="hw-intro" xreflabel="Introduction">
		<title>Introduction</title>
		<para>
		There are many computer architectures available. Most of them have a cleaner design and stronger characteristics than the <emphasis/nowadays-standard/ Intel-compatible Personal Computer, and a number of them were in existence before the PC was "invented". Today, though, we see that the PC-compatible processor series has taken over the workstation and server market.
		</para>
		<para>
		On a side note, as the quote from the "<ulink url='http://www.fourmilab.ch/autofile/www/autofile.html'>Autodesk file</ulink>" by John Walker in the 80s, about the PC predecessor would say:

	<blockquote>
		<para>
Coming to Terms with the 8086
		<para>
It's become clear that the plague called the 8086 architecture has sufficiently entrenched itself that it's not going
to go away. For the last month or more, Mike Riddle, John Walker, Keith Marcelius, and Greg Lutz have been
bashing their collective heads against it. The following is collected information on this unfortunate machine.
		</para>
		<para>
I think we'd be wise to diffuse our 8086 knowledge among as many people as possible. The main reference for
the 8086 is a book called, imaginatively enough, The 8086 Book published by Osborne. This is the architecture
and instruction set reference, but does not give sufficient information to write assembly code (of which, more
later). However, it is the starting point to understand the machine. AI will reimburse the cost of your buying
this book, which is available at computer and electronic stores.
		</para>
		<para>
I have never encountered a machine so hard to understand, one where the most basic decisions in designing
a program are made so unnecessarily difficult, where the memory architecture seems deliberately designed to
obstruct the programmer, where the instruction set seems contrived to induce the maximum confusion, and
where the assembler is so bizarre and baroque that once you've decided what bits you want in memory you
can't figure out how to get the assembler to put them there.
		</para>
	</blockquote>

		</para>
		<para>
		This list of other general-purpose architectures (besides the
		Intel-compatible)
		would include Motorola 68000 (<literal/m68k/), 
		Sun Microsystems Sparc (<literal/sparc/), 
		Digital Equipment Alpha (<literal/alpha/), 
		Motorola/IBM PowerPC (<literal/ppc/ or <literal/powerpc/), 
		Silicon Graphics/DEC MIPS (<literal/mips/ and <literal/mipsel/), 
		Intel IA-64 (<literal/ia64/) and
		AMD 64 (<literal/amd64/). This list is by no means complete, it's 
		only a random selection of architectures already &LNK8; by &DEB;.
		</para>
		<para>
		So, given different architectures which are not binary-compatible (that is, where programs are not compatible across <emphasis/architecture bounds/), how do you get the same software running on all of them? We are, of course, interested in re-using existing applications &mdash; those that have a tradition, more features, and more hours in production than anything we would be able to create ourselves.
		<!--Of course, most trivial (and utmost incompetent) answer would be "<emphasis/let's write the software needed ourselves, let's pretend stupid and let's sell it as Big News to the World/". This approach, you might recognize, was chosen on at least one occassion in the past and proved fatal for human sanity, so there has to be a way around it.--> The key to the problem is namely <emphasis/porting/; changing existing code base in a way that it makes provisions for the new target platform (at places where any specific handling is necessary). Given proper education, writing portable software is easy; porting ("behaving" existing software), however, can be a source of great despair &mdash; sometimes you first have to deal with unacceptably poor programming practices and missed design, before you even come to portability issues.
		</para>
		<para>
		Let's see what would you have to do if you had a completely usable but new architecture, for which no high-level kernels and application programs were developed yet. <!-- (We can't take the <literal>PC</> architecture for a typical porting example because that special case would include &LNK9; and <emphasis/hardware/ in form of shotguns.) -->
		</para>
		<para>
		The first step in getting software run on our hypothetic architecture would come down to porting an existing Operating System <emphasis/kernel/ (first piece implemented in software and not hardware), so that the kernel is able to recognize basic system components and initialize hardware-dependent subsystems. When we'd get <emphasis/that/ done, we'd have to write kernel drivers to support additional hardware, such as network, audio and graphic cards, or your custom boards. Modern kernels support <emphasis/Loadable Kernel Modules/ (LKMs) which you can load into the kernel at runtime, so this task would not be as pressing as if you had to put everything in a single kernel image &mdash; but nevertheless, the system is not very usable without it.
		</para>
		<para>
		Once we'd get the above done, we'd have to get the build-chain (development tools) supported for a platform, or we wouldn't be able to get any user applications running. (In reality, this step would probably be more to the top of the list.) And once we'd have all that done, there would still be more work waiting for individual software programs. We'd have to try compiling them (converting to a binary, machine-runnable form) on new hardware. Depending on how much portability issues the original authors addressed themselves, this could be an easy, difficult or impossible task. Sometimes doing a complete rewrite (and avoding other design mistakes the original authors made) is easier than insisting on code base that was written by poor programmers, or at time when no standardized portability techniques were widespread.
		</para>
		<para>
		To sum up, there's much more to programming that just the physical position of sitting in front of a computer and punching letters.
		(Even though we all probably know a person or two who seem to be using their existence to prove the contrary).
		</para>
		<para>
		When you get to understand the basics of computer hardware, Unix will start looking like the only reasonable and natural extension to hardware, and its concepts and design elements will be easy to understand.
		</para>
	</section>

	<section id="hw-kernels" xreflabel="Kernels">
		<title>Operating system kernels</title>
		<para>
		As we've mentioned in the Introduction, a basic software element of an usable, general purpose computer is the kernel. Among the most widely known free kernels today is <emphasis/Linux/, made by Linus Torvaldsen and first released in 1991. Linux is an extraordinary thing in a true meaning of the word; you can find <ulink url="http://groups-beta.google.com/group/comp.os.minix/msg/2194d253268b0a1b">Linus' USENET post from October 5, 1991</> in the Google Groups' <ulink url="http://groups.google.com/googlegroups/archive_announce_20.html">20 Year Usenet Timeline</>. Another excellent site, <ulink url="http://www.computerhope.com">ComputerHope</>, maintains a record of Linus saying
		<quote>Hello everybody out there using minix - I'm doing a (free) operating
		system (just a hobby, won't be big and professional like gnu) for
		386(486) AT clones.</quote>
		</para>
		<para>
		Nowadays, many (or all) Free Software bundles sold by various companies are commonly called <emphasis/Linux distributions/. As the name implies, of course, they contain the Linux kernel, but that is only a tiny piece of the complete bundle. In addition to the kernel, bundles contain <emphasis/loads/ of Free Software packages which have been ported and compiled for your platform, and have been pre-configured to work nicely with other packages from the "bundle".
		</para>
		<para>
		A variety and freedom of choice always existed in the Free Software applications arena. For example, if there were 10 usable (not even popular, just usable) music player or web server programs in existence, chances are you'd find all of them already packaged and waiting for installation in your Debian package archive (and probably in majority of the <emphasis/Linux distributions/ as well).
		Kernels, however, have a completely different story. Today, Linux is by far the most popular Free Software kernel. Other kernels (such as &LNK10; or &LNK10-1;) are getting up to speed, but they have a life of their own and are based on a different license, not GNU GPL.
		</para>
		<para>
		Now you can understand why the authoritative people insist on calling distributions <literal>GNU/Linux</> instead of just <literal/Linux/. "Linux" identifies the kernel flavour (since now you know there are many, not just Linux), and "GNU" identifies the so-called <emphasis/userland/ (collection of user and system software, mostly the parts crucial for any Unix to be usable). Kernel is only a tiny part, what you actually "feel" when you use the system is the "spirit" of the userland - behavior of basic commands and tools. Omitting "GNU" from the name is ignorant behavior; GNU/Linux should be called GNU/Linux, at least in writing.
		</para>
		<para>
		I hope <command/you/ <emphasis/will/ understand that most of the things you'll appreciate in "Linux" will actually be standard and decades old Unix features that have nothing to do with the Linux kernel itself.
		</para>
		<para>
		Now, fitting the section title and this introduction together, we can reach the expected conclusion &mdash; since Debian is aiming to be an universal Operating System, it offers the choice of kernels!
		</para>
		<para>
		Yes, that's right! Besides the most widely known Debian GNU/Linux, there are also &LNK10;, &LNK10-1; and &LNK11-1; available. &LNK11-1; (visit &LNK11;) microkernel itself is still in development and not ready for use in production, but NetBSD and FreeBSD are mature kernels, and the usability of their Debian ports should increase rapidly. (Currently the main issue  with *BSD kernels and Debian is getting the kernels play along with GNU userland instead of the expected BSD). Just for the record, Linux 2.6 kernel series seems to outperform the rival cavalry on just about every test performed (at least according to <ulink url="http://www.feyrer.de/NetBSD/gmcgarry/">Gregory McGarry</> and <ulink url="http://bulk.fefe.de/scalability/">Felix von Leitner</>), but the BSD people are coming up with no-less smarter ideas and valuable features.
		</para>
		<para>
		In practice, this means that you'll be able to choose any hardware platform (machine type and architecture) and any of the supported kernels that best match your exact needs, while from the user perspective it will always be Debian with no visible and incompatible differences!
		</para>
	</section>


	<section>
		<title>Kernel drivers</title>
		<para>
		Free Software kernels come with all supported drivers already included in the kernel source packages. Loading or unloading a driver for any piece of hardware is an instant, one-command action.
		</para>
		<para>
		Free Software drivers are often better than their proprietary counterparts (paradoxically, since the proprietary drivers were made by the hardware manufacturers themselves). The only notable exceptions to this rule happen when the manufacturers keep their hardware internals <emphasis/secret/ and don't publish openly accessible specifications, so the technical people can't easily find their way with the piece of hardware (but this is easy to deal with &mdash; don't buy such products and you will directly communicate the message to the manufacturers, in the only language that they understand without thinking twice).
		</para>
		<para>
		The situation today looks MUCH better than it looked 8 years ago when I first wrote this. Today Linux
		works on just about everything, it supports accelerated graphics and DRI (Direct Rendering Infrastructure)
		on all major graphics cards (nVidia and AMD/ATI), and the drivers for those cards come from the 
		manufacturers. Not all of them are completely open about it, though, but shiny examples include companies
		Atheros (network cards) and ATI (after takeover by AMD) who directly talk to the Free Software developers
		and have opened their specifications and drivers. And good times are yet ahead! (On a side note, for
		a completely open graphics card design and drivers, although not usable for 3D yet,
		see <ulink url='http://www.opengraphics.org/'>OpenGraphics</ulink>.)
		</para>
		<para>
		So in general, when the hardware is supported, the whole process of integrating it into your system consists of loading appropriate kernel or user-space drivers, performing any necessary configuration tasks, and making sure the hardware configures itself automatically on each system boot.
		</para>
		<para>
		To save you the trouble, we will present an introduction to the general hardware identification techniques, then provide a series of sections describing different kinds of hardware and giving actual instructions how to properly integrate them in your system.
		</para>
		<para>
		Note that this chapter will be losing on importance, as new Debian installers perform the autodetection well, and nowadays there are generally <emphasis/no manual steps required/ to set up drivers on commodity hardware.
		</para>
		<title>Hardware identification techniques</title>
		<para>
		(As mentioned, this section is losing on practical relevance as almost all hardware is nowadays 
		auto-detected, auto-configured and everything else auto- that you can imagine. But it's still how
		things work, so it's a great source of knowledge that would today be considered "old school").
		</para>
		<para>
		We are going to provide the general techniques for identifying system hardware here, because you'll use them in all of the following hardware sections.
		</para>
		<para>
		In general, to identify system hardware, you run <command>less /var/log/dmesg</>. That will display most general and low-level information, such as system and processor type, available memory, attached hard disks, etc. This is all pretty nice, but does not help you in identifying <emphasis/unknown/ hardware because those lines are written only after the appropriate drivers are loaded (and if that was the case, you wouldn't be trying to identify those devices).
		</para>
		<para>
		Since (as we just said above) the basic components such as mainboards, processors and hard disks are recognized without special setup on your part, you'll be interested in identifying the rest of the hardware &mdash; that would mostly be "attachable" devices such as PCI and AGP cards, serial or parallel adapters and USB gadgets. To do so, run <command/lspci/ (<application/pciutils/ package) and <command/lsusb/ (<application/usbutils/ package).
		</para>
		<para>
		Note that the ID strings returned by above utilities will be your starting point in finding out the name (or names) of the drivers that support your specific devices. Free software drivers usually target <emphasis/chipsets/ instead of each device model of each vendor separately. For example, many old ISA network cards (from <emphasis/different/ manufacturers) worked with the <literal/ne2000/ driver. Nowadays, most network cards work using drivers <literal/8139too/, <literal/8139cp/, <literal/via-rhine/ or <literal/e100/. That said, most of the time you will not be interested in searching for the exact identification strings as reported by <command/lspci/ or <command/lsusb/, but only look at them for <emphasis/clues/ about chipset names (and those can also be easily read from the chip labels, if you can take the cards out of the computer and look at them).
		</para>
	</section>
	<section>
		<title>Driver name identification techniques</title>
		<para>
		So when you find some hardware ID strings, you'll want to search for the appropriate driver names. There are few approaches to this; you can run <command/sudo modconf/ and try to locate your ID string in the list. If you find the device in the list, press Enter and try to load the driver module (you almost can't make a mistake at this step &mdash; if you pick a wrong module, it simply won't load successfully and you'll be able to try a different one). If you find the right one using <command/modconf/, the tool will do all the necessary steps by itself and you'll have the hardware configured.
		</para>
		<note>
		<para>
		Just, don't feel lucky if you manage to load the <literal/dummy/ module. The whole purpose of that module is to only <emphasis/pretend/ as if the device was there, so obviously it won't do you much good in practice.
		</para>
		</note>
		<para>
		If you don't get lucky with <command/modconf/, simply open your Web browser application and look up your identification string (say, "<literal/Realtek Semiconductor RTL-8139/") on <ulink url="http://www.google.com/linux">http://www.google.com/linux</>. In the results returned, you should learn the name of the driver to support the specific hardware. The ID string I used in this example belongs to a network card, and directly the first result returned by Google would tell you the appropriate NIC (network card) driver name is <literal/8139too/.
		</para>
		<para>
		Finally, since the drivers are kept on your hard disk as normal files, the third way to learn the correct driver name includes visiting the modules directory and doing some manual file <emphasis/snoop & search/ operation there. To enter the correct directory, simply run <command>cd /lib/modules/`uname -r`/</>. Once there, try using <command/cd/, <command/ls/ and <command/find/ commands to get some results. Again, using the above "<literal/Realtek Semiconductor RTL-8139/" for example, running <command/find . -iname '*8139*'/ in the modules directory should give you a hint right away.
		</para>
		<important>
		<title>Note on drivers loading automatically on each boot</title>
		<para>
		If you load the driver using <command/sudo modconf/, then <command/modconf/ will also take care of adding the driver name to <filename>/etc/modules</> file. In effect, this would make the driver load on each machine boot.
		</para>
		<para>
		If you don't succeed with <command/modconf/, then after finding out the driver name, you'll have to load it manually using <command>sudo modprobe <replaceable/DRIVER_NAME/</>. You'll also want to add the driver name to <filename>/etc/modules</> to make it load on every boot; you can do that by running <command>echo <replaceable/DRIVER_NAME/ | sudo tee /etc/modules</>.
		</para>
		</important>

		<para>
		On systems of today, we have a mechanism called "udev" which is configured by files in
		<filename class='directory'>/etc/udev/</filename>. For example, once the network cards are
		(auto)detected, their names become persistent since udev updates file 
		<filename>/etc/udev/rules.d/70-persistent-net.rules</filename>. So that's the place to look for
		if you want to force or change your network card name assignments. Find more introductory information
		about "udev" in <filename>/usr/share/doc/udev/README.Debian.gz</filename>.
		</para>

		<para>
		Ok, those few simple hints are enough that we can move on to practical hardware setup scenarios.
		</para>
	</section>

	<section>
		<title>Common hardware setup and performance; guidelines and practical examples</title>

		<section id="hw-lan">
			<title>Network Interfaces (LAN)</title>
			<para>
			The machine picked for this example had two PCI network cards. Let's see how we could detect and recognize both. We will use the <command/lspci/ command and search for lines mentioning <literal/Ethernet/. Real output of <command/lspci | grep Ethernet/ looks like this (each line representing one ethernet card):
<screen>
$ lspci | grep Ethernet
00:0f.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139 (rev 10)
00:12.0 Ethernet controller: VIA Technologies, Inc. Ethernet Controller (rev 74)
</screen>
			</para>
			<para>
			Or a similar system might show:
<screen>
$ lspci | grep Ethernet
0000:00:0f.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+ (rev 10)
0000:00:12.0 Ethernet controller: VIA Technologies, Inc. VT6102 [Rhine-II] (rev 74)
</screen>
			</para>
			<para>
			Today, popular low-cost PC network cards probably use one of <literal/8139too/ or <literal/8139cp/ (RealTek), <literal/winbond-840/ or <literal/rl100a/ (Winbond), <literal/via-rhine/ (VIA) or <literal/eepro100/ (Intel) drivers. We could try running <command>modprobe <replaceable/MODULE_NAME/</> for all of those driver module names above and we'd actually get lucky, but let's be some more clever than that; let's show how we could be successful using the identification tips we gave in the previous section.
			</para>
			<!-- TODO: in shell section where we show redirection, show backtics on uname -r example -->
			<para>
			If we fired up <command/sudo modconf/ and entered the <emphasis>kernel/drivers/net</> section, we'd find both "<emphasis/RealTek RTL-8139 PCI Fast Ethernet Adapter/" and "<emphasis/VIA Rhine/" there. Selecting them and specifying no additional parameters (PCI devices don't usually need them) would successfully load the modules.
			</para>
			<para>
			If we opened the Web browser and searched for the identification string "<literal/Realtek Semiconductor RTL-8139/" on <ulink url="http://www.google.com/linux">http://www.google.com/linux</>, the first result would hint <literal/8139too/ to be the appropriate driver name. Searching for "<literal/VIA Technologies, Inc. Ethernet Controller/" would reval the <literal/via-rhine/ driver name in the 3rd result.
			</para>
			<para>
			And if we did <command>cd /lib/modules/`uname -r`/</> and <command/find -iname '*8139*'; find -iname '*via*'/, we would also have something to work with.
			</para>
			<!--
			<para>
			Altogether, finding the appropriate driver name is trivial. Saying this is hard is absolutely inexcusable; if you have problems with this step, then you are literally <emphasis/computer-illiterate/ and should consider a different career.
			</para>
			-->
			<para>
			It's important to know that, unlike most things in Unix, network interfaces are <emphasis>not</> represented by files in the <filename class='directory'>/dev/</> directory (although there exists a patch for the Linux kernel which enables that); in Linux, the interfaces are simply given "virtual" names such as <literal>eth0</>, <literal>eth1</> etc. The tool to manage network interfaces is traditionally called <command/ifconfig/. Running <command/sudo ifconfig -a/ should give you some nice output that you might want to look at.
			</para>
			<para>
			If you ran <command/ifconfig/, you probably noticed that the network interfaces, for whom you have just loaded the drivers, have not been configured. The configuration file for this kind of stuff is named <filename>/etc/network/interfaces</>, and it defines the usual things, such as network interface IP addresses, netmasks and gateways.  The <citerefentry><refentrytitle>interfaces</><manvolnum>5</></citerefentry> manual page is pretty informative, but we'll provide two most common examples; simple static IP and dynamic IP (DHCP) setups. Our first interface, <literal>eth0</> will be given a static IP; the other, <literal>eth1</> will have a dynamic IP.
	</para>
	<example>
	<title>/etc/network/interfaces</title>
<programlisting>
#
# Standard stuff
auto lo eth0 eth1

iface lo inet loopback

</programlisting>

<programlisting>
#
# Eth0: static
iface eth0 inet static
  address 192.168.7.3
  netmask 255.255.255.0
  broadcast 192.168.7.255
  gateway 192.168.7.1

</programlisting>

<programlisting>
#
# Eth1: DHCP
iface eth1 inet dhcp

</programlisting>
		</example>
		<para>
		Configuring that file and running <command>sudo /etc/init.d/networking restart</> should set you on stage.
			</para>
			<para>
			In some cases you might want to change the network card's ethernet ("hardware") address. This is posible with the <command/ifconfig/ command, and you have to run it on each system boot, of course:
<screen>
ifconfig eth0 down
ifconfig eth0 hw ether BA:BE:BE:EF:D0:0D
ifconfig eth0 up
</screen>
		</para>
		</section>

		<section>
			<title>Hard disks</title>
			<para>
			As we've mentioned already, hard disks are recognized and work without any special setup. (Well, not really, they too are an option in the kernel configuration, but definitely all of the usual setups include the disk and filesystem drivers out of the box).
			</para>
			<para>
			One thing that you can do, however, is check the performace of your disks (cached and raw read performance). Install <application>hdparm</>, then run <command>sudo hdparm /dev/sda</> to get a feeling of what disks are about. (Note: old ATA disks on older Linux systems were called "hda". The distinction between "hda" and "sda" is a leftover from times when "hda" were strictly ATA and "sda" were strictly SCSI devices).
			</para>
<screen>
$ sudo hdparm /dev/sda

/dev/sda:
multcount    = 16 (on)
IO_support   =  1 (32-bit)
unmaskirq    =  1 (on)
using_dma    =  1 (on)
keepsettings =  0 (off)
readonly     =  0 (off)
readahead    =  8 (on)
geometry     = 1823/255/63, sectors = 29297520, start = 0
</screen>
			<para>
			To actually measure the throughput, first make sure the system isn't busy with anything that could influence the outcome (<command>top</> should report only 1 process running &mdash; and that being itself), then run <command>sync</> three times (to <emphasis>sync</>, or clean memory buffers by synchronizing to the disk <emphasis>now</>), and finally, run <command>sudo hdparm -tT /dev/<replaceable/T/d<replaceable/L/</>. 
			</para>
			<para>
			In <filename>/dev/<replaceable/T/d<replaceable/L/</>, <literal><replaceable/T/</> stands for disk type (which is <literal>s</> for SCSI, and <literal>h</> for IDE devices), and <literal><replaceable/L/</> stands for "number" which is actually letters of the alphabet, starting at <literal>a</>. If you had an IDE disk, it would most probably be <filename>/dev/sda</>. Actually, it would probably be nice to explain this "numbering" scheme properly: on typical PC motherboards, there are two IDE disk connectors (<emphasis>primary</> and <emphasis>secondary</>), each accepting a 40- or 80-wire cable with two connectors (<emphasis>master</> and <emphasis>slave</>) for peripherial devices. Altogether, this makes a total of 4 disks/CD-Roms that you can attach, and according to their position, they're assigned letters <literal/a/, <literal/b/, <literal/c/ or <literal/d/. With some other bus types (SCSI for example), the devices are just numbered "in order of appearance"; regardless, the name/number assignment principle stays the same. In case of newer setups using LVM or MD, devices like <literal>/dev/sda</literal> won't do you much good; run <command/mount/ to get an idea of proper device names in your setup.
			</para>
			<para>
			Anyway, speaking of <command>hdparm -tT</>, here's a sample output:
<screen>
$ sync; sync; sync; sudo hdparm -tT /dev/hda

/dev/hda:
Timing buffer-cache reads:   848 MB in  2.00 seconds = 424.00 MB/sec
Timing buffered disk reads:   90 MB in  3.01 seconds =  29.90 MB/sec
</screen>
			</para>
			<para>
			Interesting, though, how the statistics looked back in the day. Here's 
			a modern system from February 2010:
<screen>
$ sync; sync; sync; sudo hdparm -tT /dev/sdc

/dev/sdc:
Timing cached reads:   13570 MB in  2.00 seconds = 6794.06 MB/sec
Timing buffered disk reads:  278 MB in  3.02 seconds =  92.08 MB/sec
</screen>
			</para>
			<para>
			Now, what can we see here? <emphasis>Cache</> performance test measures the raw throughput achieveable from system RAM.
			<emphasis>Buffered</> test eliminates the cache and directly measures disk's ability to read the magnetic medium. For a PC (and &mdash; Ultra ATA &mdash; 80-column cable), <literal>30 MB/s</> was nice (older disks were in <literal>15 - 25 MB/s</> range, but now we managed to get in the 100 MB range per disk.
			One traditional SCSI/Unix disk manufacturer and popular SATA manufacturer today is &LNK12;, although
			the quality of their SATA disks at least has dropped enormously. Altogether, I've had the best
			experience (quality-wise) with Western Digital disks.
			<!-- TODO time-dependent -->
			</para>
		<!-- TODO sda=autotune, napomenuti kernel/Documentation za 
		svaki divajs -->
			<para>
			If your disk throughput is much worse than this, chances are that <emphasis>DMA</> (Direct Memory Access) is not enabled; check that first with <command>sudo hdparm /dev/sda | grep dma</>. If it's disabled, run <command>sudo hdparm -d1 /dev/sda</> and repeat the test.
			</para>
			<para>
			In any case, if you figure out any <application>hdparm</> settings that boost your disk performance, you'll want to add <literal>-k1K1</> to the options (to preserve settings over disk reset &mdash; something that <emphasis role='bold'>can</> happen during runtime), and you'll want to save the whole line in <filename>/etc/bootmisc.sh</> or somewhere, to have it run on each boot.
			</para>
			<para>
			If you have two disks, putting them on separate cables (in case they're not SATA which is one disk
			per cable) can further improve transfer rates.
			</para>
			<caution>
			<para>
			<!-- TODO using CD as rescue 
			TODO mounting using LABELS!!!
			TODO section on bootloaders
			-->
			Just don't rush and reposition the disk to which you installed &DEB;. If you do so, the device filename will change (from say, <filename>/dev/sda</> to <filename>/dev/hdc</>) and your system will not boot properly any more! Don't do this until you read this Guide and learn how to use rescue CDs.
			</para>
			<para>
			Actually, today you can even change disk order and partitions since most of the things target partitions
			by UUIDs (Unique Identifiers) and not physical position on the bus. Thumbs up for modern developments!
			</para>
			</caution>
		</section>

	<section>
		<title>CD/DVD-Roms</title>
		<para>
		Like hard disks, PC CD-Roms typically just work out of the box. There are some commands, however, that could be used to tune their exact behavior.
		</para><para>
		We could just say that the Linux kernel can drive CD-Roms in either standard IDE/ATAPI mode, or SCSI emulation. SCSI emulation was primarily used to allow <application/cdrecord/ burn CDs on ATAPI drives. This, however, is not needed anymore, as <application/cdrecord/ can now write to ATAPI devices as well.
		</para><para>
		Of the commands you can use with CD-Rom drives, there's <command/hdparm/ to retrieve their basic hardware information. And then there's the <command/setcd/ package that can control various other CD-specific settings, including drive speed and identification of the inserted CDs.
		</para><para>
		Finally, the standard, low-level CD-burning application is called <command/wodim/ and can, besides for burning, be used to eject the drive if it hanged in RAW mode and won't listen to the Eject button. You generally do not need to use <command/wodim/ if you have a graphical interface and a GUI program. But, using <command/wodim/ is trivial, all you need to write the file (usually an ISO image) to the CD/DVD is <command>wodim -vv -eject FILE_NAME.iso</command>! In case you need to create the .iso first, copy all files to one directory (the easiest, not to search for them), and then produce the .iso with <command>genisoimage -T -U -R -l -o mycd.iso DIR_NAME</command>.
		</para>
	</section>

	<section>
		<title>Graphics</title>
		<para>
		Graphic cards arena is pretty interesting. If you know something about the evolution of PC graphics cards, you know there were a little myriad of graphic "modes" invented, each with its pros and cons, and each with a different set of graphic cards that supported it. Those "modes" have surely put a certain burden on backward-compatibility; even modern PC graphic cards like &ATI; or &NVIDIA; that probably never see a console (terminal) mode still support dozens or even hundreds of various text modes.
		</para>
		<para>
		One of those modes is the standard character terminal mode, so you won't have any problems getting to the console (text mode) on PCs.
		</para>
		<para>
		One other supported standard is the VGA mode which allows a resolution of 640x480 pixels in 256 colors. (Just by the way, it means the screen alone took 640x480x8 bits &mdash; or about 307 kilobytes &mdash; to fit in memory).
		</para><para>
		Then there's VESA 2.0 which is supported by SVGATextMode (and which is quite a pain to set up) so we won't discuss it.
		</para><para>
		And there's VESA 2.0 in framebuffer mode. Instead of using the card's specific instruction set, you can initialize and use the card in framebuffer/VESA mode. This was quite attractive before, when it was easier to fire up the framebuffer mode than wait for months (should I say years?) before &XFREE86; (X Window System implementation) card-specific drivers became available. VESA 2.0 framebuffers allowed for good resolutions, but they too were limited to 256 colors. Another big drawback was a completely unaccelerated display which flickered even when you were moving a 2D window around the screen. Nowadays the Linux kernel does support the hardware framebuffer acceleration for most popular card groups.
		</para><para>
		Framebuffers are also a comfortable option for graphic cards that do not support native console mode (such as &APPLE;'s) or were using framebuffer by design, such as some from &SUN;. 
		</para>
		<para>
		The X Window implementation used today on Linux systems is <ulink url="http://www.x.org/">X.org</ulink>.
		You install it and it just works; it autodetects everything and doesn't even
		need the config file (<filename>/etc/X11/xorg.conf</filename>).
		And if you have an nVidia or ATI card, a program called <application/jockey-gtk/ will recognize
		that there are proprietary drivers available to increase performance, and it'll allow you to
		install the drivers on a point &amp; click. We've come a long way, indeed.
		</para>

	<section>
		<title>Modems</title>

	<section>
		<title>Telephone-line modems (of historical interest?)</title>
		<para>
		First of all, we must say that there are two main types of modems: real hardware modems, and handicapped modems called <emphasis>Winmodems</>.
		</para>
		<para>
		"Hardware modems" are the usual, full-featured modems. They are sometimes also called <emphasis>Rockwell</> or <emphasis>Hayes-compatible</> modems, they are attached to serial ports, and (being Hayes-compatible) they all support the standard &LNK13;. All external modems that you attach to the computer via serial cable are "hardware modems". Of internal modems that you plug into an ISA or PCI slot on the mainboard, usually only old ones (prior to year 1998 or even older) are "hardware modems".
		</para>
		<para>
		"Winmodems", on the other hand, are once again a disastrous invention from the PC world; basically they are modems with one $5 (five dollar, at the time of invention!) chip removed, whose tasks then need to be performed by the main system processor. Winmodems are only sold as internal (and that PCI) cards, and have practically flooded the post-millenium modem market; at most "modern" computer shops, they don't even know that Winmodem is not the only type of "modem". Winmodems do not have <emphasis>a single technical quality or a bright idea</> &mdash; it's quite the opposite. Such modems <emphasis>need special drivers to work at all</>, and even then you are lucky if they support some degenerated "AT" command set. Needless to say, Winmodems are a major annoyance because all the drivers are proprietary and closed-source. The <ulink url="http://www.linmodems.org">linmodems.org</> site is trying hard to help Winmodem owners, but it's really not worth it. Winmodems are a disgusting piece of "hardware", they smell bad, and you are better off passing them to the next lucky owner. If you can buy a real modem yourself, you're good; if you can persuade someone into swapping a real modem for your Winmodem, you're <emphasis>really</> good.
		</para>
		<para>
		In the meantime, since originally writing the Winmodems section, the manufacturers seem to have standardized on one or two chips, and basically it is possible to get Winmodems working quite comfortably. They are, of course, as crappy as they've always been, but at least the cost of set up is no longer higher than of winmodem itself.
		</para>
		<para>
	If you will be interested in connecting to ISPs, you will use the PPP protocol. If you'll want to use the modem in "terminal" mode, then the infamous <application/minicom/, <application/seyon/, <application/lrzsz/ or <application/modemu/ will be at your disposal.
		</para>
		<para>
		If you <emphasis>are</> interested in PPP connections, you simply need to run <command/sudo pppconfig/. It is a very convenient program that will let you configure different PPP ("dial-up") connections. If you name the connection <literal>ISP1</>, then running <command/sudo pon ISP1/ will call the specified number and connect. <command/plog/ will show some system log lines, and <command/poff/ will terminate the connection. Remember that the full log is accessible in <filename>/var/log/ppp.log</>, we redirected messages to that file earlier in the Guide when we configured the syslog daemon.
		</para>

		<para>
		Finally, it's worth noting that <command/pppconfig/ does no magic; it only modifies files <filename>/etc/ppp/peers/<replaceable/NAME/</> and <filename>/etc/chatscripts/<replaceable/NAME/</> (and, well, <filename>/etc/ppp/<replaceable/TYPE/-secrets</> if your ISP uses <emphasis>PAP</> or <emphasis>CHAP</> authentication method). For completness, we include a sample working configuration for a typical dial-up ISP connection.
		</para>
		<example>
			<title>/etc/ppp/peers/provider</title>
			<para>
			Notice that the string <literal><replaceable/USERNAME/</> should be replaced with the username you use to connect to the ISP. File <filename>/dev/ttyS<replaceable/0/</> represents the first COM port or, in DOS parlance, COM1 (for serial port 2, you would use <filename>/dev/ttyS1</>, and so on). Note that in case of internal modems, the ports would probably be <filename>/dev/ttyS2</> or <filename>/dev/ttyS3</>; your computer does have 4 serial ports even if only one or two are available on external connectors.
			</para>
<programlisting>
# This optionfile was generated by pppconfig 2.0.10. 
# 
#
hide-password 
noauth
connect "/usr/sbin/chat -v -f /etc/chatscripts/provider"
debug
/dev/ttyS<replaceable/0/
115200
defaultroute
noipdefault 
user <replaceable/USERNAME/
remotename provider
ipparam provider
</programlisting>
		</example>
		<example>
			<title>/etc/chatscripts/provider</title>
			<para>
			Notice that the number <literal><replaceable/1234567890/</> should be replaced with your ISP number. Also, the string <literal>ATx3m1</> is a setting you should use in most european countries &mdash; it instructs the modem not to wait for dial-tone (this can be set from the <command/pppconfig/ menu, <literal>Provider -> Advanced -> Modeminit</>).
			</para>
<programlisting>
# This chatfile was generated by pppconfig 2.0.10.
# Please do not delete any of the comments.  Pppconfig needs them.
# 
# ispauth PAP
# abortstring
ABORT BUSY ABORT 'NO CARRIER' ABORT VOICE ABORT 'NO DIALTONE' ABORT 'NO DIAL TONE' ABORT 'NO ANSWER' ABORT DELAYED
# modeminit
'' ATx3m1
# ispnumber
OK-AT-OK ATDT<replaceable/1234567890/
# ispconnect
CONNECT \d\c
# prelogin

# ispname
# isppassword
# postlogin

# end of pppconfig stuff
</programlisting>
		</example>
		<example>
			<title>/etc/ppp/pap-secrets</title>
			<para>
			<literal><replaceable/USERNAME/</> and <literal><replaceable/PASSWORD/</> need to be replaced with the actual values you use for authentication with the ISP, of course.
			</para>
<programlisting>
(none)  *       password
<replaceable/USERNAME/ provider <replaceable/PASSWORD/
</programlisting>
		</example>
		<para>
		Mentioned Debian PPP tools are definitely superior to any "ad-hoc" programs that you would employ, but <application>wvdial</> is worth mentioning because it can do a lot of auto-detection (basically, all you need to know to use <application>wvdial</> is your ISP phone number, user name and password). After installation, run <command>sudo wvdialconf /etc/wvdial.conf</> to create the configuration file. Then, running <command>wvdial</> should establish the connection. As usual, a working <filename>/etc/wvdial.conf</> is provided for completeness.
		</para>
		<example>
		<title>/etc/wvdial.conf</title>
		<para>
			<literal><replaceable/1234567890/</>, <literal><replaceable/USERNAME/</> and <literal><replaceable/PASSWORD/</> need to be replaced with the actual values you use for authentication with the ISP, of course.
		</para>
		<para>
		<filename>/dev/modem</> is a symbolic link to the modem device (<application>wvdial</> should detect it all). If it does not, and <filename>/dev/ttyS0</> were the real port (modem attached to the first serial port, or <emphasis>COM1</> in DOS parlance), you'd create the symlink manually by running <command>sudo ln -sf /dev/ttyS0 /dev/modem</>.
		</para>
		<para>
		<!-- TODO hwinfo -->
		Additionally, the <literal>l0m0</> part of the "init string" makes the modem speaker quiet during both dialling and the duration of the connection.
		</para>
<programlisting>
[Dialer Defaults]
Modem = /dev/modem
Baud = 115200
Init1 = ATZ 
Init2 = ATx3l0m0 S0=0
#Init3 = ATI 5
Phone = <replaceable/1234567890/
Username = <replaceable/USERNAME/
Password = <replaceable/PASSWORD/
</programlisting>
<para>
If <command/wvdial/ does not succeed in its mission, try going for an "all bets are off" approach &mdash; add <literal/Stupid Mode = 1/ to the config file and try one more time.
</>
		</example>
	</section>
	<!--
	<section>
		<title>ISDN modems</title>
		<para>
		</para>
	</section>
	-->
	<section>
		<title>Cable modems</title>
		<para>
		Cable modems first need to be connected to the computer by an ethernet (LAN) or USB cable.
		</para><para>
		If you're using the cable modem to connect to your ISP, then the ISP probably provided DHCP server on their side. In other words, you can simply define the interface to pick up the configuration from a DHCP server. Your <filename>/etc/network/interfaces</> file should simply look like this:
<programlisting>
auto eth0
iface eth0 inet dhcp
</programlisting>
		</para><para>
		It's useful to know that ISPs match your ethernet card hardware address before giving you the connection details and finally access. But sometimes you're forced to change your hardware ethernet address; for example, your card might get destroyed by a lightning, or your machine breaks down and you need to replace the card or temporarily move the modem to another computer. Calling the ISP to change your hardware address is sometimes not an option &mdash; they're suspicious when you call, or it takes a while for their changes to take effect. Fortunately however, in Linux, it is possible to manually change the hardware address of your network card. You can't write the address to the card's memory permanently though (you need to repeat it on each reboot), but that doesn't affect its usefulness. For a real example, please see <xref linkend="hw-lan">.
		</para>
	</section>
	<section>
		<title>ADSL modems</title>
		<para>
		ADSL modems also arrive in ethernet or USB cable versions.
		</para><para>
		ADSL modems usually work using the PPPoE (PPP over Ethernet) protocol. To make your life real easy, install <application>pppoe</>,
		<application>pppoeconf</> and <application>pppstatus</> packages.
		</para><para>
		If your modem is connected and turned on, <command>pppoe -A</> should find at least one PPPoE provider "on air". This is very simple and should be done at the beginning to minimize problems with <command>pppoeconf</>. If you see no providers listed by <command>pppoe -A</>, then something's wrong. In newer Debian installations, <command/pppoe/ was replaced by <command/pppoe-discovery/.
		</para><para>
		In the next step, you should read <filename>/usr/share/doc/pppoeconf/</> to read a well-written ADSL introduction and practical HOW-TO. Running <command>pppoeconf</> and following the instructions from the mentioned documentation file should be enough that you configure your ADSL modem. Once you do it, you can connect using <command/pon dsl-provider/ and disconnect using <command/poff/. If you've redirected local2 stream to a separate file (as shown earlier in the Guide in the syslog daemon section), then you can also run <command/plog/ to see latest "news" regarding the connection.
		</para>
	</section>
	</section>

	<section>
		<title>Mice (console)</title>
		<para>
		Besides in the X Window System (which will be covered separately), you can also use mouse in your text consoles. That is, by the way, very convenient, because you can simply select text with the LMB (Left Mouse Button) and paste with the MMB (Middle Mouse Button).
		</para>
		<para>
		The traditional program handling console mice is called <application/gpm/. After installing <application>gpm</>, run <command>sudo gpmconfig</> to configure it. The device file to use is <filename>/dev/psaux</> for PS/2 port mice, <filename>/dev/ttyS<replaceable/N/</> for serial, and <filename>/dev/usb/mouse<replaceable/N/</> for USB (where <literal><replaceable/N/</> is a number dependent on the port assigned, starting at <literal>0</>). Of protocol types, many exist and many are supported; on PCs, the "auto-sensing" <literal>autops2</> is the best (and default) choice. <emphasis>Repeat protocol</> is a convenient way to let <application>gpm</> handle mice, and "repeat" events on file <filename>/dev/gpmdata</> so that other applications (such as X Window System) could use the same events. This, however, is not necessary since nowadays they can both open the mouse file directly.
		</para>
		<para>
		You can start, stop or restart the <application>gpm</> daemon by invoking, for example, <command>sudo /etc/init.d/gpm restart</>.
		</para>
		<para>
		And again, <command>gpmconfig</> does no magic, it simply modifies <database class='field'>/etc/gpm.conf</> which I provide for completeness.
		</para>
		<example>
			<title>/etc/gpm.conf</title>
<programlisting>
#  /etc/gpm.conf - configuration file for gpm(1)
#
#  If mouse response seems to be to slow, try using
#  responsiveness=15. append can contain any random arguments to be
#  appended to the commandline.  
#
#  If you edit this file by hand, please be aware it is sourced by
#  /etc/init.d/gpm and thus all shell meta characters must be
#  protected from evaluation (i.e. by quoting them).
#
#  This file is used by /etc/init.d/gpm and can be modified by
#  /usr/sbin/gpmconfig.
#

# PS/2 Mouse example
device=/dev/psaux
responsiveness=
repeat_type=
type=autops2
append=""
sample_rate=
</programlisting>
		</example>
	</section>

	<section>
		<title>Audio cards</title>
		<para>
		The Linux audio drivers story is quite interesting. Traditionally, Linux used the Open Sound System (OSS) architecture. It was written by guys who ran their own company and wanted to make money on audio drivers, and only contributed old or uncommon drivers to the Linux kernel tree.
		</para><para>
		This was, as you might guess, pretty unfortunate, so the folks got together to rewrite the audio system and get rid of the hog. The result was ALSA - Advanced Linux Sound Architecture. ALSA is the default sound system in the Linux kernel 2.6 series.
		</para>
	</section>

<!--
	<section>
		<title>USB gadgets</title>
		<para>
		</para>
	</section>
-->

	<section>
		<title>Digital cameras</title>
		<para>
		Some of the digital cameras were (or still are) supported directly by the Linux kernel, allowing you to mount their memory cards as the usual disks.
		</para><para>
		One other, and more common way, is to use user-space drivers for the cameras. The GNU <application/gphoto2/ application supports numerous camera models (533 in my version, not counting models that are not listed but work using an existing driver!), and does various camera-specific tricks. Here's how I use it:
<programlisting>
gphoto2 --port usb: --get-all-files --camera "Kodak DC3400"
</programlisting>
		</para><para>
		Another common trick these days is to plug the memory card in some universal reader device and then mount it as a standard disk. This way it's also possible to upload files to the card even if the camera itself doesn't support uploading (so you can't use <application/gphoto2/).
		</para>
	</section>

	<section>
		<title>Printers</title>
		<para>
		Traditionally, printing in Unix was done by the BSD <application/lpr/
		system (<literal>lp</literal> or <literal>lpr</literal> stand for
		<literal>Line Printer</literal>, although printing is all but limited
		to line/matrix printers, of course). Afterwards, <application/lprng/
		(lpr New Generation) appeared as well, offering some enhancements while
		preserving compatibility. The main configuration file was 
		<filename>/etc/printcap</filename>, describing printers' capabilities.
		</para><para>
		Probably the three most relevant printing-related commands are
		<command/lp/, <command/lpq/ and <command/lprm/. They print files, list,
		and cancel print jobs. All rival printing systems offer a compatibility 
		mode in which all those commands are command-line compatible.
		</para><para>
		With PostScript printers it's quite easy. With PC printers, as always 
		&mdash; the things are a little different. To overcome printing problems,
		(primarily on GNU/Linux PCs, but on other Unices as well), CUPS &mdash;
		Common Unix Printing System &mdash; was developed, and it's what we are
		going to use. Let's first install it:
<programlisting>
$ sudo apt-get install cupsys cupsys-{bsd,client} foomatic-db foomatic-filters-ppds
</programlisting>
		</para><para>
		By default, CUPS listens on &LNK14;. Visit the page with your web browser, and you'll be able to perform printer administration tasks from quite an usable web GUI.
		<emphasis role='bold'>The username and password you're asked for are "<literal>root</literal>", and root's password</emphasis>.
		</para><para>
		For details on supported printers and the drivers you can use, surely visit &LNK15;.
		</para><para>
		CUPS can also be configured directly, just using config files in 
		<filename class='directory'>/etc/</filename>, but that is out of the scope
		of this Guide.
		</para><para>
		Here's what I wrote years ago in this section: "Printer setup is <emphasis role='bold'>still</emphasis> unnecessarily too hard to get right, but hopefully things will get better." Well, things have surely changed for the better. Almost all printers are nowadays recognized by Cups (auto-detection finds them and the drivers exist). What's more, if you're using a modern desktop, such as &GNOME;, &XFCE; or &KDE;, or a more "out of the box" oriented flavor of Debian, such as Ubuntu, there's a great chance the printer will be automatically recognized and installed with the appropriate driver <emphasis/as soon as you plug the cable to the computer/!
		</para>
	</section>

<!--
	<section>
		<title>Scanners</title>
		<para>
		</para>
	</section>
	-->

	</section>

</chapter>

