How the data is laid out on disk

Source: Internet
Author: User
Tags file size file system linux

Developers of storage and computer architecture need to understand the distribution of data on disk, so that system recovery can be done manually when the system fails. At present, the capacity of the disk is more and more large, the failure rate is higher, when the failure occurs after the disk data recovery, disk data recovery not only to understand the partition and other basic disk data layout, and need to know the file system on the disk data distribution. Here we first discuss the distribution of basic data on disk for systems such as partitioning.

Partition

DOS Partition

Dos Partitioning is a commonly used partitioning method, and its disk data distribution is described as follows:

The first sector is the primary boot partition MBR,MBR describes the structure of the disk partition, and the contents of the MBR include boot code and partition table information, and finally end with the flag 0xaa55.

The boot code in the MBR is code that runs first after the BIOS starts, and typically the boot code checks the disk partition table and determines which partition is the boot partition, finds the boot partition, and then boots the operating system from the boot partition.

The DOS partition provides four primary partitions, each of which can describe the maximum 2TB of disk space. When the disk capacity increases, the extended partition is needed to satisfy the application requirement, and the extended partition is to build the partition information table in the space described by the primary partition. In four primary partitions, there can be only one active partition, which is the boot partition.

GPT Partitioning

Due to the giant magnetoresistance effect of the discovery of disk capacity is increasing, the DOS partition has a 2TB upper limit to meet the growing demand for large partitions, so Microsoft has introduced GPT (GUID Partition table), the partition table's disk structure as shown in the following figure.

The first part is the retention of the MBR, occupies a sector; the second part is the EFI information, which occupies a sector, which describes the location information of the distribution area; The third part is the partitioned table, which occupies 32 sectors, each of which occupies 128 bytes, and therefore, can accommodate up to 128 partitioned table entries. Part IV is the partition area; To improve reliability, part fifth is divided into partitioned table backup areas, which occupy the last 32 sectors of the entire disk.

Where's bootload?

After knowing the partition information of the disk, we usually focus on the bootloader of the operating system. In Linux, for example, bootloader is usually grub, and embedded systems typically use Uboot, where grub, for example, is more powerful. Grub is installed on the boot partition when the operating system is installed. The/boot directory in Linux contains the grub file and the operating system image file.

Grub is supporting the file system, in the/boot/grub directory there are e2fs_stage1_5, xfs_stage1_5 and other files, these files collectively known as stage1.5, in fact, the various file systems are driven. Here's a brief description of grub's makeup. Grub's boot files are divided into Stage1 and Stage2, Stage1 are copied from grub to the MBR at the time of the grub installation, and because the MBR is 512 bytes in size, the Stage1 file size is 512 bytes. The role of Stage1 is to boot the stage2, because Stage2 is stored on the boot, it has file system format, and Stage1 program can not be very large, therefore, the boot partition file system is not recognized, The location of Stage2 and stage1.5 files can be stored in stage1 only in the form of a program table.

For grub, the boot program in the MBR needs to be modified because of the need to obtain the Stage2 file, so grub is installed in the boot partition and MBR when the operating system is installed.

How does the system start?

Familiar with the disk data distribution to the system startup process to understand some help, here briefly describe the system startup process.

1, the system after the power, directly to the BIOS program into the memory to run, the BIOS program will scan the hardware, and implement some basic hardware drivers (such as PCI scan) and self-test operations. The BIOS program scans the boot hard drive in the system, and once a bootable hard drive is found, the BIOS mounts the boot loader in the MBR on the boot hard drive into memory and hands the CPU to the boot program.

2, the bootstrapper in the MBR makes a partitioned table check, which is actually the Grub Stage1 program, because it was updated by the grub installation. When everything is complete, the bootstrapper loads the Grub Stage2 program in the boot partition into memory via a fixed address and hands the CPU to the STAGE2 program.

3, the STAGE2 program is the body of grub, which can identify the file system. The boot partition has a file system, which is formatted by the user when the operating system is installed, and grub will mount the boot partition so that it is easy to locate the mirrored files of the Linux operating system, and some systems require special drivers during the grub operation, for example, The system root file system is built on top of a special soft raid, so a special soft raid driver needs to be loaded before starting the Linux operating system. For this purpose, you can preload the driver for the Linux operating system in a ramdisk manner, RAMDisk files can be specified in the GRUB configuration file. Grub completes some preload operations, loads the Linux kernel into memory, and then releases the CPU resources to the Linux kernel.

4, when the Linux kernel starts to run, because grub has preloaded some drivers, Linux can also see some special devices, and Linux will do the root switch to mount the real root file system. If the BIOS has already allocated resources for devices such as PCI, then Linux can be used directly, of course, the PCI bus can be rescan, and the driver will be loaded. Since the root file system is already loaded, Linux can start a variety of services based on/etc/inittab, so that the Linux system is basically started.

This article outlines the partitioning and bootloader data distribution on disk, which is fundamental to the storage system.

This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/database/storage/

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.