AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Shrink img file12/28/2022 Thoroughly test the new disk image before discarding the old one. See "ADDING REMOTE STORAGE" in guestfish(1). The URI format is compatible with guestfish. The input disk can be a URI, in order to use a remote disk as the source. # virt-resize -expand /dev/sda2 nbd:// outdisk However virt-resize does not know how to resize some filesystems, so you would have to online resize them after booting the guest. If the expanded partition in the image contains a filesystem or LVM PV, then if virt-resize knows how, it will resize the contents, the equivalent of calling a command such as pvresize(8), resize2fs(8), ntfsresize(8), btrfs(8), xfs_growfs(8), or resize.f2fs(8). The following would increase the size of /dev/sda1 by 200M, and expand /dev/sda2 to fill the rest of the available space: # virt-resize -resize /dev/sda1= 200M -expand /dev/sda2 \ "-resize" is the other commonly used option. (In this case, an extra partition is not created at the end of the disk, because there will be no unused space). It expands the named partition within the disk to fill any extra space: # virt-resize -expand /dev/sda2 indisk outdisk More realistically you'd want to expand existing partitions in the disk image by passing extra options (for the full list see the "OPTIONS" section below). If outdisk is smaller, then it will give an error. If outdisk is larger, then an extra, empty partition is created at the end of the disk covering the extra space. This command just copies disk image indisk to disk image outdisk without resizing or changing any existing partitions. The output disk is the one created in the previous step. a device, a file, or a URI to a remote disk). Virt-resize takes two mandatory parameters, the input disk and the output disk (both can be e.g. # virsh vol-create-as poolname newvol 10G 5. Or use virsh(1) vol-create-as to create a libvirt storage volume: # virsh pool-list Or use lvcreate(1) to create a logical volume: # lvcreate -L 10G -n lv_name vg_name ![]() To store the resized disk image in a file, create a file of a suitable size: # rm -f outdisk You have to have space to store the resized output disk. Virt-resize cannot do in-place disk modifications. (This example is a virtual machine with an 8 GB disk which we would like to expand up to 10 GB). Use virt-filesystems(1) to display the current partitions and sizes: # virt-filesystems -long -parts -blkdevs -h -a /dev/vg/lv_guest If the guest is managed by libvirt, you can use virsh dumpxml like this to find the disk image name: # virsh dumpxml guestname | xpath /domain/devices/disk/source the file or device on the host containing the guest’s disk). Virt-resize -expand /dev/sda2 olddisk newdisk.qcow2ĭETAILED USAGE EXPANDING A VIRTUAL MACHINE DISK 1. ![]() This is what you would typically use for Linux guests that use LVM: virt-resize -expand /dev/sda2 -LV-expand /dev/vg_guest/lv_root \Īs in the first example, but the output format will be qcow2 instead of a raw disk: qemu-img create -f qcow2 -o preallocation=metadata newdisk.qcow2 15G Virt-resize -expand /dev/sda2 olddisk newdiskĪs above, but make the /boot partition 200MB bigger, while giving the remaining space to /dev/sda2: virt-resize -resize /dev/sda1= 200M -expand /dev/sda2 \Īs in the first example, but expand a logical volume as the final step. # Note "/dev/sda2" is a partition inside the "olddisk" file. This example takes olddisk and resizes it into newdisk, extending one of the guest’s partitions to fill the extra 5GB of space: virt-filesystems -long -h -all -a olddisk If you are not familiar with the associated tools: virt-filesystems(1) and virt-df(1), we recommend you go and read those manual pages first. Virt-resize should not be used on live virtual machines - for consistent results, shut the virtual machine down before resizing it. Virt-resize cannot resize disk images in-place. Virt-resize is a tool which can resize a virtual machine disk, making it larger or smaller overall, and resizing or deleting any partitions contained within. Virt-resize - Resize a virtual machine disk SYNOPSIS virt-resize ]
0 Comments
Read More
Leave a Reply. |