A method for hot expansion of hard disk and file system based on cloud platform
By adding udev hard disk expansion rules and creating virtual machine images on the cloud platform, and using udev to listen to kernel messages and execute scripts, the hot expansion of hard disks and file systems is achieved, solving the problem of insufficient hard disk capacity affecting business systems, and providing efficient and safe services. expansion solution.
Patent Information
- Application Number
- CN202010882455.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-08-28
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2040-08-28
AI Technical Summary
When the hard disk capacity in existing cloud computing is insufficient, it needs to be expanded. However, existing methods usually require rebuilding or uninstalling the hard disk, which affects the normal operation of the business system and cannot achieve hot expansion.
By adding udev hard disk expansion rules and creating virtual machine images, udev is used to monitor the kernel's uevent messages and execute preset scripts to expand hard disk and file system partitions and file systems. It supports hot expansion of system disks and data disks without restarting the cloud server. .
It realizes hot expansion of hard disks and file systems, avoiding the impact on business systems. It supports a variety of back-end storage and hypervisor drivers to meet users' diverse expansion needs, provides automated expansion functions, and improves service reliability and flexibility.
Smart Images

Figure CN112035063B
Abstract
Description
Technical Field
[0001] The present invention relates to cloud computing technology, and in particular to a method for hot expansion of a hard disk and a file system based on a cloud platform. Background Art
[0002] With the development of the cloud service market in recent years, more and more government departments, enterprises and individuals have deployed their business systems in the cloud, and can use various resources such as computing, storage and network conveniently on demand through the network, thereby saving funds and human resources and improving work efficiency. However, when using cloud servers and cloud hard disk services, the hard disk capacity may be insufficient over time. At this time, the hard disk needs to be expanded.
[0003] The current method uses the method of rebuilding the cloud server or uninstalling the hard disk and then mounting it to expand the hard disk, and uses plug-ins such as cloud-init to expand the partition and file system when restarting the cloud server. However, the business system is still running in it, and it cannot be shut down or uninstalled at will. The current method affects the normal operation of the business system, and at this time, the support of hot expansion of hard disks and file systems is needed. Summary of the invention
[0004] In order to solve the above technical problems, the present invention provides a method for hot expansion of hard disks and file systems based on a cloud platform, which can realize hot expansion of hard disks without restarting, and simultaneously supports hot expansion operations on system disks and data disks.
[0005] The technical solution of the present invention is:
[0006] A method for hot expansion of a hard disk and a file system based on a cloud platform, comprising:
[0007] Add udev hard disk expansion rules and corresponding execution scripts, and create a virtual machine image to create a user virtual machine; the user sends an expansion request, dispatches to the physical node where the virtual machine is located, and executes the corresponding command expansion. Udev monitors the uevent message sent by the kernel, and executes the prepared script if the corresponding hard disk expansion rules are met. The script is executed to complete the expansion function of the corresponding disk partition and file system.
[0008] Furthermore,
[0009] Add udev hard disk expansion rules and create images. udev can detect changes in the hard disk and perform corresponding operations when the defined rules are met. After the hard disk is expanded, the corresponding scripts for partition and file system expansion are pre-set. Write the rules and scripts into the cloud server image for users to create cloud servers.
[0010] When a user makes a request to hot-expand the hard disk of an existing cloud server, the server program is dispatched to the computing host where the user's cloud server is located, and the blockresize command of libvirt is executed. This command calls the specific hypervisordriver to perform the hot-expand operation. For example, the block_resize command of the qemu monitor command is executed to expand the hard disk corresponding to the server.
[0011] At this time, the udev daemon running in the cloud server listens to the uevent sent by the kernel. When it listens to the uevent that matches the defined hard disk expansion rules, it calls the corresponding script.
[0012] Script execution. Execute the script to expand the hard disk partition and file system.
[0013] Furthermore,
[0014] The adding of udev hard disk expansion rules and the mirroring process, udev hard disk hot expansion rule matching key, setting the ACTION (uevent event behavior) in the rule to change means that this rule takes effect when the hard disk changes. The subsystem name SUBSYSTEM of the device is set to block. DEVPATH is set to the kernel device path of the corresponding hard disk. When the above matching key is completely matched with the uevent sent by the kernel, the subsequent assignment key will be executed.
[0015] The process of adding udev hard disk expansion rules and making images, assigning keys to udev hard disk hot expansion rules, and setting the rule udev key RUN to execute the preset script. The content of the preset script is to expand the partition and file system corresponding to the expanded hard disk. The growpart tool is used for partition expansion, and the resize2fs tool is used for file system expansion.
[0016] During the image creation process, you need to pre-set the udev hard disk hot expansion rules and scripts. And ensure that the added rules have been loaded into udev and take effect. During the image creation process, you need to ensure that the root partition is the last partition of the system disk to ensure that the root partition can be successfully expanded when the system disk is expanded.
[0017] Furthermore, the process of processing the hot expansion request of the hard disk for the existing cloud server is as follows:
[0018] (1) The user has created a cloud server using the image created above. The user has made a hot expansion request for this cloud server.
[0019] (2) The server verifies the user request and performs permission verification. After the verification is passed, subsequent operations are performed.
[0020] (3) The server responds to the request and sends it to the computing node where the cloud server is located through the message queue.
[0021] (4) The corresponding program on the computing node responds to the request and searches for the device name corresponding to the disk ID through the cloud server block device mapping. The libvirt API is called to pass in the cloud server ID, device name, and new disk size.
[0022] (5) Libvirt calls a specific driver to perform disk expansion operations. For example, it calls the block_resize command of the qemu monitor command to perform specific disk expansion operations.
[0023] Furthermore, the steps to expand the partition and file system are as follows:
[0024] (1) When the disk size changes, the kernel will issue a uevent event with action change.
[0025] (2) The udev daemon listens to the uevent message and matches the uevent with the existing rules. If all matching keys meet the requirements of the rule, the corresponding assignment key is executed. For example, action=="change", devpath==" / dev / vda", subsystem=="block" in uevent meets the requirements of action=="change", devpath=="*vda", subsystem=="block" defined in rules. The assignment key of the rule will be executed: RUN+="test.sh", that is, the test.sh script will be executed.
[0026] (3) If the uevent meets the hard disk hot expansion rules, the preset script is executed.
[0027] (4) Call growpart to expand the last partition of the corresponding disk. In detail, if the system disk is to be expanded, the script will search for the partition where the mount point " / " is located, that is, the root partition to be expanded. If the disk has been mounted to a file system, call resize2fs to expand the corresponding file system.
[0028] The beneficial effects of the present invention are
[0029] (1) The method and device for hot expansion of hard disk and file system under cloud platform introduced in the present invention can realize the expansion operation of hard disk, realize the requirement of providing simple, efficient, safe and reliable services with elastic processing capacity in cloud services, and enable users to focus more on their own business.
[0030] (2) The method and device for hot expansion of hard disk and file system introduced in the present invention can realize hot expansion of hard disk and file system without restarting operation, thereby not affecting the normal operation of user business system and the normal use of cloud server.
[0031] (3) The method and device for hot expansion of hard disk and file system introduced in the present invention support hot expansion operations of system disk and data disk at the same time, and can support a variety of back-end storage and hypervisor drivers, thereby meeting the diverse expansion needs of users.
[0032] (4) The method and device for hot expansion of a hard disk and a file system introduced in the present invention can realize automatic expansion of partitions and file systems without the need for users to manually trigger or restart operations, which is more convenient for users to use. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] Figure 1 It is a working block diagram of the present invention.
[0034] Figure 2 This is a flowchart for processing hard disk hot expansion requests;
[0035] Figure 3 Request flow chart for automatic hot expansion of partitions and file systems. DETAILED DESCRIPTION
[0036] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0037] A method for hot expansion of a hard disk and a file system in a cloud environment of the present invention includes the following process:
[0038] (1) Add udev hard disk expansion rules and create images. udev can detect changes in the hard disk and perform corresponding operations when the defined rules are met. After the hard disk is expanded, the corresponding scripts for partition and file system expansion are pre-set. The rules and scripts are written into the cloud server image and provided to users to create cloud servers.
[0039] (2) The user makes a request to hot-expand the hard disk of the existing cloud server. The server program is dispatched to the computing host where the user's cloud server is located, and the blockresize command of libvirt is executed. This command calls the specific hypervisordriver to perform the hot expansion operation. For example, the block_resize command of the qemu monitor command is executed to expand the hard disk corresponding to the server.
[0040] (3) At this time, the udev daemon running in the cloud service listens to the uevent issued by the kernel. When it listens to a uevent that matches the defined hard disk expansion rules, it calls the corresponding script.
[0041] (4) Script execution: Execute the script to expand the hard disk partition and file system.
[0042] udev hard disk hot expansion rule matching key, set the ACTION (behavior of uevent event) in the rule to change, which means that this rule takes effect when the hard disk changes. The subsystem name SUBSYSTEM of the device is set to block. DEVPATH is set to the kernel device path of the corresponding hard disk. When the above matching key is completely matched with the uevent sent by the kernel, the subsequent assignment key will be executed.
[0043] Assign a key to the udev hard disk hot expansion rule and set the rule udev key RUN to execute the preset script.
[0044] The content of the preset script is to expand the partition and file system corresponding to the expanded hard disk. The growpart tool is used to expand the partition, and the resize2fs tool is used to expand the file system.
[0045] Furthermore, during the image creation process, it is necessary to pre-set the prepared udev hard disk hot expansion rules and scripts, and ensure that the added rules have been loaded into udev and take effect.
[0046] Furthermore, during the image creation process, it is necessary to ensure that the root partition is the last partition of the system disk, so as to ensure that the root partition can be successfully expanded when the system disk is expanded.
[0047] like Figure 2 As shown in the figure, the process of processing a user's request to perform hot expansion of the hard disk capacity of an existing cloud server is as follows:
[0048] (1) The user has created a cloud server using the image created above. The user has made a hot expansion request for this cloud server.
[0049] (2) The server verifies the user request and performs permission verification. After the verification is passed, subsequent operations are performed.
[0050] (3) The server responds to the request and sends it to the computing node where the cloud server is located through the message queue.
[0051] (4) The corresponding program on the computing node responds to the request and searches for the device name corresponding to the disk ID through the cloud server block device mapping. The libvirt API is called to pass in the cloud server ID, device name, and new disk size.
[0052] (5) Libvirt calls a specific driver to perform disk expansion operations. For example, it calls the block_resize command of the qemumonitorcommand to perform specific disk expansion operations.
[0053] When a user calls a capacity expansion request, he can choose to use hot expansion or normal expansion. And only by using an image with udev rules and scripts preset can the subsequent automated file system expansion operation be completed.
[0054] The new disk size needs to be larger than the original disk capacity. The capacity change step is 1GB. The maximum disk capacity is set to 500GB.
[0055] After the above steps, the physical disk has been expanded. However, the cloud server partition and file system have not been expanded. Figure 3 As shown, the steps to complete the expansion of the partition and file system are as follows:
[0056] 1) When the disk size changes, the kernel will issue a uevent event with action change.
[0057] 2) The udev daemon listens to the uevent message and matches the uevent with the existing rules. If all matching keys meet the requirements of the rule, the corresponding assignment key is executed. For example, action=="change", devpath==" / dev / vda", subsystem=="block" in uevent meets the requirements of action=="change", devpath=="*vda", subsystem=="block" defined in rules. The assignment key of the rule will be executed: RUN+="test.sh", that is, the test.sh script will be executed.
[0058] 3) If the uevent meets the hard disk hot expansion rules, the preset script is executed.
[0059] 4) Call growpart to expand the last partition of the corresponding disk. In detail, if the system disk is to be expanded, the script will find the partition where the mount point " / " is located, that is, the root partition for expansion.
[0060] 5) If the disk has been mounted to the file system, call resize2fs to expand the corresponding file system.
[0061] The above description is only a preferred embodiment of the present invention, which is only used to illustrate the technical solution of the present invention, and is not used to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A method for hot expansion of hard disk and file system based on cloud platform, characterized in that: include: 1) Add udev hard disk expansion rules and corresponding execution scripts, and create a virtual machine image for creating user virtual machines; 2) The user sends a capacity expansion request, which is dispatched to the physical node where the virtual machine is located and executes the corresponding command to expand the capacity; 3) The udev daemon running in the cloud server monitors the uevent issued by the kernel; when it monitors the uevent that matches the defined hard disk expansion rules, it calls the corresponding script; 4) Script execution completes the corresponding disk partition and file system expansion functions; udev detects changes in the hard disk; when the defined rules are met, the corresponding operations are performed; after the hard disk is expanded, the corresponding scripts for partition and file system expansion are preset; the rules and scripts are written into the cloud server image for users to create cloud servers; The user requests to hot-expand the hard disk capacity of the existing cloud server. The server program is dispatched to the computing host where the user's cloud server is located and executes the blockresize command of libvirt. This command calls the specific hypervisor driver to perform the hot-expand operation. The adding of udev hard disk expansion rules and the making process of mirroring are described. The udev hard disk hot expansion rule matching key, setting the ACTION (behavior of uevent event) in the rule to change means that this rule takes effect when the hard disk changes; the subsystem name SUBSYSTEM of the device is set to block; DEVPATH is set to the kernel device path of the corresponding hard disk; when the above matching key is completely matched with the uevent sent by the kernel, the subsequent assignment key will be executed; dev is the hard disk hot expansion rule assignment key. Set the rule udev key RUN to execute the preset script. The content of the preset script is to expand the partition and file system corresponding to the expanded hard disk; the growpart tool is used to expand the partition, and the resize2fs tool is used to expand the file system.
2. The method according to claim 1, characterized in that During the image creation process, you need to pre-set the prepared udev hard disk hot expansion rules and scripts; and ensure that the added rules have been loaded into udev and take effect; During the image creation process, it is necessary to ensure that the root partition is the last partition of the system disk to ensure that the root partition can be successfully expanded when the system disk is expanded.
3. The method according to claim 2, characterized in that The process of processing a hard disk hot expansion request is as follows: (1) The user has created a cloud server using the image created above; the user has made a hot expansion request for this cloud server; (2) The server verifies the user request, performs permission verification, and performs subsequent operations after the verification is passed; (3) The server responds to the request and sends it to the computing node where the cloud server is located through the message queue; (4) The corresponding program on the computing node responds to the request and searches for the device name corresponding to the disk ID through the cloud server block device mapping; calls the libvirt API to pass in the cloud server ID, device name, and new disk size; (5) Libvirt calls the specific driver to perform the disk expansion operation.
4. The method according to claim 3, characterized in that The steps to expand the partition and file system are as follows: (1) When the disk size changes, the kernel will issue a uevent event with action change; (2) The udev daemon listens to the uevent message and matches the uevent with the existing rules. If all matching keys meet the requirements of the rule, the corresponding assignment key is executed; (3) If the uevent meets the hard disk hot expansion rules, the preset script is executed; (4) Call growpart to expand the last partition of the corresponding disk. If the system disk is to be expanded, the script will search for the partition where the mount point " / " is located, that is, the root partition for expansion. If the disk has been mounted to a file system, call resize2fs to expand the corresponding file system.
