Make Fdisk output more accurate and reasonable

Source: Internet
Author: User
Tags deprecated

Note: The new version of Fdisk default output has been correctly justified, this article only applies to older versions of Fdisk.

1 output without the option parameter
[Email protected] ~]# fdisk-ldisk/dev/sda:160.0 GB, 160041885696 bytes255 heads, $ sectors/track, 19457 Cylindersunit s = Cylinders of 16065 * 8225280 = bytessector size (logical/physical): bytes/512 bytesi/o Size (minimum/optimal ): bytes/512 bytesdisk identifier:0xf0b1ebb0   Device Boot      Start         End      Blocks   Id  System/dev /SDA1   *           1        7295    58592256  linux/dev/sda2            7295 19458    97695745    5  extended/dev/sda5            7295       17021    78124032  linux/dev/sda6 17021       18966    15624192  linux/dev/sda7           18967       19458 3945472,  Linux swap/solaris[[ Email protected] ~]#

At this time, the output is based on CHS hard drive addressing mode in ancient times, CHS has long been eliminated by the industry, the concept is purely historical, only possible in some BIOS still exist. But there is still a lot of information or software, such as the results of fdisk-l. In order to take into account the knowledge integrity, or simply do a brief introduction, interested students can go to the Internet to find the keyword CHS. The earliest hard disk has multiple platters, each with a head (head) to scan it, a platter divided into concentric rings, each of which is called a track, and each track is divided evenly into multiple arcs called sectors (Sector). It is important to note that the concentric rings here, regardless of radius, are divided into the same number of sectors, and the large size of each sector is fixed at 512B. Therefore, the data density of the inner ring must be higher than the data density of the outer ring. The corresponding tracks (track) on all platters together form a cylinder (Cylinder). As far as I'm concerned, I've never seen a hard disk with more than 2 platters, so the cylinder is actually very short.

The CHS positioning principle is also very simple, first find the cylinder (C), then find the disk surface (H) on this cylinder, and finally find the sector (S) on the cylinder and surface cutting track. In theory, you can find the disk surface and then find the track and sector. CHS is the order of the original hard drive construction, all the heads are fixed on the same device, the relative position is constant, so all the heads are moved together. Thus, if the adjacent data on the same cylinder, you can read and write without moving the head, so the most efficient. Don't talk about this, after all, CHS has long been eliminated. Back to the above output, the first line shows/DEV/SDA the total capacity of this hard disk is 160G, the second line shows that the disk has 255 heads (disk), each track has 63 sectors, concentric ring has 19,457. Does this hard drive really have 255 disk faces? Obviously, this is not possible. The reason for this output is that it is compatible with CHS mode. The 255 heads 63 sectors are the limits of CHS, which does not represent the physical structure of the actual hard disk. The third line of units represents how many bytes of data a cylinder can store, that is, 255*63*512, which is clearly meaningless for today's hard drives. However, the start and end columns in the partition list of the output result use unit as the unit of measure, which means that the alignment unit of the partition is a cylinder, which is not very precise. The unit of the blocks column is KB, regardless of units.

2 The option parameter that is strongly recommended

If we run Fdisk without parameters, output the following result.

[Email protected] ~]# fdisk/dev/sdawarning:dos-compatible mode is deprecated. It's strongly recommended to         switch off the mode (command ' C ') and change display units to         sectors (Command ' u '). C Ommand (M for help):

Here is a warning message: The DOS compatibility mode is deprecated, it is strongly recommended to perform the C command switching mode, and the U command is used to change the output unit from cylinder to sector. Follow the prompts to do the following:

 Command (M for help): CDOS compatibility flag isn't SetCommand (M for help): Uchanging Display/entry units to sector Scommand (M for help): pdisk/dev/sda:160.0 GB, 160041885696 bytes255 heads, + sectors/track, 19457 cylinders, Total 312 581808 sectorsunits = sectors of 1 * = bytessector size (logical/physical): bytes/512 bytesi/o Size (minimum /optimal): bytes/512 bytesdisk identifier:0xf0b1ebb0 Device Boot Start End Blocks Id system/ DEV/SDA1 * 2048 117186559 58592256, linux/dev/sda2 117188606 312580095 97695745 5 Extend Ed/dev/sda5 117188608 273436671 78124032, Linux/dev/sda6 273438720 304687103 15624192 Ux/dev/sda7 304689152 312580095 3945472, Linux Swap/solariscommand (M for help): 

It is visible that the unit of the partitioned list in the print results is no longer in cylinder, but as a sector. The sector is indeed the smallest storage unit for most current hard disks and logical hard disks (LUNs), and it also uses the linear addressing method of LBA. Since Fdisk can give a warning, why not change the default to the right way? The comparison found that the new version of Fdisk does show up correctly by default, and when you encounter an older version of Fdisk, you still need to add a CU parameter.

With non-interactive fdisk-l, the partition information can be displayed correctly using the Fdisk-cul.

[Email protected] ~]# fdisk-culdisk/dev/sda:160.0 GB, 160041885696 bytes255 heads, sectors/track, 19457 cylinders,  Total 312581808 sectorsunits = sectors of 1 * all = Bytessector size (logical/physical): bytes/512 bytesi/o Size (minimum/optimal): bytes/512 bytesdisk identifier:0xf0b1ebb0   Device Boot      Start         End      Blocks   Id  system/dev/sda1   *        2048   117186559    58592256  linux/dev/sda2       117188606   312580095    97695745    5  extended/dev/sda5       117188608   273436671    78124032  linux/dev/sda6       273438720   304687103    15624192  linux/dev/sda7       304689152   312580095     3945472   -  swap/solaris Linux

By the way, note that the above MBR and the first primary partition, and the partitions are not closely connected, but there are some "unused" sectors. One of the reasons I can think of is that part of the code for grub is in the middle of the gap between partitions.

Make Fdisk output more accurate and reasonable

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.