Physical Devices  «Prev  Next»
Lesson 3 Mapping devices to files
ObjectiveList the device-to-file mapping conventions for your system.

Mapping Devices to Files

Determining from the name which device special file corresponds to which physical device is not always straightforward. For disk drives, several sets of conventions are fairly common. Rather than trying to spell out rules, the following table presents some examples from which the general principles can be deduced:
UNIX version Filename Device
Linux /dev/hda1 hd=IDE disk drive; a=first drive on system; 1=partition number
  /dev/sdb4 sd=SCSI disk drive; b=second drive on system; 4=partition number
SunOS /dev/sd1c sd=SCSI drive; 1=device number on controller; c=partition
System V (Solaris, HP-UX) /dev/dsk/c0d2s3 SCSI controller 0, device number 2, partition 3
  /dev/dsk/c0t0d3s2 SCSI controller 0, LUN 0, device 3, partition 2
  /dev/rdsk/c0d3s2 SCSI controller 0, device 3, partition 2 (raw device access)
In addition, systems other than Linux provide a parallel set of device special files for "raw" device access. Raw devices can be read block by block, like a tape drive or other unformatted device. This capability is used by backup programs or other programs that must manipulate the disk at a low level. These files are usually marked with an r somewhere in the name.

HP-UX

HP-UX and AIX systems provide some tools for relating devices to files. On HP-UX, the command
ioscan -f –n

yields a fairly informative list of devices and special files.

AIX

On AIX, the command
lscfg –v

gives a complete description of available devices. Note that both of these commands will tell you which devices are actually available, in addition to relating the names to physical devices.

Linux

Linux does not have such complete information available. On Linux, you can obtain a list of which devices are installed on your machine by listing the file /proc/devices:
$ cat /proc/devices
Character devices:
1 mem
2 pty
3 ttyp
4 ttyp
5 cua
7 vcs
10 misc
Block devices:
1 ramdisk
2 fd
3 ide0
9 md
22 ide1

This output tells you, for example, that major block device 3 is the first IDE controller on this machine.
In the simulation below, you will compare the /proc/devices file with the /dev file and determine which devices are on the IDE controller.
1)
2)
3)
  1. You are already logged in with root privileges. Use the cat command to list /proc/devices so you can view the major devices available on your system. Remember that /proc/devices is not really a file. Therefore, you cannot use ls -l.
  2. View devices on system
  3. cat /proc/devices
  4. Type cat /proc/devices in order to view the major devices on your system.
  1. Now, compare the character and block device listings with the contents of the /dev directory. According to the readout, the ttyp device is on the IDE controller. Suppose that you wish to use hdparm to find out the size of the hard disk /dev/hda in this machine. Run hdparm on /dev/hda to discover the size of your hard drive. Type /sbin/hdparm /dev/hda.
  2. Discover size of hard drive
  3. /sbin/hdparm /dev/hda
  4. The command you have entered is incorrect. Please check the instructions and try again.
  1. The size of the hard drive is 2.5 GB. The geometry entry reads 2496876. sectors. If you round this figure up, it comes to 2.5 GB. Assuming 1K per sector, this is essentially 2.5GB. This is the end of the simulation. Click the Exit button.

Available devices on Linux

Here are the steps you went through to list the available devices on a Linux machine:
  1. You are already logged in with root privileges. Use the cat command to list /proc/devices so you can view the major devices available on your system. Remember that /proc/devices is not really a file. Therefore, you cannot use ls -l to view it.
    Solution: cat /proc/devices
  2. Now, compare the character and block device listings with the contents of the /dev directory. According to the readout, the ttyp device is on the IDE controller. Suppose that you wish to use hdparm to find out the size of the hard disk /dev/hda in this machine. Run hdparm on /dev/hda to discover the size of your hard drive. Type /sbin/hdparm /dev/hda.
  3. The size of the hard drive is 2.5 GB. The geometry entry reads 2496876. sectors. If you round this figure up, it comes to 2.5 GB. Assuming 1K per sector, this is essentially 2.5GB.