Linux kexec kernel Boot

Source: Internet
Author: User

Linux Kexec Introduction

The function of Kexec is to run a new kernel with a running kernel, just like running an application. This mechanism enables a fast restart of the system because it skips the bootloader. In addition Kdump is based on the KEXEC implementation (schematic below).

The implementation of Kexec has several difficulties:

    1. In the context of the current kernel, how do I replace the existing kernel with the new kernel?
    2. During normal reset startup, the device is reset (or initialized) to a known state. Skipping the reset phase, how to ensure that the device status is reliable when the new kernel kexec is started?

Examples of the use of kexec are divided into 2 parts: kexec kernel loading and kexec kernel execution.

    Kexec-l/bzimage--initrd=/initrd.img.gz--append= "ro nosmap loglevel=4 console=ttys0,9600n8 acpi_rsdp=0x7b7fe014"    KEXEC-E
Kexec Kernel Load
    1. Loading kernel image files, root file system, command line parameters and other segment into user-state memory;
    2. Segment SHA256 Check to ensure that the kernel data is not corrupted, if it is kdump, back up the relevant data to the backup area (such as i386, the initial 640K configuration data for the SMP kernel boot, need to backup, or PowerPC, fixed location of the exception vector information such as need to backup, etc.). This link is called purgatory, the process can be implemented in the user State control, but also in the Kernel State control implementation (such as enable--kexec-file-syscall option);
    3. Allocate the Kernel State page and copy the segment from the user-state memory to the kernel-state page, and if the Enable--kexec-file-syscall option, skip the first two steps and load the segment directly into the kernel page and purgatory.
    4. Assign the page and initialize the Image->control_code_page, create a page table for it, and for the next time overwrite the current kernel with the page table mappings for code addressing. Initializes the LEVEL4/3/2/1 4-tier page table and establishes a mapping relationship, as shown in.

Kexec kernel operation
    1. Call the device driver shutdown interface to turn off the device;
    2. Shut down interrupts, such as Io-apic, local IRQ, Lapic;
    3. Turn off non-No. 0 CPU cores;
    4. Clear the TLB (here the following code for the Assembly implementation, concrete implementation of arch-related, generally called relocate_new_kernel);
    5. Set up segment register, GDT, IDT, etc.;
    6. Create a new stack and press the entry address of the new kernel into the stack;
    7. Set CR0 Register: Enable paging function and page protection function;
    8. Set CR4 Register: Enable to extend the address;
    9. Set the CR3 register so that CR3 points to the new page table root, and after that, it bye bye with the old kernel;
    10. Copy the kernel segment page to the specified location, overwriting the current kernel;
    11. Call the RET instruction, the new kernel bzimage the entry address of the stack before it pops out, and enter the new kernel boot;
KEXEC Debugging Note implementation
    1. Kexec does not synchronize or unmount the file system, this process requires the user to ensure;
    2. From the above process can be seen, kexec does not reset the CPU or device, but the system restarts the process will call Reboot_notifier_list, so register_reboot_notifier registered interface do not have to perform CPU reset operations;
    3. To ensure that the device is in a stable state during kexec, Kexec invokes the device-driven shutdown interface to shut down, ensuring that the user's own device driver provides the correct shutdown interface, or that the user is otherwise closed;

--eof--

Linux kexec kernel Boot

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.