解析Linux MBR分区的深奥之处(linux分区mbr)

The Linux MBR partition is located in the beginning of a hard drive, occupying the first 446 bytes of the physical drive. It contains the master boot record, partition table, and boot loader code. Knowing how to parse the partition table can come in handy when trying to manage your system’s disks.

The master boot record (MBR) of the Linux partition contains a crucial piece of information — the partition table. This table is a list of four 16-byte entries that describe the location and size of four primary partitions on the disk. Each entry contains an 8-bit partition status field, a 3-byte partition type field, and a 4-byte LBA start field. The first partition in the table is always considered active and its status field will be set to ‘0x80’. The remaining three partitions have their status set to ‘0x00’.

The partition type field identifies the type of filesystem used on the partition. Common partition types include ‘0xaa’ for BSD, ‘0x81’ for Linux, ‘0xc1’ for Windows, and ‘0xf2’ for OS/2. The last field, the LBA start field, is a 4-byte, little-endian number that identifies the start of the partition in blocks of 512 bytes.

To parse the partition table and obtain the partition information, a Linux user should use a tool such as fdisk. fdisk will read the MBR and display the partition information. It also provides an interface for manipulating the entries in the partition table.

To list the partition information, run the command `fdisk -l`. The output should look similar to:

“`

Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: dos

Disk identifier: 0x000d8423

Device Boot Start End Sectors Size Id Type

/dev/sda1 * 2048 39065599 39063552 18.6G 83 Linux

/dev/sda2 39065600 90591994 51526395 24.5G 5 Extended

/dev/sda3 90591999 195352575 84760377 40.5G 8e Linux LVM

/dev/sda5 39065664 90591994 51526321 24.5G 8a Linux

This output shows the device, the partition type (e.g. Linux, Windows, etc), the start and end sectors, the size of the partition, and the partition id. 
Parsing the Linux MBR partition allows a user to manage their system's disks and identify partitions. A good tool to use is fdisk, which will read the MBR and display the partition information. With this information, a user can make an educated decision on how to manage the system disks.

数据运维技术 » 解析Linux MBR分区的深奥之处(linux分区mbr)