![]() |
![]() |
![]() |
In Linux, partitions are represented by device files. A 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 Linux, all disks are represented as block devices only. Unlike other Unices, Linux does not offer "raw" character versions of disks and their partitions.
The only important thing with a device file are its major and minor device number, shown instead of the files size:
$ ls -l /dev/hda
|
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
Primary partitions on a disk are 1, 2, 3 and 4. So Each partition entry has a starting and an ending block address
assigned to it and a type. The type is a numerical code (a
byte) which designates a particular partition to a certain type
of operating system. For the benefit of computing consultants
partition type codes are not really unique, so there is always
the probability of two operating systems using the same type
code.
/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.
device files have certain names and many system
programs have knowledge about these names compiled in. They
expect your IDE disks to be named /dev/hd*
and your SCSI disks
to be named /dev/sd*
. Disks are numbered a, b, c and so on, so
/dev/hda
is your first IDE disk and /dev/sda
is your first SCSI
disk. Both devices represent entire disks, starting at block
one. Writing to these devices with the wrong tools will
destroy the master boot loader and partition table on these
disks, rendering all data on this disk unusable or making your
system unbootable. Know what you are doing and, again, back up
before you do it.
/dev/hda1
is
the first primary partition on the first IDE disk and so on.
Logical partitions have numbers 5 and up, so /dev/sdb5
is the
first logical partition on the second SCSI disk.