New tool: virt-sparsify to make disk images sparse.
[libguestfs.git] / sparsify / virt-sparsify.pod
1 =encoding utf8
2
3 =head1 NAME
4
5 virt-sparsify - Make a virtual machine disk sparse
6
7 =head1 SYNOPSIS
8
9  virt-sparsify [--options] indisk outdisk
10
11 =head1 DESCRIPTION
12
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
16 host.
17
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.
20
21 Virt-sparsify can also convert between some disk formats, for example
22 converting a raw disk image to a thin-provisioned qcow2 image.
23
24 Virt-sparsify can operate on any disk image, not just ones from
25 virtual machines.  If a virtual machine has multiple disk images, then
26 you must sparsify each one separately.
27
28 =head2 IMPORTANT LIMITATIONS
29
30 =over 4
31
32 =item *
33
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
37 source image>.
38
39 =item *
40
41 The virtual machine I<must be shut down> before using this tool.
42
43 =item *
44
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.
48
49 =item *
50
51 Virt-sparsify cannot resize disk images.  To do that, use
52 L<virt-resize(1)>.
53
54 =item *
55
56 Virt-sparsify cannot handle encrypted disks.
57
58 =item *
59
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.
63
64 =item *
65
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.
69
70 =back
71
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.
74
75 =head1 EXAMPLES
76
77 Typical usage is:
78
79  virt-sparsify indisk outdisk
80
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.
85
86 To convert between formats, use the I<--convert> option:
87
88  virt-sparsify disk.raw --convert qcow2 disk.qcow2
89
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:
93
94  virt-sparsify --ignore /dev/sda1 indisk outdisk
95
96 See L<virt-filesystems(1)> to get a list of filesystems within a disk
97 image.
98
99 =head1 OPTIONS
100
101 =over 4
102
103 =item B<--help>
104
105 Display help.
106
107 =item B<--convert> raw
108
109 =item B<--convert> qcow2
110
111 =item B<--convert> [other formats]
112
113 Use C<output-format> as the format for the destination image.  If this
114 is not specified, then the input format is used.
115
116 Supported and known-working output formats are: C<raw>, C<qcow2>.
117
118 You can also use any format supported by the L<qemu-img(1)> program,
119 eg. C<vdi> or C<vmdk>, but support for other formats is reliant on
120 qemu.
121
122 Specifying the I<--convert> option is usually a good idea, because
123 then virt-sparsify doesn't need to try to guess the input format.
124
125 =item B<--format> raw
126
127 =item B<--format> qcow2
128
129 Specify the format of the input disk image.  If this flag is not
130 given then it is auto-detected from the image itself.
131
132 If working with untrusted raw-format guest disk images, you should
133 ensure the format is always specified.
134
135 =item B<--ignore> filesystem
136
137 =item B<--ignore> volgroup
138
139 Ignore the named filesystem.  Free space on the filesystem will not be
140 zeroed, but existing blocks of zeroes will still be sparsified.
141
142 In the second form, this ignores the named volume group.  Use the
143 volume group name without the C</dev/> prefix, eg. I<--ignore vg_foo>
144
145 You can give this option multiple times.
146
147 =item B<--machine-readable>
148
149 This option is used to make the output more machine friendly
150 when being parsed by other programs.  See
151 L</MACHINE READABLE OUTPUT> below.
152
153 =item B<-q>
154
155 =item B<--quiet>
156
157 This disables progress bars and other unnecessary output.
158
159 =item B<-v>
160
161 =item B<--verbose>
162
163 Enable verbose messages for debugging.
164
165 =item B<-V>
166
167 =item B<--version>
168
169 Display version number and exit.
170
171 =item B<-x>
172
173 Enable tracing of libguestfs API calls.
174
175 =back
176
177 =head1 MACHINE READABLE OUTPUT
178
179 The I<--machine-readable> option can be used to make the output more
180 machine friendly, which is useful when calling virt-sparsify from
181 other programs, GUIs etc.
182
183 There are two ways to use this option.
184
185 Firstly use the option on its own to query the capabilities of the
186 virt-sparsify binary.  Typical output looks like this:
187
188  $ virt-sparsify --machine-readable
189  virt-sparsify
190  ntfs
191  btrfs
192
193 A list of features is printed, one per line, and the program exits
194 with status 0.
195
196 Secondly use the option in conjunction with other options to make the
197 regular program output more machine friendly.
198
199 At the moment this means:
200
201 =over 4
202
203 =item 1.
204
205 Progress bar messages can be parsed from stdout by looking for this
206 regular expression:
207
208  ^[0-9]+/[0-9]+$
209
210 =item 2.
211
212 The calling program should treat messages sent to stdout (except for
213 progress bar messages) as status messages.  They can be logged and/or
214 displayed to the user.
215
216 =item 3.
217
218 The calling program should treat messages sent to stderr as error
219 messages.  In addition, virt-sparsify exits with a non-zero status
220 code if there was a fatal error.
221
222 =back
223
224 All versions of virt-sparsify have supported the I<--machine-readable>
225 option.
226
227 =head1 EXIT STATUS
228
229 This program returns 0 if successful, or non-zero if there was an
230 error.
231
232 =head1 ENVIRONMENT VARIABLES
233
234 =over 4
235
236 =item TMPDIR
237
238 Location of the temporary directory used for the potentially large
239 temporary overlay file.
240
241 You should ensure there is enough free space in the worst case for a
242 full copy of the source disk (I<virtual> size), or else set C<$TMPDIR>
243 to point to another directory that has enough space.
244
245 This defaults to C</tmp>.
246
247 =back
248
249 For other environment variables, see L<guestfs(3)/ENVIRONMENT VARIABLES>.
250
251 =head1 SEE ALSO
252
253 L<virt-filesystems(1)>,
254 L<virt-df(1)>,
255 L<virt-resize(1)>,
256 L<virt-rescue(1)>,
257 L<guestfs(3)>,
258 L<guestfish(1)>,
259 L<truncate(1)>,
260 L<fallocate(1)>,
261 L<qemu-img(1)>,
262 L<http://libguestfs.org/>.
263
264 =head1 AUTHOR
265
266 Richard W.M. Jones L<http://people.redhat.com/~rjones/>
267
268 =head1 COPYRIGHT
269
270 Copyright (C) 2011 Red Hat Inc.
271
272 This program is free software; you can redistribute it and/or modify
273 it under the terms of the GNU General Public License as published by
274 the Free Software Foundation; either version 2 of the License, or
275 (at your option) any later version.
276
277 This program is distributed in the hope that it will be useful,
278 but WITHOUT ANY WARRANTY; without even the implied warranty of
279 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
280 GNU General Public License for more details.
281
282 You should have received a copy of the GNU General Public License
283 along with this program; if not, write to the Free Software
284 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.