Device name and device number in Linux

Source: Internet
Author: User
Tags naming convention

See Dr. Zhao Jiong's "Linux 0.11 source code comment" has been two or three weeks, starting from today, some personal summary and sentiment sub-standard inscribed out, chat for memory for later review.
In the/linux/boot/bootsect.s of linux0.11 source code, there is a label definition Root_dev

! Root_dev:0x000-same type of floppy as boot.
! 0x301-first partition on First drive etc
Root_dev = 0x306

Here, Root_dev is the device number of the system-specified root file system. Everyone knows that "everything is a file" in a Linux system, so the device is also a file, where the 0x306 is the device number of the device on which the root file system resides.
It is important to note thatthe name of the device number used in Linux0.11 is an old-fashioned naming convention, unlike today's Linux system device number naming conventions. The following are explained separately.

1, old Linux device number naming rules:
Device number = Main device number * 256 + secondary device number (Dev_no = (major << 8) + minor). Here the main device number is defined in advance (1-memory, 2-disk, 3-hard disk, 4-ttyx,5-tty,6-parallel port, 7-non-named pipe), for example, for the hard disk, the main device number is 3, so 3*256+0=0x300 is the first hard disk in the system number, followed by the following name:
Device number device file corresponding to device
0x300/dev/hd0 the first hard drive in a system
The first partition of the first hard disk in a 0X301/DEV/HD1 system
The second partition of the first hard disk in the 0X302/DEV/HD2 system
The third partition of the first hard disk in the 0X303/DEV/HD3 system
The fourth partition of the first hard disk in the 0X304/DEV/HD4 system

Second hard drive in 0X305/DEV/HD5 system
The first partition of the second hard disk in a 0X306/DEV/HD6 system
······ 2, modern Linux device number naming rules:
Modern Linux to manage a variety of devices are very rich, including hard disk, u disk, printer and other devices. We still target the device naming rules with hard drives. Linux divides the hard disk into two categories: the first is the traditional IDE hard disk, using the HD logo, the second is SATA, SCSI, USB hard disk, USB drive (strictly speaking, the USB drive does not count hard disk), etc., are marked with SD, (HD and SD is the main device name of these two types of hard disk).
Therefore, for the IDE hard disk in the system, the HDA,HDB,HDC,HDD is used to mark the number 1th (typically up to 4 drives). When we use 1 hard drives, we usually install them on the main interface on the main IDE so the hard disk device name is usually HDA on a single hard drive. The numbers behind HDA are used to indicate each partition of the drive, as follows:

devices that correspond to device files
/dev/hda the hard disk on the primary interface of the primary IDE, which is the first hard disk of the system
/DEV/HDA1 first primary partition of the first hard disk
/dev/hda2 the second primary partition of the first hard disk
/dev/hda3 the third primary partition of the first hard disk
/DEV/HDA4 the fourth partition of the first hard disk, which is the extended partition
/DEV/HDA5 first logical partition of first hard disk
/dev/hda6 the second logical partition of the first hard disk
······
/DEV/HDB hardware on the slave interface of the primary IDE, which is the second hard disk of the system
/DEV/HDB1 the first primary partition of the second hard disk
······
For SATA,SCSI,USB hard disk, USB flash drive, etc., as long as the HD into SD can be. The naming rules are the same.

Comparison and summary:
1, the old name method only HD, it is estimated that there is only IDE hard disk for the sake of it. In fact, now the IDE hard disk is rarely used, check my machine is SATA hard disk, with SD.
2, the old name does not consider the logical partition, so each hard disk needs to occupy 5 digital signs (such as the first hard drive at the end of 0~4). In the modern name, the hard drive code is changed to ABCD, and the subsequent partitions are digitally marked. And one of the details is that the partition number starts at 1, not 0 (I guess this is designed to be compatible with old-fashioned naming.) Because the old name in the number 0 represents the entire hard disk, the partition number is also starting from 1. So even if the modern name HDD name directly hda is not hda0, then the first partition is still hda1).
3, each hard disk can only have four primary partitions and extended partitions (three primary partitions + an extended partition, or four primary partitions), this is determined by the hard disk itself, and the operating system does not matter.
Each hard disk can have at most one extended partition, which is limited by the operating system. I understand that the extended partition is just a sign that the partition is again partitioned into multiple logical partitions, so the extended partition is equivalent to a logical partition container, and there is no need for multiple, so the OS limits the extended partition to only one at most.

Device name and device number in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.