A method of modification virtual machine image subregion
Technical field
The present invention relates to desktop cloud mirror image administrative skill field, especially a kind of method for modifying virtual machine image subregion.
Background technique
There are more and more desktop cloud platforms to be applied to inside each enterprise now, each enterprise demand is very
It is personalized;It much requires and existing server is utilized, such as create cloud desktop based on existing server;In this way
The disk configuration of cloud desktop is usually also required to personalization.Traditional mode mainly by way of manual, needs to make according to user
The cloud desktop for making the disk partition to meet the requirements of the customers is supplied to user's use, can there is following hidden danger in this way:
First is that a secondary mirror will be remake by hand according to each customer demand when desktop cloud project is more and more
Picture.Actually the software of cloud desktop is all consistent with operating system, and only disk partition and CPU configuration are different.And CPU configuration is logical
It is all often that dynamic adjusts, and system disk subregion is then mirror image default.And a completely new mirror image is made, it is various to installing by bare machine
Software is very time-consuming and laborious.
Second is that client wants to adjust partition size again actually in use process, need into each cloud desktop
Inside operating system, the subregion of each cloud desktop is modified by hand in the same way, and the usual quantity of the desktop of desktop cloud all compares
Huger, such efficiency is very low, and manual operation user makes mistakes.
To solve the above-mentioned problems, a kind of method for modifying virtual machine image subregion is needed.It is virtual by a kind of modification
The method of machine mirrored partition, in a manner of full-automatic, efficient, mirrored partition can not be modified automatically, can not press by being able to solve
Contracting mirror image cannot come into force to the virtual machine that mirror image is used, can not reduce the problems such as mirror image partition size.
Summary of the invention
Present invention solves the technical problem that being to provide a kind of method for modifying virtual machine image subregion;Solving can not be certainly
Dynamic modification mirrored partition, mirror image can not be compressed, cannot be come into force to the virtual machine that mirror image is used, can not to reduce mirrored partition big
The problems such as small.
The technical solution that the present invention solves above-mentioned technical problem is:
The method is to create new mirror image according to the virtual machine partitions situation inquired;And according to needing to modify new mirror
The subregion of picture;Former mirror image is replaced with new mirror image again.
The method includes the following steps:
Step 1: checking subregion service condition;
Step 2: creating new mirror image;
Step 3: modifying new mirrored partition;
Step 4: compressing new image file;
Step 5: replacing former mirror image using new mirror image;
Step 6: starting virtual machine;
Described checks subregion service condition, refers to the service condition for checking former mirrored partition, includes title, type,
The mirror image is used with space, available space, total size and which virtual machine;
The type containing type has subregion, block device;
The subregion refers to disk partition.
The new mirror image of creation is the new image file for creating a size and former mirror image striking resemblances.
The new mirrored partition of modification, which refers to, all shuts down the virtual machine that former mirror image is used, then by former mirror image
Information imported into inside new mirror image while modifying new mirrored partition size.
The new mirrored partition size of the modification refers to increase or reduces the size of mirrored partition;If desired mirror image is reduced
Subregion, first judges whether available space is greater than the space of diminution, if so then execute mirror image partition size is reduced;Otherwise modification is shown
Mirrored partition failure.
The new image file of compression refers to the actual size for compressing new image file;Image file is by increase
Afterwards, authentic document size can expand automatically, at this time in order to save memory space, then need to compress the actual size of mirror image, compression
The logic size of mirror image can't change afterwards.
Replacing former mirror image using new mirror image is that original mirror image is replaced by new mirror image, realizes mirrored partition modification.
The starting virtual machine is the virtual machine that starting uses the mirror image, and virtual machine will load repair during startup
Mirrored partition after changing.
For the present invention by a kind of method for modifying virtual machine image subregion, mirrored partition, nothing can not be modified automatically by solving
Method compression mirror image cannot come into force to the virtual machine that mirror image is used, can not reduce the problems such as mirror image partition size.The present invention is whole
A process is full-automatic, does not need manual intervention, is different from general method.The method provided by the present invention can not only extend mirror image point
The size in area can also reduce the size of mirrored partition, and a variety of granularities after being different from a kind of backup of virtual machine image grade are restored
Method can not extend or reduce automatically subregion.The method provided by the present invention re-compresses mirror image after extending mirror image, guarantees mirror image
Physics occupied space minimizes, and maximally utilizes memory space, is suitble to desktop cloud to the very high project of cost requirement, is different from one
As method.The method provided by the present invention all uniformly comes into force to the virtual machine based on former mirror image, after restarting virtual machine, point of virtual machine
Area's size becomes consistent after mirrored partition is modified, and helps adaptation project individual demand, is different from general method.
Detailed description of the invention
The following further describes the present invention with reference to the drawings:
Fig. 1 is flow chart of the present invention.
Specific embodiment
There are many embodiments of the present invention, illustrates one of implementation method, process by taking desktop cloud platform as an example here
Figure is as shown in Figure 1, specific implementation process is as follows
1, check that subregion service condition, process are as follows:
1) information of file system is checked;
2) information of case of non-partitioned is filtered out, is left all to be partition information;
3) the virtual machine list based on former mirror image is inquired.
2, new mirror image is created, process is as follows:
1) size of former mirror image is obtained;
2) a new image file with former mirror image size striking resemblances is created.
3, new mirrored partition is modified, process is as follows:
1) all virtual machines based on former mirror image are closed;
2) judge modification mode, if reduction operation, then judge whether subregion available space is greater than the space of diminution, if
Then continue, otherwise reports exception and the process that terminates;If extended operation, then whether host operating system current space available is judged
New mirror image is created enough, if then continuing, otherwise reports exception and the process that terminates;
3) former mirror file system is imported into new image file while modifies mirrored partition size.
4, new image file is compressed, process is as follows:
1) by new mirror image boil down to qcow2 format;
2) actual size and logic size of new mirror image are checked;
3) whether decision logic size changes, and exception is reported if changing and the process that terminates.
5, former mirror image is replaced using new mirror image, process is as follows:
1) new be mirrored on mirror image server is uploaded;
2) virtual machine based on former mirror image is all uniformly revised as based on new mirror image.
6, start virtual machine, check the modified partition information of virtual machine.
Whole flow process terminates.