A kind of quick formatting and the method using magnetic disk of virtual machine
Technical field
The present invention relates to field of cloud computer technology, especially a kind of quick formatting and the method using magnetic disk of virtual machine.
Background technique
Under cloud computing environment, each cloud platform is intended to dominate the market, and increases the user volume of oneself, in such case
Under, good user experience is most important.
Virtual machine requires addition storing data disk and comes extension storage space, current method in operation use process
Steps are as follows:
1, the disk file of specified format is created above in host;
2, the disk file of creation is mounted to virtual machine;
3, user logs in virtual machine, the disk newly increased is checked in disk management, and format, disk is divided to use.
This method is available, but user experience is not so good, especially for being unfamiliar with for the user of virtual machine system,
It may not know how to find new disk and format to use.
In order to improve user using the Experience Degree in virtual machine process, facilitate user that extension is simply gone to use virtual machine
Disk storage space, need a kind of simple and effective quick formatting and the method using magnetic disk of virtual machine.
Summary of the invention
Present invention solves the technical problem that being to provide a kind of quick formatting and the method using magnetic disk of virtual machine, solve
Virtual machine existing user experience bottom, use process when extension is using disk are cumbersome under cloud platform environment at this stage
Problem.
The technical solution that the present invention solves above-mentioned technical problem is:
The method includes:
Step 1, magnetic disk of virtual machine formatted file is created above in host;
Step 2, the block that the disk file created connection is mounted to above host is set using virtualization tool
It is standby;
Step 3, the block device is formatted using block device Formatting Facility;
Step 4, formatted block device is unloaded;
Step 5, formatted magnetic disk of virtual machine file mount is used to virtual machine.
The block device is one kind in computer I/O equipment, and block device stores information in the block of fixed size,
The each piece of address for having oneself;Each piece can read and write independently of other pieces.
The block device Formatting Facility determines according to virtual machine system type and required disk type, commonly such as
The common ntfs type of windows virtual machine then uses mkfs.ntfs Formatting Facility etc.:
The formatting refers to the storage content in fully erased disk file, and a kind of new file system is arranged for it
System;
The file system refers to that operating system is for clearly storing the side of equipment or the file on subregion in computer
Method and data structure;That is the method for constituent act on a storage device.
The unloading block device is the connection relationship for closing the disk file and block device.
The carry disk file can be to virtual machine use restarts mode by modifying virtual machine configuration,
It can be direct hot plug form;
The hot plug refers to directly using virsh attach-device tool mount virtual machine disk file to void
Quasi- machine is used as disk, and virtual machine does not need to restart.
The present invention program's has the beneficial effect that:
1, a kind of new, simpler quick formatting is provided with using the method for magnetic disk of virtual machine, and the present invention provides
Method And Principle is simple, operating process is efficient, while method is also easily realized.
2, method user experience provided by the invention is good, and it is existing during newly-increased magnetic disk of virtual machine to avoid user
Cumbersome, professional technique requires the problems such as high.
Detailed description of the invention
The following further describes the present invention with reference to the drawings:
Fig. 1 is flow chart of the invention.
Specific embodiment
Following will be combined with the drawings in the embodiments of the present invention, and technical solution in the embodiment of the present invention carries out clear, complete
Whole description, it is clear that described embodiments are only a part of the embodiments of the present invention, instead of all the embodiments.It is based on
Embodiment in the present invention, it is obtained by those of ordinary skill in the art without making creative efforts every other
Embodiment shall fall within the protection scope of the present invention.
It referring to Figure 1, is a kind of quick formatting provided in an embodiment of the present invention and the method using magnetic disk of virtual machine
Flow diagram, which comprises
First the creation in host virtualizes the disk file that type corresponds to format to administrator
Specifically we are illustrated by taking the disk file of XEN virtualization type creation vhd format as an example, and others are such as
The application methods such as the qcow2 format disc file under KVM virtualization type are similar;Execution, which is such as issued orders, creates vhd format
Disk file:
#vhd-util create -n add.vhd-s 2000
As above order creates the vhd format disc file add.vhd of a 2G size with vhd-util tool.
Then it is virtual the vhd format disc file add.vhd connection created to be mounted to an XEN on host
Change the block device under type:
0 tap2:tapdisk:vhd:/root/add.vhd of #xm block-attach/dev/xvdf w 0
Non- xvda/b/c... of block device naming rule under XEN virtualized environment etc., above we utilize xm block-
Disk file connection has been mounted to/dev/xvdf block device by attach tool.
Then above-mentioned block device/dev/xvdf is formatted using the Formatting Facilities such as mkfs.ntfs, here we
Assuming that disk file is formatted as ntfs file system is supplied to windows virtual machine use, execution is such as issued orders:
#mkfs.ntfs /dev/xvdf -f
After formatting successfully above, it that is to say and formatted the subsequent disk file add.vhd of block device.Then
The connection of block device and disk file is closed in unloading:
#xm block-detach 0 /dev/xvdf
Finally, we edit the relevant configuration file add.xml of a virtual machine block device, content is as follows:
Then by executing virsh attach-device i-xxxxxxxx add.xml order for disk file carry
It is used to virtual machine, is not necessarily to the troublesome operations such as carry out additional discovery disk, format diskette after logging in virtual machine.