In Linux, partitions are represented by device files. These are phoney files located in /dev. Here are a few entries, which come from executing `ls -l` while in the /dev dirtectory::
brw-rw---- 1 root disk 3, 0 May 5 1998 hda brw-rw---- 1 root disk 8, 0 May 5 1998 sda crw------- 1 root tty 4, 64 May 5 1998 ttyS0A device file is a file with type c ( for "character" devices, devices that do not use the buffer cache) or b (for "block" devices, which go through the buffer cache). In the listing above, this is indicated by the first character of each line. In Linux, all disks are represented as block devices only.
/dev/hda
to /dev/hdd
. Hard
Drive A(/dev/hda
) is the first drive and
Hard Drive C /dev/hdc
) is the third.
drive name | drive controller | drive number | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
/dev/hda
|
/dev/hda
is the first drive (master) on the
first IDE controller and /dev/hdd
is
the second (slave) drive on the second controller (the fourth IDE drive in the computer).
drive name | drive controller | drive number | partition type | partition number | |||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
/dev/hda1
|
/dev/hdb2
. The partition type
(primary) is listed in the
table above for clarity, although the concept is not explained until
Section 3.
drive name | drive controller | drive number | partition type | partition number | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
/dev/sda1
|
/dev/sdb1
. In the table above, the drive number is
arbitraily chosen to be 6 to introduce the idea that SCSI ID numbers do not map onto device names under
linux.drive name | drive controller | drive number | partition type | partition number | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
/dev/hdb1
|
This is all you have to know to deal with linux disk devices. For the sake of completeness, see Kristian's discussion of device numbers below.
$ ls -l /dev/hda
brw-rw---- | 1 | root | disk | 3, | 0 | Jul 18 1994 | /dev/hda |
permissions | owner | group | major device number | minor device number | date | device name |
When accessing a device file, the major number selects which device
driver is being called to perform the input/output operation. This
call is being done with the minor number as a parameter and it is
entirely up to the driver how the minor number is being
interpreted. The driver documentation usually describes how the driver
uses minor numbers. For IDE disks, this
documentation is in
/usr/src/linux/Documentation/ide.txt
. For SCSI, disks, one would expect such documentation in
/usr/src/linux/Documentation/scsi.txt
, but it isn't
there. One has to look at the driver source to be sure (
/usr/src/linux/driver/scsi/sd.c:184-196
). Fortunately,
there is Peter Anvin's list of device numbers and names in
/usr/src/linux/Documentation/devices.txt
; see the entries
for block devices, major 3, 22, 33, 34 for IDE
and major 8 for SCSI, disks. The major and minor
numbers are a byte each and that is why the number of partitions per
disk is limited.