Devices

A device file is a file with type c (for 'character' devices, devices that do not use the buffer cache) or b (for b'lock' devices, which go through the buffer cache). In Linux, all disks are represented as block devices only.

Device names

Naming Convention

By convention, IDE drives will be given device names /dev/hda to /dev/hdd. Hard Drive A (/dev/hda) is the first drive and Hard Drive C (/dev/hdc) is the third.

Table - IDE controller naming convention

Drive nameDrive controllerDrive number
/dev/hda11
/dev/hdb12
/dev/hdc21
/dev/hdd22

A typical PC has two IDE controllers, each of which can have two drives connected to it. For example, /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).

Name Assignment

SCSI drives have ID numbers which go from 1 through 15. Lower SCSI ID numbers are assigned lower- order letters. For example, if you have two drives numbered 2 and 5, then #2 will be /dev/sda and #5 will be /dev/sdb. If you remove either, all the higher numbered drives will be renamed the next time you boot up.

What is Udev?

  • Udev is the device manager for the Linux 2.6 kernel that creates/removes device nodes in the /dev directory dynamically. It is the successor of devfs and hotplug.

  • It runs in userspace and the user can change device names using Udev rules.

  • Udev depends on the sysfs file system which was introduced in the 2.5 kernel.

  • It is sysfs which makes devices visible in user space. When a device is added or removed, kernel events are produced which will notify Udev in user space.

  • The external binary /sbin/hotplug was used in earlier releases to inform Udev about device state change. That has been replaced and Udev can now directly listen to those events through Netlink

Logical Partitions

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.

Partition Types

Partition Types

A partition is labeled to host a certain kind of file system not to be confused with a volume label. Such a file system could be the linux standard ext2 file system or linux swap space, or even foreign file systems like (Microsoft) NTFS or (Sun) UFS. There is a numerical code associated with each partition type.

For example, the code for ext2 is 0x83 and linux swap is 0x82.

To see a list of partition types and their codes, execute

# /sbin/sfdisk -T

Foreign Partition Types

The partition type codes have been arbitrarily chosen and they are particular to a given operating system. Therefore, it is theoretically possible that if you use two operating systems with the same hard drive, the same code might be used to designate two different partition types. OS/2 marks its partitions with a 0x07 type and so does Windows NT’s NTFS.

MS-DOS allocates several type codes for its various flavors of FAT file systems: 0x01, 0x04 and 0x06 are known. DR-DOS used 0x81 to indicate protected FAT partitions, creating a type clash with Linux/Minix at that time, but neither Linux/Minix nor DR-DOS are widely used any more.

Primary Partitions

The number of partitions on an Intel-based system was limited from the very beginning: The original partition table was installed as part of the boot sector and held space for only four partition entries. These partitions are now called primary partitions.

Logical Partitions

  • One primary partition of a hard drive may be sub partitioned. These are logical partitions.

  • The primary partition used to house the logical partitions is called an extended partition and it has its own file system type (0x05).

  • Unlike primary partitions, logical partitions must be contiguous. Each logical partition contains a pointer to the next logical partition, which implies that the number of logical partitions is unlimited.

  • However, linux imposes limits on the total number of any type of partition on a drive, so this effectively limits the number of logical partitions. This is at most 15 partitions total on an SCSI disk and 63 total on an IDE disk.

Swap Partitions

  • Every process running on your computer is allocated a number of blocks of RAM.

  • These blocks are called pages. The set of in-memory pages which will be referenced by the processor in the very near future is called a working set.

  • Linux tries to predict these memory accesses (assuming that recently used pages will be used again in the near future) and keeps these pages in RAM if possible.

  • If you have too many processes running on a machine, the kernel will try to free up RAM by writing pages to disk. This is what swap space is for.

  • It effectively increases the amount of memory you have available. However, disk I/O is about a hundred times slower than reading from and writing to RAM.

  • If memory becomes so scarce that the kernel pages out from the working set of one process in order to page in for another, the machine is said to be thrashing. Swap space is something you need to have, but it is no substitute for sufficient RAM.

  • Linux divides its physical RAM (random access memory) into chucks of memory called pages.

  • Swapping is the process whereby a page of memory is copied to the preconfigured space on the hard disk, called swap space, to free up that page of memory.

  • The combined sizes of the physical memory and the swap space is the amount of virtual memory available.

Subscribe For More Content