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

NAME

6       virt-resize - Resize a virtual machine disk
7

SYNOPSIS

9        virt-resize [--resize /dev/sdaN=[+/-]<size>[%]]
10          [--expand /dev/sdaN] [--shrink /dev/sdaN]
11          [--ignore /dev/sdaN] [--delete /dev/sdaN] [...] indisk outdisk
12

DESCRIPTION

14       Virt-resize is a tool which can resize a virtual machine disk, making
15       it larger or smaller overall, and resizing or deleting any partitions
16       contained within.
17
18       Virt-resize cannot resize disk images in-place.  Virt-resize should not
19       be used on live virtual machines - for consistent results, shut the
20       virtual machine down before resizing it.
21
22       If you are not familiar with the associated tools: virt-filesystems(1)
23       and virt-df(1), we recommend you go and read those manual pages first.
24

EXAMPLES

26       Copy "olddisk" to "newdisk", extending one of the guest's partitions to
27       fill the extra 5GB of space.
28
29        truncate -r olddisk newdisk; truncate -s +5G newdisk
30        virt-filesystems --long -h --all -a olddisk
31        # Note "/dev/sda2" is a partition inside the "olddisk" file.
32        virt-resize --expand /dev/sda2 olddisk newdisk
33
34       As above, but make the /boot partition 200MB bigger, while giving the
35       remaining space to /dev/sda2:
36
37        virt-resize --resize /dev/sda1=+200M --expand /dev/sda2 olddisk newdisk
38
39       As above, but the output format will be uncompressed qcow2:
40
41        qemu-img create -f qcow2 newdisk.qcow2 15G
42        virt-resize --expand /dev/sda2 olddisk newdisk.qcow2
43

DETAILED USAGE

45   EXPANDING A VIRTUAL MACHINE DISK
46       1. Shut down the virtual machine
47       2. Locate input disk image
48           Locate the input disk image (ie. the file or device on the host
49           containing the guest's disk).  If the guest is managed by libvirt,
50           you can use "virsh dumpxml" like this to find the disk image name:
51
52            # virsh dumpxml guestname | xpath /domain/devices/disk/source
53            Found 1 nodes:
54            -- NODE --
55            <source dev="/dev/vg/lv_guest" />
56
57       3. Look at current sizing
58           Use virt-filesystems(1) to display the current partitions and
59           sizes:
60
61            # virt-filesystems --long --parts --blkdevs -h -a /dev/vg/lv_guest
62            Name       Type       Size  Parent
63            /dev/sda1  partition  101M  /dev/sda
64            /dev/sda2  partition  7.9G  /dev/sda
65            /dev/sda   device     8.0G  -
66
67           (This example is a virtual machine with an 8 GB disk which we would
68           like to expand up to 10 GB).
69
70       4. Create output disk
71           Virt-resize cannot do in-place disk modifications.  You have to
72           have space to store the resized output disk.
73
74           To store the resized disk image in a file, create a file of a
75           suitable size:
76
77            # rm -f outdisk
78            # truncate -s 10G outdisk
79
80           Or use lvcreate(1) to create a logical volume:
81
82            # lvcreate -L 10G -n lv_name vg_name
83
84           Or use virsh(1) vol-create-as to create a libvirt storage volume:
85
86            # virsh pool-list
87            # virsh vol-create-as poolname newvol 10G
88
89       5. Resize
90           virt-resize takes two mandatory parameters, the input disk (eg.
91           device or file) and the output disk.  The output disk is the one
92           created in the previous step.
93
94            # virt-resize indisk outdisk
95
96           This command just copies disk image "indisk" to disk image
97           "outdisk" without resizing or changing any existing partitions.  If
98           "outdisk" is larger, then an extra, empty partition is created at
99           the end of the disk covering the extra space.  If "outdisk" is
100           smaller, then it will give an error.
101
102           More realistically you'd want to expand existing partitions in the
103           disk image by passing extra options (for the full list see the
104           "OPTIONS" section below).
105
106           "--expand" is the most useful option.  It expands the named
107           partition within the disk to fill any extra space:
108
109            # virt-resize --expand /dev/sda2 indisk outdisk
110
111           (In this case, an extra partition is not created at the end of the
112           disk, because there will be no unused space).
113
114           "--resize" is the other commonly used option.  The following would
115           increase the size of /dev/sda1 by 200M, and expand /dev/sda2 to
116           fill the rest of the available space:
117
118            # virt-resize --resize /dev/sda1=+200M --expand /dev/sda2 \
119                indisk outdisk
120
121           If the expanded partition in the image contains a filesystem or LVM
122           PV, then if virt-resize knows how, it will resize the contents, the
123           equivalent of calling a command such as pvresize(8), resize2fs(8)
124           or ntfsresize(8).  However virt-resize does not know how to resize
125           some filesystems, so you would have to online resize them after
126           booting the guest.
127
128           Other options are covered below.
129
130       6. Test
131           Thoroughly test the new disk image before discarding the old one.
132
133           If you are using libvirt, edit the XML to point at the new disk:
134
135            # virsh edit guestname
136
137           Change <source ...>, see
138           <http://libvirt.org/formatdomain.html#elementsDisks>
139
140           Then start up the domain with the new, resized disk:
141
142            # virsh start guestname
143
144           and check that it still works.  See also the "NOTES" section below
145           for additional information.
146
147       7. Resize LVs etc inside the guest
148           (This can also be done offline using guestfish(1))
149
150           Once the guest has booted you should see the new space available,
151           at least for filesystems that virt-resize knows how to resize, and
152           for PVs.  The user may need to resize LVs inside PVs, and also
153           resize filesystem types that virt-resize does not know how to
154           expand.
155
156   SHRINKING A VIRTUAL MACHINE DISK
157       Shrinking is somewhat more complex than expanding, and only an overview
158       is given here.
159
160       Firstly virt-resize will not attempt to shrink any partition content
161       (PVs, filesystems).  The user has to shrink content before passing the
162       disk image to virt-resize, and virt-resize will check that the content
163       has been shrunk properly.
164
165       (Shrinking can also be done offline using guestfish(1))
166
167       After shrinking PVs and filesystems, shut down the guest, and proceed
168       with steps 3 and 4 above to allocate a new disk image.
169
170       Then run virt-resize with any of the "--shrink" and/or "--resize"
171       options.
172
173   IGNORING OR DELETING PARTITIONS
174       virt-resize also gives a convenient way to ignore or delete partitions
175       when copying from the input disk to the output disk.  Ignoring a
176       partition speeds up the copy where you don't care about the existing
177       contents of a partition.  Deleting a partition removes it completely,
178       but note that it also renumbers any partitions after the one which is
179       deleted, which can leave some guests unbootable.
180
181   QCOW2 AND NON-SPARSE RAW FORMATS
182       If the input disk is in qcow2 format, then you may prefer that the
183       output is in qcow2 format as well.  Alternately, virt-resize can
184       convert the format on the fly.  The output format is simply determined
185       by the format of the empty output container that you provide.  Thus to
186       create qcow2 output, use:
187
188        qemu-img create [-c] -f qcow2 outdisk [size]
189
190       instead of the truncate command (use "-c" for a compressed disk).
191
192       Similarly, to get non-sparse raw output use:
193
194        fallocate -l size outdisk
195
196       (on older systems that don't have the fallocate(1) command use "dd
197       if=/dev/zero of=outdisk bs=1M count=..")
198

OPTIONS

200       --help
201           Display help.
202
203       --version
204           Display version number and exit.
205
206       --resize part=size
207           Resize the named partition (expanding or shrinking it) so that it
208           has the given size.
209
210           "size" can be expressed as an absolute number followed by
211           b/K/M/G/T/P/E to mean bytes, Kilobytes, Megabytes, Gigabytes,
212           Terabytes, Petabytes or Exabytes; or as a percentage of the current
213           size; or as a relative number or percentage.  For example:
214
215            --resize /dev/sda2=10G
216
217            --resize /dev/sda4=90%
218
219            --resize /dev/sda2=+1G
220
221            --resize /dev/sda2=-200M
222
223            --resize /dev/sda1=+128K
224
225            --resize /dev/sda1=+10%
226
227            --resize /dev/sda1=-10%
228
229           You can increase the size of any partition.  Virt-resize will
230           expand the direct content of the partition if it knows how (see
231           "--expand" below).
232
233           You can only decrease the size of partitions that contain
234           filesystems or PVs which have already been shrunk.  Virt-resize
235           will check this has been done before proceeding, or else will print
236           an error (see also "--resize-force").
237
238           You can give this option multiple times.
239
240       --resize-force part=size
241           This is the same as "--resize" except that it will let you decrease
242           the size of any partition.  Generally this means you will lose any
243           data which was at the end of the partition you shrink, but you may
244           not care about that (eg. if shrinking an unused partition, or if
245           you can easily recreate it such as a swap partition).
246
247           See also the "--ignore" option.
248
249       --expand part
250           Expand the named partition so it uses up all extra space (space
251           left over after any other resize changes that you request have been
252           done).
253
254           If virt-resize knows how, it will expand the direct content of the
255           partition.  For example, if the partition is an LVM PV, it will
256           expand the PV to fit (like calling pvresize(8)).  Virt-resize
257           leaves any other content it doesn't know about alone.
258
259           Currently virt-resize can resize:
260
261           ·   ext2, ext3 and ext4 filesystems when they are contained
262               directly inside a partition.
263
264           ·   NTFS filesystems contained directly in a partition, if
265               libguestfs was compiled with support for NTFS.
266
267               The filesystem must have been shut down consistently last time
268               it was used.  Additionally, ntfsresize(8) marks the resized
269               filesystem as requiring a consistency check, so at the first
270               boot after resizing Windows will check the disk.
271
272           ·   LVM PVs (physical volumes).  virt-resize does not usually
273               resize anything inside the PV, but see the "--LV-expand"
274               option.  The user could also resize LVs as desired after boot.
275
276           Note that you cannot use "--expand" and "--shrink" together.
277
278       --shrink part
279           Shrink the named partition until the overall disk image fits in the
280           destination.  The named partition must contain a filesystem or PV
281           which has already been shrunk using another tool (eg. guestfish(1)
282           or other online tools).  Virt-resize will check this and give an
283           error if it has not been done.
284
285           The amount by which the overall disk must be shrunk (after carrying
286           out all other operations requested by the user) is called the
287           "deficit".  For example, a straight copy (assume no other
288           operations) from a 5GB disk image to a 4GB disk image results in a
289           1GB deficit.  In this case, virt-resize would give an error unless
290           the user specified a partition to shrink and that partition had
291           more than a gigabyte of free space.
292
293           Note that you cannot use "--expand" and "--shrink" together.
294
295       --ignore part
296           Ignore the named partition.  Effectively this means the partition
297           is allocated on the destination disk, but the content is not copied
298           across from the source disk.  The content of the partition will be
299           blank (all zero bytes).
300
301           You can give this option multiple times.
302
303       --delete part
304           Delete the named partition.  It would be more accurate to describe
305           this as "don't copy it over", since virt-resize doesn't do in-place
306           changes and the original disk image is left intact.
307
308           Note that when you delete a partition, then anything contained in
309           the partition is also deleted.  Furthermore, this causes any
310           partitions that come after to be renumbered, which can easily make
311           your guest unbootable.
312
313           You can give this option multiple times.
314
315       --LV-expand logvol
316           This takes the logical volume and, as a final step, expands it to
317           fill all the space available in its volume group.  A typical usage,
318           assuming a Linux guest with a single PV "/dev/sda2" and a root
319           device called "/dev/vg_guest/lv_root" would be:
320
321            virt-resize indisk outdisk \
322              --expand /dev/sda2 --LV-expand /dev/vg_guest/lv_root
323
324           This would first expand the partition (and PV), and then expand the
325           root device to fill the extra space in the PV.
326
327           The contents of the LV are also resized if virt-resize knows how to
328           do that.  You can stop virt-resize from trying to expand the
329           content by using the option "--no-expand-content".
330
331           Use virt-filesystems(1) to list the filesystems in the guest.
332
333           You can give this option multiple times, but it doesn't make sense
334           to do this unless the logical volumes you specify are all in
335           different volume groups.
336
337       --no-copy-boot-loader
338           By default, virt-resize copies over some sectors at the start of
339           the disk (up to the beginning of the first partition).  Commonly
340           these sectors contain the Master Boot Record (MBR) and the boot
341           loader, and are required in order for the guest to boot correctly.
342
343           If you specify this flag, then this initial copy is not done.  You
344           may need to reinstall the boot loader in this case.
345
346       --no-extra-partition
347           By default, virt-resize creates an extra partition if there is any
348           extra, unused space after all resizing has happened.  Use this
349           option to prevent the extra partition from being created.  If you
350           do this then the extra space will be inaccessible until you run
351           fdisk, parted, or some other partitioning tool in the guest.
352
353           Note that if the surplus space is smaller than 10 MB, no extra
354           partition will be created.
355
356       --no-expand-content
357           By default, virt-resize will try to expand the direct contents of
358           partitions, if it knows how (see "--expand" option above).
359
360           If you give the "--no-expand-content" option then virt-resize will
361           not attempt this.
362
363       -d | --debug
364           Enable debugging messages.
365
366       -n | --dryrun
367           Print a summary of what would be done, but don't do anything.
368
369       -q | --quiet
370           Don't print the summary.
371
372       --format raw
373           Specify the format of the input disk image.  If this flag is not
374           given then it is auto-detected from the image itself.
375
376           If working with untrusted raw-format guest disk images, you should
377           ensure the format is always specified.
378
379           Note that this option does not affect the output format.  See
380           "QCOW2 AND NON-SPARSE RAW FORMATS".
381
382       --output-format raw
383           Specify the format of the output disk image.  If this flag is not
384           given then it is auto-detected from the image itself.
385
386           If working with untrusted raw-format guest disk images, you should
387           ensure the format is always specified.
388
389           Note that you still need to create the output disk with the right
390           format.  See "QCOW2 AND NON-SPARSE RAW FORMATS".
391

NOTES

393   "Partition 1 does not end on cylinder boundary."
394       Virt-resize aligns partitions to multiples of 64 sectors.  Usually this
395       means the partitions will not be aligned to the ancient CHS geometry.
396       However CHS geometry is meaningless for disks manufactured since the
397       early 1990s, and doubly so for virtual hard drives.  Alignment of
398       partitions to cylinders is not required by any modern operating system.
399
400   RESIZING WINDOWS VIRTUAL MACHINES
401       In Windows Vista and later versions, Microsoft switched to using a
402       separate boot partition.  In these VMs, typically "/dev/sda1" is the
403       boot partition and "/dev/sda2" is the main (C:) drive.  We have not had
404       any luck resizing the boot partition.  Doing so seems to break the
405       guest completely.  However expanding the second partition (ie. C:
406       drive) should work.
407
408       Windows may initiate a lengthy "chkdsk" on first boot after a resize,
409       if NTFS partitions have been expanded.  This is just a safety check and
410       (unless it find errors) is nothing to worry about.
411
412   GUEST BOOT STUCK AT "GRUB"
413       If a Linux guest does not boot after resizing, and the boot is stuck
414       after printing "GRUB" on the console, try reinstalling grub.  This
415       sometimes happens on older (RHEL 5-era) guests, for reasons we don't
416       fully understand, although we think is to do with partition alignment.
417
418        guestfish -i -a newdisk
419        ><fs> cat /boot/grub/device.map
420        # check the contents of this file are sensible or
421        # edit the file if necessary
422        ><fs> grub-install / /dev/vda
423        ><fs> exit
424
425       For more flexible guest reconfiguration, including if you need to
426       specify other parameters to grub-install, use virt-rescue(1).
427

ALTERNATIVE TOOLS

429       There are several proprietary tools for resizing partitions.  We won't
430       mention any here.
431
432       parted(8) and its graphical shell gparted can do some types of resizing
433       operations on disk images.  They can resize and move partitions, but I
434       don't think they can do anything with the contents, and they certainly
435       don't understand LVM.
436
437       guestfish(1) can do everything that virt-resize can do and a lot more,
438       but at a much lower level.  You will probably end up hand-calculating
439       sector offsets, which is something that virt-resize was designed to
440       avoid.  If you want to see the guestfish-equivalent commands that virt-
441       resize runs, use the "--debug" flag.
442

SHELL QUOTING

444       Libvirt guest names can contain arbitrary characters, some of which
445       have meaning to the shell such as "#" and space.  You may need to quote
446       or escape these characters on the command line.  See the shell manual
447       page sh(1) for details.
448

SEE ALSO

450       virt-filesystems(1), virt-df(1), guestfs(3), guestfish(1), lvm(8),
451       pvresize(8), lvresize(8), resize2fs(8), ntfsresize(8), virsh(1),
452       parted(8), truncate(1), fallocate(1), grub(8), grub-install(8),
453       virt-rescue(1), Sys::Guestfs(3), <http://libguestfs.org/>.
454

AUTHOR

456       Richard W.M. Jones <http://people.redhat.com/~rjones/>
457
459       Copyright (C) 2010 Red Hat Inc.
460
461       This program is free software; you can redistribute it and/or modify it
462       under the terms of the GNU General Public License as published by the
463       Free Software Foundation; either version 2 of the License, or (at your
464       option) any later version.
465
466       This program is distributed in the hope that it will be useful, but
467       WITHOUT ANY WARRANTY; without even the implied warranty of
468       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
469       General Public License for more details.
470
471       You should have received a copy of the GNU General Public License along
472       with this program; if not, write to the Free Software Foundation, Inc.,
473       675 Mass Ave, Cambridge, MA 02139, USA.
474
475
476
477libguestfs-1.8.15                 2011-11-10                    virt-resize(1)
Impressum