1virt-sparsify(1)            Virtualization Support            virt-sparsify(1)
2
3
4

NAME

6       virt-sparsify - Make a virtual machine disk sparse
7

SYNOPSIS

9        virt-sparsify [--options] indisk outdisk
10
11        virt-sparsify [--options] --in-place disk
12

WARNING

14       Using "virt-sparsify" on live virtual machines, or concurrently with
15       other disk editing tools, can be dangerous, potentially causing disk
16       corruption.  The virtual machine must be shut down before you use this
17       command, and disk images must not be edited concurrently.
18

DESCRIPTION

20       Virt-sparsify is a tool which can make a virtual machine disk (or any
21       disk image) sparse a.k.a. thin-provisioned.  This means that free space
22       within the disk image can be converted back to free space on the host.
23
24       Virt-sparsify can locate and sparsify free space in most filesystems
25       (eg. ext2/3/4, btrfs, NTFS, etc.), and also in LVM physical volumes.
26
27       Virt-sparsify can also convert between some disk formats, for example
28       converting a raw disk image to a thin-provisioned qcow2 image.
29
30       Virt-sparsify can operate on any disk image, not just ones from virtual
31       machines.  However if a virtual machine has multiple disks and uses
32       volume management, then virt-sparsify will work but not be very
33       effective (http://bugzilla.redhat.com/887826).
34
35   IMPORTANT NOTE ABOUT SPARSE OUTPUT IMAGES
36       If the input is raw, then the default output is raw sparse.  You must
37       check the output size using a tool that understands sparseness such as
38       "du -sh".  It can make a huge difference:
39
40        $ ls -lh test1.img
41        -rw-rw-r--. 1 rjones rjones 100M Aug  8 08:08 test1.img
42        $ du -sh test1.img
43        3.6M   test1.img
44
45       (Compare the apparent size 100M vs the actual size 3.6M)
46
47   IMPORTANT LIMITATIONS
48       •   The virtual machine must be shut down before using this tool.
49
50       •   Virt-sparsify may require up to 2x the virtual size of the source
51           disk image (1 temporary copy + 1 destination image).  This is in
52           the worst case and usually much less space is required.
53
54           If you are using the --in-place option, then large amounts of
55           temporary space are not required.
56
57       •   Virt-sparsify cannot resize disk images.  To do that, use
58           virt-resize(1).
59
60       •   Virt-sparsify cannot handle encrypted disks.  Libguestfs supports
61           encrypted disks, but encrypted disks themselves cannot be
62           sparsified.
63
64       •   Virt-sparsify cannot yet sparsify the space between partitions.
65           Note that this space is often used for critical items like
66           bootloaders so it's not really unused.
67
68       •   In copy mode, qcow2 internal snapshots are not copied over to the
69           destination image.
70
71       You may also want to read the manual pages for the associated tools
72       virt-filesystems(1) and virt-df(1) before starting.
73

EXAMPLES

75       Typical usage is:
76
77        virt-sparsify indisk outdisk
78
79       which copies "indisk" to "outdisk", making the output sparse.
80       "outdisk" is created, or overwritten if it already exists.  The format
81       of the input disk is detected (eg. qcow2) and the same format is used
82       for the output disk.
83
84       To convert between formats, use the --convert option:
85
86        virt-sparsify disk.raw --convert qcow2 disk.qcow2
87
88       Virt-sparsify tries to zero and sparsify free space on every filesystem
89       it can find within the source disk image.  You can get it to ignore
90       (don't zero free space on) certain filesystems by doing:
91
92        virt-sparsify --ignore /dev/sda1 indisk outdisk
93
94       See virt-filesystems(1) to get a list of filesystems within a disk
95       image.
96
97       Since virt-sparsify ≥ 1.26, you can now sparsify a disk image in place
98       by doing:
99
100        virt-sparsify --in-place disk.img
101

OPTIONS

103       --help
104           Display help.
105
106       --check-tmpdir ignore
107       --check-tmpdir continue
108       --check-tmpdir warn
109       --check-tmpdir fail
110           Check if "TMPDIR" or --tmp directory has enough space to complete
111           the operation.  This is just an estimate.
112
113           If the check indicates a problem, then you can either:
114
115ignore it,
116
117           •   print a warning and continue,
118
119warn and wait for the user to press the Return key (this is the
120               default), or:
121
122fail and exit.
123
124           You cannot use this option and --in-place together.
125
126       --colors
127       --colours
128           Use ANSI colour sequences to colourize messages.  This is the
129           default when the output is a tty.  If the output of the program is
130           redirected to a file, ANSI colour sequences are disabled unless you
131           use this option.
132
133       --compress
134           Compress the output file.  This only works if the output format is
135           "qcow2".
136
137           You cannot use this option and --in-place together.
138
139       --convert raw
140       --convert qcow2
141       --convert [other formats]
142           Use "output-format" as the format for the destination image.  If
143           this is not specified, then the input format is used.
144
145           Supported and known-working output formats are: "raw", "qcow2",
146           "vdi".
147
148           You can also use any format supported by the qemu-img(1) program,
149           eg. "vmdk", but support for other formats is reliant on qemu.
150
151           Specifying the --convert option is usually a good idea, because
152           then virt-sparsify doesn't need to try to guess the input format.
153
154           For fine-tuning the output format, see: --compress, -o.
155
156           You cannot use this option and --in-place together.
157
158       --echo-keys
159           When prompting for keys and passphrases, virt-sparsify normally
160           turns echoing off so you cannot see what you are typing.  If you
161           are not worried about Tempest attacks and there is no one else in
162           the room you can specify this flag to see what you are typing.
163
164       --format raw
165       --format qcow2
166           Specify the format of the input disk image.  If this flag is not
167           given then it is auto-detected from the image itself.
168
169           If working with untrusted raw-format guest disk images, you should
170           ensure the format is always specified.
171
172       --ignore filesystem
173       --ignore volgroup
174           Ignore the named filesystem.
175
176           When not using --in-place: Free space on the filesystem will not be
177           zeroed, but existing blocks of zeroes will still be sparsified.
178
179           When using --in-place, the filesystem is ignored completely.
180
181           In the second form, this ignores the named volume group.  Use the
182           volume group name without the /dev/ prefix, eg. --ignore vg_foo
183
184           You can give this option multiple times.
185
186       --in-place
187           Do in-place sparsification instead of copying sparsification.  See
188           "IN-PLACE SPARSIFICATION" below.
189
190       --key SELECTOR
191           Specify a key for LUKS, to automatically open a LUKS device when
192           using the inspection.
193
194           --key NAME:key:KEY_STRING
195           --key UUID:key:KEY_STRING
196           --key all:key:KEY_STRING
197               "NAME" is the libguestfs device name (eg. "/dev/sda1").  "UUID"
198               is the device UUID.  "all" means try the key against any
199               encrypted device.
200
201               Use the specified "KEY_STRING" as passphrase.
202
203           --key NAME:file:FILENAME
204           --key UUID:file:FILENAME
205           --key all:file:FILENAME
206               Read the passphrase from FILENAME.
207
208           --key NAME:clevis
209           --key UUID:clevis
210           --key all:clevis
211               Attempt passphrase-less unlocking for the device with Clevis,
212               over the network.  Please refer to "ENCRYPTED DISKS" in
213               guestfs(3) for more information on network-bound disk
214               encryption (NBDE).
215
216               Note that if any such option is present on the command line,
217               QEMU user networking will be automatically enabled for the
218               libguestfs appliance.
219
220       --keys-from-stdin
221           Read key or passphrase parameters from stdin.  The default is to
222           try to read passphrases from the user by opening /dev/tty.
223
224           If there are multiple encrypted devices then you may need to supply
225           multiple keys on stdin, one per line.
226
227       --machine-readable
228       --machine-readable=format
229           This option is used to make the output more machine friendly when
230           being parsed by other programs.  See "MACHINE READABLE OUTPUT"
231           below.
232
233       -o option[,option,...]
234           Pass -o option(s) to the qemu-img(1) command to fine-tune the
235           output format.  Options available depend on the output format (see
236           --convert) and the installed version of the qemu-img program.
237
238           You should use -o at most once.  To pass multiple options, separate
239           them with commas, eg:
240
241            virt-sparsify --convert qcow2 \
242              -o cluster_size=512,preallocation=metadata ...
243
244           You cannot use this option and --in-place together.
245
246       -q
247       --quiet
248           This disables progress bars and other unnecessary output.
249
250       --tmp block_device
251       --tmp dir
252           In copying mode only, use the named device or directory as the
253           location of the temporary overlay (see also "TMPDIR" below).
254
255           If the parameter given is a block device, then the block device is
256           written to directly.  Note this erases the existing contents of the
257           block device.
258
259           If the parameter is a directory, then this is the same as setting
260           the "TMPDIR" environment variable.
261
262           You cannot use this option and --in-place together.
263
264       --tmp prebuilt:file
265           In copying mode only, the specialized option --tmp prebuilt:file
266           (where "prebuilt:" is a literal string) causes virt-sparsify to use
267           the qcow2 "file" as temporary space.
268
269           •   The file must be freshly formatted as qcow2, with indisk as the
270               backing file.
271
272           •   If you rerun virt-sparsify, you must recreate the file before
273               each run.
274
275           •   Virt-sparsify does not delete the file.
276
277           This option is used by oVirt which requires a specially formatted
278           temporary file.
279
280       -v
281       --verbose
282           Enable verbose messages for debugging.
283
284       -V
285       --version
286           Display version number and exit.
287
288       --wrap
289           Wrap error, warning, and informative messages.  This is the default
290           when the output is a tty.  If the output of the program is
291           redirected to a file, wrapping is disabled unless you use this
292           option.
293
294       -x  Enable tracing of libguestfs API calls.
295
296       --zero partition
297       --zero logvol
298           Zero the contents of the named partition or logical volume in the
299           guest.  All data on the device is lost, but sparsification is
300           excellent!  You can give this option multiple times.
301

IN-PLACE SPARSIFICATION

303       Since virt-sparsify ≥ 1.26, the tool is able to do in-place
304       sparsification (instead of copying from an input disk to an output
305       disk).  This is more efficient.  It is not able to recover quite as
306       much space as copying sparsification.
307
308       To use this mode, specify a disk image which will be modified in place:
309
310        virt-sparsify --in-place disk.img
311
312       Some options are not compatible with this mode: --convert, --compress
313       and -o because they require wholesale disk format changes;
314       --check-tmpdir because large amounts of temporary space are not
315       required.
316
317       In-place sparsification works using discard (a.k.a trim or unmap)
318       support.
319

MACHINE READABLE OUTPUT

321       The --machine-readable option can be used to make the output more
322       machine friendly, which is useful when calling virt-sparsify from other
323       programs, GUIs etc.
324
325       There are two ways to use this option.
326
327       Firstly use the option on its own to query the capabilities of the
328       virt-sparsify binary.  Typical output looks like this:
329
330        $ virt-sparsify --machine-readable
331        virt-sparsify
332        ntfs
333        btrfs
334
335       A list of features is printed, one per line, and the program exits with
336       status 0.
337
338       Secondly use the option in conjunction with other options to make the
339       regular program output more machine friendly.
340
341       At the moment this means:
342
343       1.  Progress bar messages can be parsed from stdout by looking for this
344           regular expression:
345
346            ^[0-9]+/[0-9]+$
347
348       2.  The calling program should treat messages sent to stdout (except
349           for progress bar messages) as status messages.  They can be logged
350           and/or displayed to the user.
351
352       3.  The calling program should treat messages sent to stderr as error
353           messages.  In addition, virt-sparsify exits with a non-zero status
354           code if there was a fatal error.
355
356       All versions of virt-sparsify have supported the --machine-readable
357       option.
358
359       It is possible to specify a format string for controlling the output;
360       see "ADVANCED MACHINE READABLE OUTPUT" in guestfs(3).
361

WINDOWS 8

363       Windows 8 "fast startup" can prevent virt-sparsify from working.  See
364       "WINDOWS HIBERNATION AND WINDOWS 8 FAST STARTUP" in guestfs(3).
365

ENVIRONMENT VARIABLES

367       TMPDIR
368           Location of the temporary directory used for the potentially large
369           temporary overlay file.
370
371           In virt-sparsify ≥ 1.28, you can override this environment variable
372           using the --tmp option.
373
374           You should ensure there is enough free space in the worst case for
375           a full copy of the source disk (virtual size), or else set $TMPDIR
376           to point to another directory that has enough space.
377
378           This defaults to /tmp.
379
380           Note that if $TMPDIR is a tmpfs (eg. if /tmp is on tmpfs, or if you
381           use "TMPDIR=/dev/shm"), tmpfs defaults to a maximum size of half of
382           physical RAM.  If virt-sparsify exceeds this, it will hang.  The
383           solution is either to use a real disk, or to increase the maximum
384           size of the tmpfs mountpoint, eg:
385
386            mount -o remount,size=10G /tmp
387
388           If you are using the --in-place option, then large amounts of
389           temporary space are not required.
390
391       For other environment variables, see "ENVIRONMENT VARIABLES" in
392       guestfs(3).
393

EXIT STATUS

395       This program returns 0 if the operation completed without errors.
396       (This doesn't necessarily mean that space could be freed up.)
397
398       A non-zero exit code indicates an error.
399
400       If the exit code is 3 and the --in-place option was used, that
401       indicates that discard support is not available in libguestfs, so
402       copying mode must be used instead.
403

SEE ALSO

405       virt-df(1), virt-filesystems(1), virt-resize(1), virt-rescue(1),
406       guestfs(3), guestfish(1), truncate(1), fallocate(1), qemu-img(1),
407       http://libguestfs.org/.
408

AUTHOR

410       Richard W.M. Jones http://people.redhat.com/~rjones/
411
413       Copyright (C) 2011-2023 Red Hat Inc.
414

LICENSE

416       This program is free software; you can redistribute it and/or modify it
417       under the terms of the GNU General Public License as published by the
418       Free Software Foundation; either version 2 of the License, or (at your
419       option) any later version.
420
421       This program is distributed in the hope that it will be useful, but
422       WITHOUT ANY WARRANTY; without even the implied warranty of
423       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
424       General Public License for more details.
425
426       You should have received a copy of the GNU General Public License along
427       with this program; if not, write to the Free Software Foundation, Inc.,
428       51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
429

BUGS

431       To get a list of bugs against libguestfs, use this link:
432       https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Virtualization+Tools
433
434       To report a new bug against libguestfs, use this link:
435       https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=Virtualization+Tools
436
437       When reporting a bug, please supply:
438
439       •   The version of libguestfs.
440
441       •   Where you got libguestfs (eg. which Linux distro, compiled from
442           source, etc)
443
444       •   Describe the bug accurately and give a way to reproduce it.
445
446       •   Run libguestfs-test-tool(1) and paste the complete, unedited output
447           into the bug report.
448
449
450
451guestfs-tools-1.51.6              2023-12-09                  virt-sparsify(1)
Impressum