Configure Linux Disk Drive, Task 2.5

Linux system performance and stability relies heavily on the hard drive disk configuration. Learn more here.

Task 2.5: Configure Disk Devices

Disk input/output is at the heart of a Linux system. Everyday operations—launching programs, saving files, and so on—entail reading from and writing to disks. Thus, your hard disk configuration is a major factor in your overall system performance and stability.

Task 2.2 described how to learn some of the basics of your hard disk configuration. Phase 5 covers high-level hard disk configuration—partitioning and preparing filesystems. This task covers low-level hard disk identification and tuning procedures.

Scenario

You're preparing a new computer that's to function as a file server on your local network. In order to provide the best performance, you want to check the hard disk configuration and, if necessary, tweak it to improve its speed.

Scope of Task

This task involves running a few utilities to verify the presence of particular types of disk hardware and to check your hard disk performance. You may also want to run programs to improve disk performance and modify boot files to make these changes persistent across reboots.

Duration

This task should take half an hour or so to complete. Once you're familiar with the tools involved, you can check and tune your hard disk configuration in a few minutes.

Setup

Log into your Linux computer and acquire rootprivileges. Most of the tools you'll use in this task cannot be run as an ordinary user, although one or two can be.

Caveats

Aside from the usual caveats about using root privileges, checking your disk hardware configuration isn't particularly risky; however, tweaking that configuration is dangerous. Setting incorrect disk options can cause a computer to lock up completely, requiring a hard reset, which in turn can sometimes cause data loss. Thus, if you have important data files on your computer, be sure to back them up before proceeding with this task.

Procedure

This task involves three steps: identifying your disk hardware, testing your disk performance, and adjusting options that influence disk performance. You'll perform the first two tasks no matter what type of disk hardware you have. You might or might not actually do the final part of the task, depending on your disk hardware and the results of your disk performance test.

Identifying Your Hardware

Linux treats hard disks as belonging to one of two categories:

ATA disks Advanced Technology Attachment (ATA) disks, also known as Integrated Device Electronics (IDE) disks, have long been the most common type on x86 hardware. Modern x86 motherboards invariably include ATA controllers, and ATA drives have typically been less expensive than other types of drives. In the past few years, ATA has spawned a subtype, Serial ATA (SATA); the older ATA drives are now often referred to as Parallel ATA (PATA).

SCSI disks Small Computer System Interface (SCSI) disks have traditionally been used on high-performance workstations and servers. In the past, they were common on Macintosh computers too, but many modern Macs use ATA disks. SCSI disks tend to be more expensive than ATA disks of similar capacity, but manufacturers often release their best-performing designs as SCSI disks, and SCSI has some inherent design advantages compared to ATA, so you do get better performance for that extra cost.

Several other types of disk devices exist, but Linux tends to treat them as if they belonged to one of these two categories—in most cases, as SCSI disks. In fact, many Linux SATA drivers appear in the SCSI driver category, although this isn't universally true. USB and FireWire drives are also usually treated as SCSI disks. For the remainder of this task, therefore, I will refer to ATA and SCSI disks, but your actual disk hardware might be neither of these things. If you have an SATA disk, it could be either an ATA disk or a SCSI disk from the Linux driver perspective.

If your Linux system is up and running and if you can use your disk, one easy way to identify it is to use the df command:

$ df 
Filesystem 1K-blocks Used Available Use% Mounted on 
/dev/sdb6 977180 322112 655068 33% / 
udev 256024 196 255828 1% /dev 
/dev/mapper/usr 6291260 5762756 528504 92% /usr 
/dev/mapper/home 17825244 11384232 6441012 64% /home 
/dev/hda6 101089 35111 61803 37% /boot 

This command displays disk free space statistics for mounted filesystems. This example output shows four types of filesystem:

ATA filesystem The last entry in the output (/dev/hda6, mounted at /boot) is for an ATA disk. Such disks have device filenames of the form /dev/hdxn, where x is a letter from an onward and n is a number from 1 upward.

SCSI filesystem SCSI disks have device filenames of the form /dev/sdxn, where xis a letter from aonward and nis a number from 1upward. The first entry in the preceding output, for the root (/) filesystem, is for a SCSI disk.

LVM filesystems The preceding output shows two Logical Volume Management (LVM) filesystems, /usr and /home. These filesystems reside on volumes that constitute one or more physical partitions managed by Linux LVM tools and identified by entries in the /dev/mapper directory tree. LVM is a way to create more flexible partitions, but its configuration is beyond the scope of this task. LVM filesystems can reside on underlying ATA, SCSI, or both types of disk. udev filesystem Finally, the /dev directory is handled, on this system, by the udev filesystem. As described in Task 2.4, this is a pseudo-filesystem that automatically adds device entries for your hardware. It doesn't correspond to any real disk hardware.

You should be aware that df can only identify hardware that's currently being used in the form of mounted filesystems. If you see LVM filesystems, they could reside on a disk that's not otherwise identified by df output. For instance, in the preceding example, there might be a /dev/sda, /dev/hdb, or other disks that aren't immediately obvious from the dfoutput. One way to track down such additional disks is by using fdisk to display the partition tables of disk devices:

# fdisk -l /dev/sdb 

Disk /dev/sdb: 81.9 GB, 81964302336 bytes 
16 heads, 63 sectors/track, 158816 cylinders 
Units = cylinders of 1008 * 512 = 516096 bytes 
Device Boot Start End Blocks Id System 
/dev/sdb1 1 9689 4883224+ a5 FreeBSD 
/dev/sdb2 9690 158816 75160008 5 Extended 
/dev/sdb5 9690 13565 1953472+ c W95 FAT32 (LBA) 
/dev/sdb6 13566 15504 977224+ 83 Linux 
/dev/sdb7 15505 60073 22462744+ 8e Linux LVM 
/dev/sdb8 60074 158816 49766440+ 8e Linux LVM 

If you see a partition table, or even output with disk size information but no partition information or gibberish for partition information, then a disk is attached. If you see no output, though, then no disk is attached. (Removable disk drives, such as Zip drives and CD-ROM drives, will yield no output unless a disk is inserted in the drive.) You can also obtain a complete list of SCSI devices by examining the /proc/scsi/scsi pseudo-file:

$ cat /proc/scsi/scsi 
Attached devices: 
Host: scsi0 Channel: 00 Id: 05 Lun: 00

 Vendor: IOMEGA Model: ZIP 100 Rev: D.13

 Type: Direct-Access ANSI SCSI revision: 02 
Host: scsi2 Channel: 00 Id: 00 Lun: 00

 Vendor: ATA Model: Maxtor 6Y080M0 Rev: YAR5

 Type: Direct-Access ANSI SCSI revision: 05 

This output reveals two SCSI drives: an Iomega Zip 100 removable disk and a Maxtor 6Y080M0 disk. The latter is actually an SATA drive that's handled by an SATA driver in the SCSI section of the Linux kernel, as revealed by the Vendor: ATA part of the output. These devices are on two different SCSI host adapters (scsi0 and scsi2); the second is actually the computer's SATA controller.

Testing Disk Performance

Now that you know what your hard disks are, you can test their performance. You can do this with the hdparm utility, which includes two performance-testing options: -t tests raw disk input/output speed and -T tests cached disk input/output speed. The latter test is effectively a test of your system's memory (RAM) performance, but if you use both options, hdparm includes a correction factor for memory performance when reporting the non-cached results, improving accuracy. You can test either ATA or SCSI disk performance using this command:

# hdparm -tT /dev/hdb 

/dev/hdb:

 Timing cached reads: 932 MB in 2.01 seconds = 463.37 MB/sec

 Timing buffered disk reads: 120 MB in 3.03 seconds = 39.60 MB/sec 

Ideally, you should run this command two or three times to ensure that you're getting consistent results. (Normal disk accesses by background processes can throw off the results of a disk benchmark.) This example shows a disk input speed of 39.60MB/s, with a cached (memory) read speed of 463.37MB/s. If you compare the numbers you obtain to the ones found on your hard disk manufacturer's data sheet, you'll probably be disappointed. Disk manufacturers generally advertise benchmark results taken under ideal circumstances, and it's not unusual to get results showing half the speed the manufacturer claims. Also, manufacturers often advertise their drives' interface speed, which will be better than the speed for reading data off the actual disk platters. Be sure to look up the disk's internal data transfer rate; this will be the limiting factor for all but short data transfer bursts.

As a general rule, modern hard disks are likely to achieve speeds of at least 30MB/s, and quite possibly well above that level. A speed of 16MB/s or less, at least with a new disk, indicates that the disk is seriously misconfigured.

Tweaking Disk Performance

If you find that your disk performance is truly sub-par, you may want to attempt to improve it. Linux's ATA drivers provide the ability to tune disk performance in software, but this option doesn't exist for SCSI drivers. Thus, if you have SCSI devices and find that performance is sub-par, you may need to look at your SCSI cabling, SCSI termination, and other issues.

Both SCSI and ATA have undergone many revisions over the years. If you're using an older or cheap SCSI host adapter or ATA controller with a new hard disk, replacing the host adapter or controller may dramatically improve your disk performance.

To tune an ATA disk's performance, you can use the hdparm utility, but you use the -X mode option to set the Direct Memory Access (DMA) transfer mode. Table 2.3 summarizes ATA disk DMA transfer modes and hardware. You can specify modes in several ways, the most mnemonic of which are sdmaxfor simple DMA level x, mdmaxfor multiword DMA level x, and udmax for UltraDMA level x.

TABLE 2.3 ATA Hardware Types


Official Name Unofficial Names Maximum Speed Added DMA Modes Cable Type
ATA-1 IDE 11.1MB/s 0, 1, 2, Multiword 0 40-wire
ATA-2 EIDE 16.6MB/s Multiword 1, Multiword 2 40-wire
ATA-3 16.6MB/s 40-wire
ATA-4 UltraDMA/33, ATA/33 33.3MB/s UltraDMA 0, UltraDMA 1, UltraDMA 2 40-wire or 801wire
ATA-5 UltraDMA/66, ATA/66 66.6MB/s UltraDMA 3, UltraDMA 4 801wire
ATA-6 UltraDMA/100, ATA/100 100MB/s UltraDMA 5 80 wire
ATA-7 UltraDMA/133, ATA/133 133MB/s UltraDMA 6 80 wire

At the time of this writing, an ATA-8 standard is under discussion, but it has not yet been finalized. In practice, hardware often leads standards, so devices with ATA-8 features will likely become available before the standard is finalized.

If you're certain that your ATA disk and its controller both support a particular mode say, ATA-7), you can activate it as follows:

# hdparm -X udma6 /dev/hda

Specifying a DMA mode that's too advanced for your hardware can result in the hardware becoming unresponsive. In the case of a hard disk, this can mean that you won't be able to access the disk or cleanly shut down the computer. Thus, you should not use hdparm in this way unless you're willing to take a risk.

Using hdparm to adjust your disk's performance creates a temporary change—once you reboot the computer, your system will revert to its default behavior. In most cases, this is fine, because your computer sets the appropriate mode at boot time. If you find that adjusting your DMA mode improves performance, though, you may want to add your hdparmcommand to an appropriate system startup script. Appropriate startup scripts vary from one distribution to another. On Red Hat, Fedora Core, Mandrake, and Slackware, the script is /etc/rc.d/ rc.local; on openSUSE, edit /etc/rc.d/boot.local; for Debian and its derivatives, create a script in the /etc/rc.boot directory; and on Gentoo, edit /etc/conf.d/local.start.

Another way to tweak disk performance is to change the driver. To do this, you'll need to know about the ATA controller or SCSI host adapter that handles the disk. You may be able to find updated drivers in a newer kernel, on your hardware manufacturer's Webpage, or on a third-party Web page. Try doing a Web search, if necessary. Another option, particularly for some SATA disks, is to change from an ATA driver to an SATA driver or vice versa. Drivers for both disk classes are available for some SATA controllers, so you may be able to switch. If you try this, though, be aware that your disk identifiers will change. This means you'll need to edit entries in /etc/fstab, and you may need to adjust your boot loader configuration as well. If something goes wrong in your change, your system may be rendered unbootable, so be ready with an emergency recovery disk.

Criteria for Completion

To complete this task, you should have correctly identified all your computer's hard disks. (Many computers have a single hard disk, although they may have removable disk devices.) You should also have checked your hard disks' performance with hdparm. If that performance is unacceptably low and if it's an ATA disk, you should try to improve it via hdparm and, if necessary, add an appropriate line to a startup script to make that change persistent when you reboot the computer.

Use the following table of contents to navigate to chapter excerpts, or click here to view Chapter 2 in its entirety.



Managing Linux hardware and the kernel
  Home: Introduction
 Part 1: Set BIOS Options for Linux: task 2.1
 Part 2: Know the hardware in your computer, task 2.2
 Part 3: Resolve hardware conflicts, task. 2.3
 Part 4: Configure USB devices to Linux, task. 2.4
 Part 5: Configure Linux Disk Drive, task 2.5
 Part 6: Configure and compile a kernel for Linux, task 2.6
 Part 7: Use Linux power management features, task 2.7
 Part 8: Configure X options for Linux, task 2.8
 Part 9: Manage X logins for Linux, task 2.9
 Part 10: Use X for day-to-day operations, task 10
ABOUT THE BOOK:   
Hit the ground running with the street-smart training you'll find in Linux Administrator Street Smarts: A Real World Guide to Linux Certification Skills. Using a "year in the life" approach, it gives you an inside look at Linux administration, with key information organized around the actual day-to-day tasks, scenarios, and challenges you'll face in the field. This valuable training tool is loaded with hands-on, step-by-step exercises covering all phases of Linux administration. Purchase the book from Wiley Publishing
ABOUT THE AUTHOR:   
Roderick W. Smith left a career in academia to pursue his passion for computers. He is particularly interested in Linux and Open Source Software, and has written several books.

This was first published in February 2007
This Content Component encountered an error

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

MicroscopeUK

SearchCloudProvider

SearchSecurity

SearchStorage

SearchNetworking

SearchCloudComputing

SearchConsumerization

SearchDataManagement

SearchBusinessAnalytics

Close