5 virt-sparsify - Make a virtual machine disk sparse
9 virt-sparsify [--options] indisk outdisk
13 Virt-sparsify is a tool which can make a virtual machine disk (or any
14 disk image) sparse a.k.a. thin-provisioned. This means that free
15 space within the disk image can be converted back to free space on the
18 Virt-sparsify can locate and sparsify free space in most filesystems
19 (eg. ext2/3/4, btrfs, NTFS, etc.), and also in LVM physical volumes.
21 Virt-sparsify can also convert between some disk formats, for example
22 converting a raw disk image to a thin-provisioned qcow2 image.
24 Virt-sparsify can operate on any disk image, not just ones from
25 virtual machines. If a virtual machine has more than one attached
26 disk, you must sparsify each one separately.
28 =head2 IMPORTANT LIMITATIONS
34 Virt-sparsify does not do in-place modifications. It copies from a
35 source image to a destination image, leaving the source unchanged.
36 I<Check that the sparsification was successful before deleting the
41 The virtual machine I<must be shut down> before using this tool.
45 Virt-sparsify may require up to 2x the virtual size of the source disk
46 image (1 temporary copy + 1 destination image). This is in the worst
47 case and usually much less space is required.
51 Virt-sparsify cannot resize disk images. To do that, use
56 Virt-sparsify cannot handle encrypted disks.
60 Virt-sparsify cannot yet sparsify the space between partitions. Note
61 that this space is often used for critical items like bootloaders so
62 it's not really unused.
66 Virt-sparsify does not yet know how to sparsify swapspace. It is not
67 safe to do this unless we can be sure there is no hibernation data, so
68 at the moment swap partitions are ignored.
72 You may also want to read the manual pages for the associated tools
73 L<virt-filesystems(1)> and L<virt-df(1)> before starting.
79 virt-sparsify indisk outdisk
81 which copies C<indisk> to C<outdisk>, making the output sparse.
82 C<outdisk> is created, or overwritten if it already exists. The
83 format of the input disk is detected (eg. qcow2) and the same format
84 is used for the output disk.
86 To convert between formats, use the I<--convert> option:
88 virt-sparsify disk.raw --convert qcow2 disk.qcow2
90 Virt-sparsify tries to zero and sparsify free space on every
91 filesystem it can find within the source disk image. You can get it
92 to ignore (don't zero free space on) certain filesystems by doing:
94 virt-sparsify --ignore /dev/sda1 indisk outdisk
96 See L<virt-filesystems(1)> to get a list of filesystems within a disk
109 Compress the output file. This I<only> works if the output format is
112 =item B<--convert> raw
114 =item B<--convert> qcow2
116 =item B<--convert> [other formats]
118 Use C<output-format> as the format for the destination image. If this
119 is not specified, then the input format is used.
121 Supported and known-working output formats are: C<raw>, C<qcow2>, C<vdi>.
123 You can also use any format supported by the L<qemu-img(1)> program,
124 eg. C<vmdk>, but support for other formats is reliant on qemu.
126 Specifying the I<--convert> option is usually a good idea, because
127 then virt-sparsify doesn't need to try to guess the input format.
129 For fine-tuning the output format, see: I<--compress>, I<-o>.
133 Debug garbage collection and memory allocation. This is only useful
134 when debugging memory problems in virt-sparsify or the OCaml libguestfs
137 =item B<--format> raw
139 =item B<--format> qcow2
141 Specify the format of the input disk image. If this flag is not
142 given then it is auto-detected from the image itself.
144 If working with untrusted raw-format guest disk images, you should
145 ensure the format is always specified.
147 =item B<--ignore> filesystem
149 =item B<--ignore> volgroup
151 Ignore the named filesystem. Free space on the filesystem will not be
152 zeroed, but existing blocks of zeroes will still be sparsified.
154 In the second form, this ignores the named volume group. Use the
155 volume group name without the C</dev/> prefix, eg. I<--ignore vg_foo>
157 You can give this option multiple times.
159 =item B<--machine-readable>
161 This option is used to make the output more machine friendly
162 when being parsed by other programs. See
163 L</MACHINE READABLE OUTPUT> below.
165 =item B<-o> option[,option,...]
167 Pass I<-o> option(s) to the L<qemu-img(1)> command to fine-tune the
168 output format. Options available depend on the output format (see
169 I<--convert>) and the installed version of the qemu-img program.
171 You should use I<-o> at most once. To pass multiple options, separate
172 them with commas, eg:
174 virt-sparsify --convert qcow2 \
175 -o cluster_size=512,preallocation=metadata ...
181 This disables progress bars and other unnecessary output.
187 Enable verbose messages for debugging.
193 Display version number and exit.
197 Enable tracing of libguestfs API calls.
201 =head1 MACHINE READABLE OUTPUT
203 The I<--machine-readable> option can be used to make the output more
204 machine friendly, which is useful when calling virt-sparsify from
205 other programs, GUIs etc.
207 There are two ways to use this option.
209 Firstly use the option on its own to query the capabilities of the
210 virt-sparsify binary. Typical output looks like this:
212 $ virt-sparsify --machine-readable
217 A list of features is printed, one per line, and the program exits
220 Secondly use the option in conjunction with other options to make the
221 regular program output more machine friendly.
223 At the moment this means:
229 Progress bar messages can be parsed from stdout by looking for this
236 The calling program should treat messages sent to stdout (except for
237 progress bar messages) as status messages. They can be logged and/or
238 displayed to the user.
242 The calling program should treat messages sent to stderr as error
243 messages. In addition, virt-sparsify exits with a non-zero status
244 code if there was a fatal error.
248 All versions of virt-sparsify have supported the I<--machine-readable>
253 This program returns 0 if successful, or non-zero if there was an
256 =head1 ENVIRONMENT VARIABLES
262 Location of the temporary directory used for the potentially large
263 temporary overlay file.
265 You should ensure there is enough free space in the worst case for a
266 full copy of the source disk (I<virtual> size), or else set C<$TMPDIR>
267 to point to another directory that has enough space.
269 This defaults to C</tmp>.
273 For other environment variables, see L<guestfs(3)/ENVIRONMENT VARIABLES>.
277 L<virt-filesystems(1)>,
286 L<http://libguestfs.org/>.
290 Richard W.M. Jones L<http://people.redhat.com/~rjones/>
294 Copyright (C) 2011 Red Hat Inc.
296 This program is free software; you can redistribute it and/or modify
297 it under the terms of the GNU General Public License as published by
298 the Free Software Foundation; either version 2 of the License, or
299 (at your option) any later version.
301 This program is distributed in the hope that it will be useful,
302 but WITHOUT ANY WARRANTY; without even the implied warranty of
303 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 GNU General Public License for more details.
306 You should have received a copy of the GNU General Public License
307 along with this program; if not, write to the Free Software
308 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.