Mirror image-based operating system rapid restoring and upgrading method

Through the rapid restoration and upgrading method of the image-based operating system, virtualization technology is used to convert the Linux distribution into LiveCD image, solving the problems of complex version and low upgrade efficiency of Linux operating system in the online environment, realizing online upgrade and rapid restoration , reduces human operation errors and improves the efficiency and accuracy of system management.

CN119292624APending Publication Date: 2025-01-10SHANGHAI EMBEDWAY INFORMATION TECH
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411359366.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-27
Publication Date
2025-01-10

AI Technical Summary

Technical Problem

In an online environment, the version of the Linux operating system is complex and difficult to upgrade across versions. There are problems such as high human operation errors, inability to fall back on the system version, and file accumulation cannot be synchronized, resulting in low upgrade efficiency and difficulty in reproduction.

Method used

Using the image-based operating system rapid restoration and upgrading method, through image construction and operating system rapid upgrade method, virtualization technology is used to convert the official Linux distribution image into LiveCD image, so as to realize the system online upgrade without relying on external storage and Quick restore, reduce human operations, and improve upgrade efficiency and accuracy.

Benefits of technology

It realizes rapid upgrade and restore of the operating system without relying on the USB flash drive, reduces human operation errors, improves upgrade efficiency, simplifies the operation process, and ensures that the system can be restored to the initial state at any point in time, which facilitates problem investigation and file management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119292624A_ABST
    Figure CN119292624A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of communication, in particular to a method for quickly restoring and upgrading an operating system based on a mirror image, and in order to achieve the purpose, the method for quickly restoring and upgrading the operating system based on the mirror image is designed and comprises a mirror image construction method and a mirror image upgrading method. The mirror image construction method comprises a method for constructing a LiveCD mirror image based on a Red Hat Linux operating system. An operating system rapid restoration method; the invention discloses an operating system quick upgrading method. The method has the advantages that a virtualization construction strategy is adopted, the mirror image file is automatically converted into the LiveCD format, and the mirror image deployment efficiency and convenience are improved; the operating system can be quickly recovered to the previous state, so that the environment problems can be quickly synchronized and diagnosed, and the problems caused by mistaken deletion of files or file accumulation during operation can be effectively solved; the operating system can be rapidly upgraded or degraded, and errors possibly occurring in the manual operation upgrading process are remarkably reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of communication technology, and in particular to a method for quickly restoring and upgrading an operating system based on a mirror image. Background Art

[0002] Linux image refers to a medium that can be directly booted into a usable Linux operating system. It is usually burned into a USB flash drive or other storage device to install the Linux operating system on the target hard disk. However, in some scenarios, since the system booted by the Linux image itself runs in memory and has features such as fast recovery, it can be modified to allow the operating system to have the ability to quickly restore and upgrade.

[0003] The regular Linux file system (root directory) is stored on the hard disk, and changes to the file system are retained after a reboot. If you need to update to a new Linux operating system, you usually need to use a USB flash drive to reinstall the operating system to the target hard disk. However, in some business scenarios, when online boards need to update the system, using USB flash drives for large-scale installation will be very inefficient and unrealistic. Even if the upgrade transition can be completed through some scripts, the following problems will still exist: 1. The system versions of the online environment are complex, it is difficult to enumerate all possibilities, and it is inconvenient to upgrade across system versions; 2. It is almost impossible to roll back the system version; 3. It is difficult to form a standardized operating method, and the probability of human error is high; 4. System operation files are piled up, and it is impossible to synchronize the online and home environments, making it difficult to reproduce the problem; Based on the above problems, it is now urgent to design a technical solution for fast restoration and upgrade of the Linux operating system, which can be restored to an initialized system after restart, and can also upgrade the system online without relying on external storage (U disk, etc.). This technical solution needs to get rid of the errors caused by human operation as much as possible and form a standardized system upgrade operation method. It is further hoped that this technical solution can realize the rapid switching of multiple different types of Linux operating systems. Summary of the invention

[0004] The purpose of the present invention is to overcome the shortcomings of the prior art and provide a method for quickly restoring and upgrading an operating system based on an image, so that when a business is already running online or in other states where it is inconvenient to insert a USB flash drive, the system upgrade can be achieved by simply placing a new system image under the system, and at any time, the operating system can be restored to its initial state by restarting the board, which is convenient for troubleshooting and preventing accidental deletion of files.

[0005] In order to achieve the above purpose, a method for fast restoration and upgrade of operating system based on mirror image is designed, including: a mirror image construction method, wherein the mirror image construction method includes a method for building a LiveCD image based on Red Hat Linux operating system: S1. Entering the corresponding Docker container of the target operating system; S2. Compiling the kernel source code and generating a kernel compressed package; S3. Extracting the kernel header file from the kernel compilation product directory and generating a kernel header file compressed package; S4. Installing the kernel compressed package to the root file system directory; S5. Calling the livemedia-creator tool of Lorax, following the ks.cfg configuration file, in the Lorax container, based on the internal S6. In the post--nochroot stage of kickstart, all the contents in the root file system directory are copied and overwritten to the root file system; S7. In the post--chroot stage of kickstart, the post-root script is executed, during which the original kernel is uninstalled, the internally maintained kernel is installed, the systemd service is adjusted, and additional software packages are installed; S8. Use the livemedia-creator tool of lorax to call dracut to reconstruct initramfs, during which the necessary tool lsblk will be installed for initramfs; S9. Convert the official complete image of openEuler to LiveCD; S10. Compile GRUB; S11. Repackage efiboot.img; S12. Repackage the root file system to generate a file in squashfs format; S13. Package into the final image; Operating system fast restoration method: For the production stage, the target hard disk on the board is empty or in other states, the final LiveCD image constructed by the image construction method is burned into a U disk and started, and the boot script of the operating system booted by the LiveCD image is run to install OS tool, installOS tool divides the target hard disk into partitions, copies the LiveCD image burned in the U disk to the hard disk, and calls the updateGRUB tool to configure the hard disk's GRUB to be able to start from the LiveCD image on the hard disk. After completion, restart the board. After that, the environment can be booted without the U disk. At any time, restart the board to restore the operating system to its initial state; operating system fast upgrade method: for online services that are already running or in other states where it is inconvenient to insert a U disk, if you need to upgrade the system, you only need to put the new system image under the system, run the installOS tool and restart the board, and the new operating system will be booted.

[0006] Preferably, the present invention also includes other technical features, wherein the image building method also includes a method for building a LiveCD image based on a Debian-based Linux operating system: S1. Compile the kernel source code in the kernel directory to generate a kernel compressed package; S2. Extract the kernel header file from the kernel compilation product to generate a kernel header file; S3. Install the kernel compressed package to the root file system directory; S4. Mount the official image and mount it; S5. Decompress the casper / filesystem.squashfs in the image and perform root cutting. After root cutting, uninstall the original kernel, install the internally maintained kernel, adjust the systemd service, and install additional software packages; S6. Repackage the file system; S7. Rebuild initrd; S8. Repackage efi.img; S9. Package into the final image.

[0007] Preferably, the present invention also includes other technical features, wherein the method also includes a method for installing a LiveCD operating system for a hard disk: S1. Burning the final image after image construction to a U disk or mounting a KVM image on the BMC, selecting the U disk or KVM image to start in the BIOS, and automatically calling the installOS tool in the image file system when starting; S2. Deleting the logical volume, erasing the target hard disk, and clearing the partition table and volume label; S3. Using sgdisk, dividing the hard disk into three partitions, the first partition of the target hard disk is a hard disk partition of the EFI partition type, used to store boot files, and the second partition of the target hard disk, A hard disk partition in ext4 disk format is used to store image files. The third partition of the target hard disk is configured as a logical volume partition; S4. The loopback device mount point of the image is dd to the second partition of the target hard disk, and the image mapping is stored in the second partition; S5. The updateGRUB tool is called to set the \EFI\BOOT\grubx64.efi file of the first partition of the hard disk as the first startup item. The updateGRUB tool uses the grub language to capture the smbios information, and then identify the CPU model or platform, and finally match the appropriate baud rate or serial port peripherals; S6. Restart.

[0008] Preferably, the present invention also includes other technical features, wherein the operating system rapid upgrade method realizes system rapid upgrade by modifying the image file, and the specific process is as follows: S1. Place the system image to be upgraded in the second partition of the target hard disk; S2. Call the updateGRUB tool, the updateGRUB tool will automatically call the updateGRUB in the image to be upgraded, ensure that the updateGRUB configuration will be the latest, set the \EFI\BOOT\grubx64.efi file of the first partition of the hard disk as the first startup item, and modify the grub configuration of the first partition of the target hard disk; S3. Loopback the image, push the image to the memory, and set it as the subsequent root file system; S4. Expand the final root file system in the image through the iso-scan function and start with iso; S5. Restart.

[0009] Compared with the prior art, the present invention has the following advantages: 1. Adopt virtualization construction strategy to automatically convert image files into LiveCD format, which improves the efficiency and convenience of image deployment.

[0010] 2. By utilizing the technical solution of the present invention, the operating system can be quickly restored to a previous state, facilitating rapid synchronization and diagnosis of environmental problems, and effectively handling problems caused by accidental deletion of files or accumulation of files during runtime.

[0011] 3. The technical solution of the present invention can realize rapid upgrade or downgrade of the operating system, significantly reducing the errors that may occur during the manual operation upgrade process. BRIEF DESCRIPTION OF THE DRAWINGS

[0012] Figure 1 , is a schematic diagram of the method for installing a LiveCD operating system on a hard disk of the present invention, step S3. dividing the hard disk into three partitions by using sgdisk. DETAILED DESCRIPTION

[0013] In order to make the purpose, principle and structure of the present invention more clear, it is further described below in conjunction with the drawings and specific embodiments.

[0014] The present invention converts the official image of the Linux distribution into a LiveCD image through virtualization technology. The LiveCD image integrates all the files required for Linux startup, including but not limited to grub (multi-boot operating system boot program), kernel (Linux kernel), initrd (initial root file system), and rootfs (final root file system).

[0015] In the production phase, if the target hard disk is empty or in other states, you can write the LiveCD image to a USB flash drive and start the computer. After startup, use the boot script in the operating system booted by the LiveCD to execute the "installOS" tool. This tool is responsible for partitioning the target hard disk, copying the LiveCD image in the USB flash drive to the hard disk, and then calling the "updateGRUB" tool to configure the GRUB on the hard disk so that it can be started from the LiveCD image on the hard disk. After completing these steps, restart the board, and the system can now boot independently without the USB flash drive.

[0016] For systems that are already deployed and running or in an environment where it is not convenient to use a USB flash drive, if you need to upgrade, just place the new system image in the existing system, run the "installOS" tool, and then restart the board. The system will boot into the new operating system.

[0017] Restarting the board at any time will restore the operating system to its original state, which helps with troubleshooting and prevents accidental deletion of files.

[0018] <Example 1> Specifically, the present invention provides a method for quickly restoring and upgrading an operating system based on a mirror.

[0019] Step S1. Image building: For Red Hat Linux operating systems (CentOS, openEuler, etc.), you can use the "livemedia-creator" tool (belonging to the lorax project) to convert the official image into a livecd image. The specific process is as follows: 1. Enter the corresponding docker container of the target operating system; 2. Compile the kernel source code and generate a kernel compressed package (kernel-*.tar.gz); 3. Extract the kernel header files from the kernel compilation directory and generate a kernel header file compressed package (kernel-headers-*.tar.gz); 4. Install the kernel compressed package to the root file system directory; 5. Call the "livemedia-creator" tool of Lorax, follow the "ks.cfg" configuration file, and kickstart based on the internal FTP source in the Lorax container. During this process, all rpm packages under the "%packages" field in the "ks.cfg" file will be installed (obtained from the internal FTP source); 6. In the "post --nochroot" stage of kickstart, copy all the contents in the root file system directory to the root file system (including self-developed tools such as "installOS"); 7. In the "post --chroot" phase of kickstart, the post-chroot script is executed, which will uninstall the original kernel, install the internally maintained kernel, adjust the systemd service, install additional software packages, etc. 8. "Lorax's "livemedia-creator" tool calls dracut to reconstruct initramfs, during which it will install necessary tools such as lsblk for initramfs; 9.livemedia-creator converts the official complete image of openEuler into LiveCD; 10. Compile GRUB; 11. Repackage efiboot.img; 12. Repackage the root file system to generate files in squashfs format; 13.Package into the final image.

[0020] For Debian operating systems (Ubuntu, etc.), you can follow the tutorial on the Ubuntu official website to convert the official image to a livecd image. The specific steps are as follows: 1. Compile the kernel source code in the "kernel" directory to generate a kernel compressed package; 2. Extract the kernel header file from the kernel compilation product and generate the kernel header file; 3. Install the kernel compressed package to the root file system directory; 4. Mount the official image and install it; 5. Unzip casper / filesystem.squashfs in the image and perform root cutting. After root cutting, uninstall the original kernel, install the internally maintained kernel, adjust the systemd service, install additional software packages, etc. 6. Repack the file system; 7. Rebuild initrd; 8. Repackage efi.img; 9. Package the image.

[0021] Among them, dockfile is used to use docker for code management to ensure stable image output. The steps of dockfile for building a Docker image based on the openEuler operating system are as follows: 1. Specify the base image and use the latest image of the 22.03 LTS SP1 version of the openEuler operating system.

[0022] 2. Define a build parameter `DOCKER_IMAGE_VERSION` to specify the image version when building the image.

[0023] 3. Define a build parameter `DOCKER_IMAGE_COMMIT_SHA` to specify the commit SHA value of the image when building the image.

[0024] 4. Create a script file named `showVersion` and write the following content to the file: Output the image version information in the script, output the image submission SHA value information in the script, and end the command input.

[0025] 5. Modify the permissions of the `showVersion` script to make it executable.

[0026] 6. Rename the original yum repository configuration file to a backup file.

[0027] 7. Create a new yum repository configuration file: Define a new yum repository and set the repository name to openEuler. Set the base URL of the repository. Enable the repository. Disable GPG checking. Set the URL of the GPG key. End the command input.

[0028] 8. Upgrade all installed packages using dnf package manager.

[0029] 9. Install a set of software packages, including server software, development tools, system tools, and anaconda tools. Install a series of development and system tool software packages.

[0030] 10. Delete a file called `system-info.sh`.

[0031] 11. Modify the bashrc file and comment out the setting of the `TMOUT` environment variable. Modify the `creator.py` file of `pylorax` and set the kernel architecture to `x86_64`. Modify the `x86.tmpl` template file. Modify the `x86.tmpl` template file.

[0032] Step S2. Install the LiveCD operating system to the hard disk: First, burn the image in the previous section to a USB flash drive (or mount the KVM image on the BMC), select the USB flash drive (or KVM image) to start in the BIOS, and the "installOS" tool in the image file system will be automatically called when starting. The "installOS" tool will perform the following process: 1. Delete the logical volume, erase the target hard disk, and clear the partition table and volume label; 2. Use sgdisk to partition the target hard disk. The hard disk is mainly divided into three partitions, such as Figure 1 As shown, the target hard disk partition 1 is an EFI partition type hard disk partition, which mainly stores boot files, such as grub firmware and configuration. The target hard disk partition 2 is an ext4 disk format hard disk partition, which is mainly used to store image files. The target hard disk partition 3 is configured as a logical volume partition (business storage requirements).

[0033] 3. dd the loopback device mount point ( / dev / loop0) of the image to partition 2 of the target hard disk and store the image mapping under partition 2; 4. Call the "updateGRUB" tool and set the "\EFI\BOOT\grubx64.efi" file in partition 1 of the hard disk as the first boot item; 5. Restart At this point, the LiveCD image operating system on the hard disk has been installed. After restarting, you can start from the image on the hard disk. After the startup is complete, any operations done on the system (except those involving the hard disk) will not be retained after restarting, and you can quickly restore it to a new pure system Step S3. Quickly upgrade the operating system: Since almost all image-based operating systems come from an image file (kernel, initrd, rootfs), the system can be quickly upgraded by modifying the image file. The specific process is as follows: 1. Place the system image to be upgraded in the target hard disk partition 2.

[0034] 2. Call the "updateGRUB" tool. The "updateGRUB" tool will automatically call the "updateGRUB" in the image to be upgraded (new image), ensure that the "updateGRUB" configuration will be the latest (consistent with the new image), set the "\EFI\BOOT\grubx64.efi" file of partition 1 of the hard disk as the first startup item, and modify the grub configuration of partition 1 of the target hard disk. The key points of the grub configuration are: loopback the image, push the image to the memory, and set it as the subsequent root file system. Use the iso-scan function to expand the final root file system in the image (start with iso).

[0035] 3. Reboot.

[0036] The method for updating the GRUB (GRand Unified Bootloader) configuration is as follows: 1. Use the associative array `DISK` to define the disk paths for different hardware platforms.

[0037] 2. Check if the environment variable `TARGET_DISK` is set. If not, check if disks such as ` / dev / sda`, ` / dev / nvme0n1` exist, and set `TARGET_DISK` according to the existing disks. If no suitable disk is found, output an error message and exit.

[0038] 3. Check the target disk. If `TARGET_DISK` is not set, output an error message and exit.

[0039] 4. Set up EFI and BOOT partitions and determine the paths of EFI and BOOT partitions according to `TARGET_DISK`.

[0040] 5. Get the partition UUID. Use the blkid command to get the UUID of the EFI and BOOT partitions.

[0041] 6. Mount the partitions. If ` / mntmp / rootfs / usr / bin / updateGRUB` does not exist, mount the EFI and BOOT partitions to the ` / mntmp` directory.

[0042] 7. Set the default ISO, read the default ISO file path, and check if it exists.

[0043] 8. Mount ISO and rootfs, mount the default ISO to ` / mntmp / ISO`, and mount rootfs.

[0044] 9. Update GRUB and execute the `updateGRUB` script.

[0045] 10. Clean up the mount and unmount all mounted partitions.

[0046] 11. Clean up the EFI directory and delete all files under the / mntmp / efi directory.

[0047] 12. Synchronize EFI files and use the `rsync` command to synchronize the EFI and images directories in the ISO to ` / mntmp / efi`.

[0048] 13. Configure the EFI boot entry. Use the `efibootmgr` command to delete all existing EFI boot entries and create a new one.

[0049] 14. Configure the GRUB configuration file according to the hardware platform and mode (DISK, RAM).

[0050] 15. Add advanced options in GRUB configuration file, including boot options for different ISOs and rescue mode.

[0051] 16. Output information of all available ISOs.

[0052] 17. Add firmware settings options in the GRUB configuration file.

[0053] At this point, the operating system has completed a rapid upgrade. Based on this method, if there is a problem, you can quickly roll back to the original operating system. Moreover, as long as you follow a set of file system framework structures, you can quickly switch between different operating systems.

[0054] The above description is only a specific implementation mode of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can make equivalent substitutions or changes according to the technical solutions and novel concepts of the present invention within the technical scope disclosed by the present invention, which should be covered by the protection scope of the present invention.

Claims

1. A method for rapid restoration and upgrade of an operating system based on an image, characterized in that ,include: An image building method, the image building method comprising a method for building a LiveCD image based on a Red Hat Linux operating system: S1. Enter the corresponding docker container of the target operating system; S2. Compile the kernel source code and generate a kernel compressed package; S3. extract kernel header files from the kernel compilation generated directory and generate a kernel header file compressed package; S4. Install the kernel compressed package to the root file system directory; S5. Call the livemedia-creator tool of Lorax, follow the ks.cfg configuration file, and kickstart based on the internal FTP source in the Lorax container. During this process, all rpm packages under the %packages field in the "ks.cfg" file will be installed; S6. In the post-nochroot stage of kickstart, all contents in the root file system directory are copied and overwritten to the root file system; S7. In the post-chroot phase of kickstart, the post-chroot script is executed, during which the original kernel is uninstalled, the internally maintained kernel is installed, the systemd service is adjusted, and additional software packages are installed; S8. Use lorax's livemedia-creator tool to call dracut to reconstruct initramfs. During this process, the necessary tool lsblk will be installed for initramfs. S9. Convert the official complete image of openEuler to LiveCD; S10. Compile GRUB; S11. Repackage efiboot.img; S12. Repack the root file system to generate a file in squashfs format; S13. Package into the final image; Method for fast restoration of operating system: in the production stage, the target hard disk on the board is empty or in other states, the final LiveCD image constructed by the image construction method is burned into a U disk and started, and the boot script of the operating system booted by the LiveCD image runs the installOS tool, the installOS tool partitions the target hard disk, and copies the LiveCD image burned in the U disk to the hard disk, and calls the updateGRUB tool to configure the GRUB of the hard disk to be able to start from the LiveCD image on the hard disk, and restart the board after completion, after which the environment can be booted without the U disk, and the operating system can be restored to its initial state by restarting the board at any time; Method for quick operating system upgrade: If you need to upgrade the system when the business is already running online or when it is inconvenient to insert a USB flash drive, you only need to put the new system image under the system, run the installOS tool and restart the board to boot the new operating system.

2. A method for rapid restoration and upgrade of an operating system based on mirroring as claimed in claim 1, characterized in that The image building method also includes a method for building a LiveCD image based on a Debian-based Linux operating system: S1. Compile the kernel source code in the kernel directory and generate a kernel compressed package; S2. extract kernel header files from kernel compilation products and generate kernel header files; S3. Install the kernel compressed package to the root file system directory; S4. Mount the official image and install it; S5. Unzip casper / filesystem.squashfs in the image and perform root cutting. After root cutting, uninstall the original kernel, install the internally maintained kernel, adjust the systemd service, and install additional software packages. S6. Repack the file system; S7. Rebuild initrd; S8. Repack efi.img; S9. Package into the final image.

3. A method for rapid restoration and upgrade of an operating system based on mirroring as claimed in claim 1 or 2, characterized in that The method also includes a method for installing a LiveCD operating system on the hard disk: S1. Burn the final image after image construction to a USB flash drive or mount the KVM image on the BMC. Select the USB flash drive or KVM image to start in the BIOS. The installOS tool in the image file system will be automatically called when starting. S2. Delete the logical volume, erase the target hard disk, and clear the partition table and volume label; S3. Use sgdisk to divide the hard disk into three partitions. The first partition of the target hard disk is an EFI partition type hard disk partition used to store boot files. The second partition of the target hard disk is an ext4 disk format hard disk partition used to store image files. The third partition of the target hard disk is configured as a logical volume partition. S4. mount the loopback device mount point of the image to the second partition of the target hard disk, and store the image mapping in the second partition; S5. Call the updateGRUB tool and set the \EFI\BOOT\grubx64.efi file of the first partition of the hard disk as the first boot item. The updateGRUB tool uses the grub language to capture the smbios information, and then identify the CPU model or platform, and finally match the appropriate baud rate or serial port peripherals; S6. Restart.

4. A method for rapid restoration and upgrade of an operating system based on mirroring as claimed in claim 3, characterized in that The method for rapidly upgrading the operating system realizes rapid system upgrade by modifying the image file. The specific process is as follows: S1. Place the system image to be upgraded in the second partition of the target hard disk; S2. Call the updateGRUB tool. The updateGRUB tool will automatically call the updateGRUB in the image to be upgraded to ensure that the updateGRUB configuration is the latest. Set the \EFI\BOOT\grubx64.efi file in the first partition of the hard disk as the first boot item, and modify the grub configuration of the first partition of the target hard disk. S3. Loopback the image, push the image to the memory, and set it as the subsequent root file system; S4. Expand the final root file system in the image through the iso-scan function and boot with iso; S5. Restart.

Citation Information

Cited By

  • Robot firmware and Docker mirror image integrated burning method and system

    CN122152332A