PS: The final Exam is finally over, and I finally have time to start running my blog. Some of the lessons in this semester are really very useful, I feel a lot of courses can be written in a very fine technical blog, such as pipeline technology, database of some technology, the examination in the University of the content of "perfunctory" really valuable content to avoid the test, but chasing a lot of the concept is very chicken. No matter how, this summer to myself left a lot of official technical books slowly to see, I will also continue to add some of their own experience and experiences in the blog.
I. About the name of the device in Linux
Attached: (Comparison of names of common devices and devices in Linux in Linux)
-------------------------------------------------------------
| IDE Interface HDD | /DEV/HD[A~D] |
| SCSI/SATA/USB HDD | /DEV/SD[A~P] |
| USB flash Drive | /DEV/SD[A~P] |
| Floppy Drive | /DEV/FP[0~1] |
| Printers | /DEV/LP[0~2] |
| Mouse | /DEV/USB/MOUSE[0~15] |
| | or/dev/psaux |
| Current CD ROM | /dev/cdrom |
| Current Mouse | /dev/mouse |
--------------------------------------------------------------
Although the use of Linux fedora distribution for more than a year, but in fact, there are many details of the knowledge is not careful to think about, such as hardware devices in the Linux/dev directory under some naming rules.
First look at the hard drives that we touch the most:
now the mainstream hard disk according to the interface can be categorized into two kinds: IDE interface and SATA interface , where the IDE interface type of hard disk is almost now obsolete, SATA interface is a relatively simple feature is composed of two interface slots are the signal interface and power interface, each SATA interface can only connect a hard disk, the number of SATA interface on the motherboard is not fixed, with the manufacturer's settings and change. Another kind of hard disk transmission interface is SCSI interface, more common in the workstation above the level of the computer, the SCSI interface hard disk on the controller contains a processor, running fast and does not consume CPU resources .
For IDE interface hard disks:
an IDE flat cable can connect two IDE devices, the two cable interfaces are called IDE1 (primary) and IDE2 (secondary), and the two devices above each flat cable are called Master devices and Slave device , so there is a table with the following name:
---------------------------------------------------
| Ide1--master | /dev/hda |
| Ide1--slave | /dev/hdb |
| Ide2--master | /DEV/HDC |
| Ide2--slave | /DEV/HDD |
---------------------------------------------------
For SATA interface drives:
Because the number of SATA interfaces on the motherboard is inconsistent, the SATA device naming in Linux is often a "first served" relationship, assuming that a motherboard has 10 SATA interfaces and that there is one device on the SATA0 and 3rd interface slots and a USB device The name is Sata0-->/dev/sda,sata3-->/dev/sdb,u disk-->/DEV/SDC, where the USB stick is behind because the BIOS program is often the last to identify the device on the USB cable, And most of the USB stick is inserted after the boot is completed, so often the name is the most.
The name of the hard disk so far is in order to partition it under the premise that the so-called "a pie" has not been cut, after the intervention of the partition after the device naming, first understand the hard disk partition and the system boot process of some knowledge.
Two. Disk partitioning and System startup brief
The hard disk referred to here refers to the traditional disk composed of platters, mechanical arm, spindle motor, the size of the hard disk on my laptop is like this 5400 rpm, the specific knowledge of the composition of the disk is not mentioned here, for the hard disk in terms of the first sector of the track is very important, It records two very important information about the disk:
(1) The main boot partition (master boot Record) where the boot loader is installed. Occupy 446B
(2) the partition table (Partition table) records the hard disk partition status. Occupy 64B
First look at the partition table:
The so-called partitioning of disks has three more important concepts:
(1) Primary partition (Primary)
(2) Extended partition (Extended)
(3) logical partition (Logical)
The most intuitive partition is the primary partition, the primary partition is directly in the 64B partition table records 4 groups of partitions, due to the 64B limit, the hard disk default partition table can hold up to 4 sets of partition information, The most straightforward assumption is that when we partition a hard disk directly into 4 primary partitions, the naming table is as follows (assuming that the hard disk used is the SATA interface type):
-------------------------------------------------
| Primary partition 1 | /dev/sda1 |
| Primary Partition 2 | /dev/sda2 |
| Primary Partition 3 | /dev/sda3 |
| Primary Partition 4 | /DEV/SDA4 |
-------------------------------------------------
where the smallest unit of the partition is a cylinder (cylinder)
However, in practice, the hard disk we use will be partitioned to more than 4 or even more than 10 partitions, how is this implemented? In fact, the function of the extended partition is used, and the extended partition is more like a generalized table, which records the next level of partitioning, which is the logical partition. As shown in the following:
So the naming table in Linux is as follows:
---------------------------------------------------------------------------------
| Primary partition 1 | /dev/sda1 |
| Extended Partition--------D | /dev/sda5 |
| --------E | /dev/sda6 |
| --------F | /dev/sda7 |
---------------------------------------------------------------------------------
It is important to note that the number of logical partitions is named starting from 5, because the name of the 1~4 can only be reserved for use by the primary partition/extended partition, but there are a few things to note in addition to the above concepts:
1. For a hard disk can only have 0~1 extension partition, can have a primary partition, that is, the primary partition |+| extended partition |<=4
2. Partitions that can be accessed as data are only primary and logical partitions, and the extended partition cannot be formatted!
3.linux IDE Hard disk has up to 59 logical partitions, SATA hard drives have up to 11 logical partitions
4. The so-called partitioning process only modifies the 64B content in the partitioned table.
Next, take a look at the main process of computer startup by using the MBR (Master boot Record) in the first sector:
1. System add self-test, through the CMOS and BIOS active boot. CMOS main storage for start-up of some parameters, the BIOS function here is not to repeat it.
2. Through the MBR execution bootloader program, Bootloader provides different boot options, load the kernel file or transfer the boot load function to other loader responsible.
(The following is a casual nagging, if you already know the recommended skip)
Since the loader of the transfer, we have to mention the implementation of multiple operating systems, today's most mainstream multi-system boot program is Grub,grub is written into the MBR, the normal operating system startup such as Windows startup, When the boot program in the MBR executes, the control of the computer is given directly to the Windows kernel, but what grub does here is to implement a "menu", and different options will lead to different operating system boot programs, which unload different partitions, Each partition will have a boot sector that is functionally consistent with the MBR. The boot program only knows the kernel files in its own partition, which is to achieve the isolation between the operating system, but because it is in the same hard disk in different partitions completed, so the partition is not transparent to the user, For example, you can obviously see the partition of the Windows kernel file on Linux (well, it can't be opened!) )
Three. linux file system and disk partitioning
(For a friend who doesn't have a basic understanding of the Linux filesystem architecture, see my previous post:http://www.cnblogs.com/guguli/p/4556445.html )
First of all, the old adage that all the devices under Linux are managed in file form, thanks to the separation of the Linux virtual file system VFS from the functional modules. However, the files in Linux are managed in a tree structure, and the structure of the downward branch is very much associated with the partitioning of the disk:
under VFS Management, the relationship between different partitions of the same disk or different disks is consistent, both nodes in the file system. Suppose our SATA hard disk is divided into two primary partitions sda1 and sda2, in the abstraction for Vfsmount complete like file system directory mount, assuming sda1 is mounted to the "/" root directory, Sda2 is mounted to the "/test" directory, so for example I Test/file1 Read and write operations will naturally be written to the second primary partition of the disk, the process of refinement is: first, from the directory of file1 files up, and then see whether the directory node is the file system mount point (see Super_block structure), here back to/ Test directory found this is a mount point, and then found that this is the second primary partition of the SDA hard disk, and then through the first sector of the SDA hard disk partition table to find the second primary partition of the cylinder range, and then read and write by address.
"Linux hardware and hard disk partitioning" about hard drive planning and usage details