16.8.2. Expanding a Disk Image
This section demonstrates a simple case of expanding a disk image:
- Locate the disk image to be resized. You can use the command
virsh dumpxml GuestName
for a libvirt guest virtual machine. - Decide on how you wish to expand the guest virtual machine. Run
virt-df -h
andvirt-list-partitions -lh
on the guest virtual machine disk, as shown in the following output:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
This example will demonstrate how to:
- Increase the size of the first (boot) partition, from approximately 100MB to 500MB.
- Increase the total disk size from 8GB to 16GB.
- Expand the second partition to fill the remaining space.
- Expand
/dev/VolGroup00/LogVol00
to fill the new space in the second partition.
- Make sure the guest virtual machine is shut down.
- Rename the original disk as the backup. How you do this depends on the host physical machine storage environment for the original disk. If it is stored as a file, use the
mv
command. For logical volumes (as demonstrated in this example), uselvrename
:lvrename /dev/vg_guests/RHEL6 /dev/vg_guests/RHEL6.backup
# lvrename /dev/vg_guests/RHEL6 /dev/vg_guests/RHEL6.backup
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Create the new disk. The requirements in this example are to expand the total disk size up to 16GB. Since logical volumes are used here, the following command is used:
lvcreate -L 16G -n RHEL6 /dev/vg_guests
# lvcreate -L 16G -n RHEL6 /dev/vg_guests Logical volume "RHEL6" created
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - The requirements from step 2 are expressed by this command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The first two arguments are the input disk and output disk.--resize /dev/sda1=500M
resizes the first partition up to 500MB.--expand /dev/sda2
expands the second partition to fill all remaining space.--LV-expand /dev/VolGroup00/LogVol00
expands the guest virtual machine logical volume to fill the extra space in the second partition.virt-resize
describes what it is doing in the output:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Try to boot the virtual machine. If it works (and after testing it thoroughly) you can delete the backup disk. If it fails, shut down the virtual machine, delete the new disk, and rename the backup disk back to its original name.
- Use
virt-df
orvirt-list-partitions
to show the new size:virt-df -h /dev/vg_pin/RHEL6
# virt-df -h /dev/vg_pin/RHEL6 Filesystem Size Used Available Use% RHEL6:/dev/sda1 484.4M 10.8M 448.6M 3% RHEL6:/dev/VolGroup00/LogVol00 14.3G 2.2G 11.4G 16%
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Resizing guest virtual machines is not an exact science. If
virt-resize
fails, there are a number of tips that you can review and attempt in the virt-resize(1) man page. For some older Red Hat Enterprise Linux guest virtual machines, you may need to pay particular attention to the tip regarding GRUB.