Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

6.2 Naming rules for physical devices


May 23, 2021 That's what Linux should learn



Everything is a file in a Linux system, and hardware devices are no exception. S ince it is a file, you must have a file name. T he udev device manager in the system kernel automatically standardizes the hardware name so that the user can guess the approximate properties of the device and partition information by the name of the device file, which is especially convenient for unfamiliar devices. I n addition, the udev Device Manager service runs as a daemon and listens for signals from the kernel to manage device files in the /dev directory. The file names of common hardware devices in Linux systems are shown in Table 6-2.

Table 6-2 Common hardware devices and their file names

Hardware Device File Name IDE Device /dev/hd(a-d) SCSI/SATA/U disk /dev/sd(a-p) floppy drive /dev/fd(0-1) Printer /dev/lp -15) optical drive /dev/cdrom mouse /dev/mouse drive /dev/st0 or /dev/ht0 Since IDE devices are now rare, the average hard drive device will start with "/dev/sd". There can be multiple hard drives on a host, so the system uses a to p to represent 16 different hard drives (allocated by default from a), and the partition number of the hard drive is also very detailed:

The number of the primary or extended partition starts at 1 and ends at 4;

The logical partition starts with number 5.

Many Linux training instructors in China, as well as many well-known Linux books when it talks about device and partition names, always misstable two knowledge points. T he first knowledge point is that the device name is misunderstood. M any trainers and Linux technology books mention, for example/ dev/sda represents a storage device on the first slot on the motherboard, and learners or readers will find that this is true in practice, so they are more convinced of this theoretical knowledge. B ut the truth is not so, /dev directory sda device is a, not by the slot, but by the system kernel identification order, and it happens that many board slot order is the system kernel identification order, so it will be named /dev/sda. Later, when using iSCSI network storage devices, you will find that the second slot on the clear motherboard is empty, but the system can recognize /dev/sdb this device is this reason.

The second knowledge point is that the partition name is misunderstood. M any Linux trainers will tell participants that the number of partitions represents the number of partitions. F or example, sda3 indicates that this is the third partition on the device, and the students do get this result when they do the experiment, but this theoretical knowledge is wrong, because the numeric encoding of the partition is not necessarily forced down, it may also be manually specified. Therefore, sda3 can only represent partitions numbered 3, not that 3 partitions already exist on the sda device.

After filling in the two "pits", Mr. Liu will analyze what information is contained in the name of the device file/dev/sda5, as shown in Figure 6-2.

6.2 Naming rules for physical devices

Figure 6-2 device file name

First, the hardware device file should be saved in the /dev/directory; I n short, "/dev/sda5" means "this is the first logical partitioned device file in the system that is identified as partition number 5 in the hardware device". Given that many of our readers don't have a Linux foundation at all, it's not easy to understand the concepts of master partitioning, extended partitioning, and logical partitioning, so let's take a brief look at hard disk-related knowledge.

It is because the computer has a hard disk device that we can archive it at any time during or after the game has been cleared, without having to start over each time. A hard disk device is made up of a large number of sectors, each with a capacity of 512 bytes. O ne of the first sectors is the most important, which holds the main boot record and partition table information. I n terms of the first sector, the master boot record takes up 446 bytes, the partition table is 64 bytes, and the end character takes up 2 bytes; The data information in the first sector is shown in Figure 6-3.

6.2 Naming rules for physical devices

Data information in the first sector, Figure 6-3

Now, here's the question - can only create up to 4 partitions for the first sector? I n order to solve the problem of insufficient number of partitions, you can point to another partition by taking out 16 bytes of space in the partition table of the first sector (which was supposed to be written to the main partition information) (called an extended partition). T hat is, an extended partition is not really a partition, but more like a pointer that takes up 16 bytes of partition table space -- a pointer to another partition. A s a result, users typically choose to use three primary partitions plus one extended partition, and then create several logical partitions in the extended partition to meet the needs of multiple partitions (greater than four). O f course, for now, it's enough to understand why the main partition can't exceed four. Primary partitions, extended partitions, and logical partitions can be planned like Figure 6-4.

The so-called extended partition, strictly speaking, it is not a partition of practical significance, it is just a pointer to the next partition, this pointer structure will form a one-way list.

6.2 Naming rules for physical devices

Figure 6-4 Planning for a hard disk partition

Readers try to interpret what /dev/hdc8 stands for. (Answer mode) https://www.linuxprobe.com/chapter-06.html answer: This is a logical partition numbered 8 in the third IDE device (less common).