|
|
最近在搞qemu
本篇来自:http://qemu.dad-answers.com/viewtopic.php?p=3451
First step would have to be to free up a whole lot of space on the drive you plan to perform this exercise. Approximately 2 times the size of the target disk image you require. This process involves copying your entire image to an intermediate format. I execute this process under 'Windows XP' although I am sure a similar approach can be taken under any OS.
1. Execute the following command to convert your disk image to a raw disk image (note change the source image format ie. qcow, in the command)
qemu-img convert -f qcow <file_to_resize> -O raw <rawformat_filename>
Note that the conversion to the raw format does not seem to be completely successful in that the file in the raw format is not filled to its full defined capacity. ie. a 2 GB file that is converted to a raw format might only create a file that is 1.5 GB in size. Thus when it is used it will not be recognised as a valid format. This will be overcome later.
2. Execute the following to create a raw block of data that can be used to expand the disk image. You can make this bigger - your discretion.
qemu-img create -f raw temp.img 100M
3. The following command will resize by adding the blank raw block of data to the end of the file. Due to the problem in converting to a raw image, in that it is not created to its full size we need to determine how much raw data to append to the end of the file. Thus following on from the example earlier, if you end up with a raw image of a size 1.5 GB and you want a final size of 4 GB then determine how many times 100M (created in the last command) occurs within 2.5 GB (4 Gb - 1.5 GB). Thus need to append 2.5 GB or 25 times 100 M (25 x 100 = 2.5 GB). Repeat the 'temp.img' as many times as required in the 'copy' command below.
copy /b <file_to_resize>+temp.img+temp.img+temp.img+temp.img+temp.img+temp.img <rawformat_filename>
Note - the /b parameter is required to ensure the copy occurs as 'binary' copy.
4. You should test this disk image (in your VM or where ever used). It should now still have a partition of 2 GB (original size) and 2 GB of unused space. Use your preferred partition manager to resize your partition.
I used a live boot disk for 'gparted' and started it in QEMU and resized the partition (I had to convert to NTFS as 'gparted' was not successful in coverting the FAT16 format it was originally in)
5. To now reclaim the space from the raw disk image I then converted it back to a compressable format tha QEMU can recognise. In this case a vmware disk image. Change the target format to whatever you require (here it is vmdk).
qemu-img convert -f raw <rawformat_filename> -O vmdk <final_filename> |
|