Resizing or shrinking KVM virtual machine filesystems and disk images
2017-08-30 23:06
549 查看
Most everyone wants to increase the size of their disk images, filesystems, or virtual machines (VM). It’s common to create a small, minimal machine (2 GB in size) and increase it depending on the flavor or configuration of the deployed
VM.
However, there are some cases where machines will need to be moved from large disk flavors to smaller flavors. Assuming the filesystem isn’t full or is minimal in size, you may be able to successfully resize the disk image so that it will fit on a smaller VM.
Assumptions
I’m using a trivial example: the deployment is using the ext3 filesystem, no swap partition, and will not require calculations for virtual drive geometry or block size.
I have an 80 GB Fedora 20 installation created as a raw img (virtual machine image) on Linux-based KVM which has already been installed and has the qemu utilities available. The operations, below, were performed on a RedHat Enterprise 6.5 Linux installation.
How to shrink a KVM image filesystem
VM.
However, there are some cases where machines will need to be moved from large disk flavors to smaller flavors. Assuming the filesystem isn’t full or is minimal in size, you may be able to successfully resize the disk image so that it will fit on a smaller VM.
Assumptions
I’m using a trivial example: the deployment is using the ext3 filesystem, no swap partition, and will not require calculations for virtual drive geometry or block size.
I have an 80 GB Fedora 20 installation created as a raw img (virtual machine image) on Linux-based KVM which has already been installed and has the qemu utilities available. The operations, below, were performed on a RedHat Enterprise 6.5 Linux installation.
How to shrink a KVM image filesystem
# cd /var/lib/libvirt/images # ls -al total 189398552 drwxrwxr-x. 2 root root drwxr-xr-x. 10 root root -rw-------. 1 root root 85899345920 Sep 16 09:33 Fedora_20_ext3.img -rw-r--r--. 1 root root 85912715264 Mar 28 14:18 Virtual_Client_for_Linux_Ubuntu_ 12-KVM.qcow2 -rw-rw-r--. 1 root root 9 Mar 28 14:09 Virtual_Client_for_Linux_Ubuntu_12- KVM.qcow2.type -rw-r--r--. 1 root root 32217432064 Aug 28 16:13 Virtual_Client_for_Linux_Windows_ 7-KVM.qcow2 -rw-rw-r--. 1 root root 10 Apr 24 09:43 Virtual_Client_for_Linux_Windows_7- KVM.qcow2.type # qemu-img info Fedora_20_ext3.img image: Fedora_20_ext3.img file format: raw virtual size: 80G (85899345920 bytes) disk size: 80G # virt-df Fedora_20_ext3.img Filesystem 1K-blocks Used Available Use% Fedora_20_ext3.img.bak:/dev/sda1 81642216 3381656 74113360 5% # yum install -y libguestfs-tools # guestfish Welcome to guestfish, the libguestfs filesystem interactive shell for editing virtual machine filesystems. Type: 'help' for help on commands 'man' to read the manual 'quit' to quit the shell ><fs> add Fedora_20_ext3.img ><fs> run 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00 ><fs> list-filesystems /dev/sda1: ext3 ><fs> e2fsck-f /dev/sda1 ><fs> resize2fs-size /dev/sda1 28G ><fs> list-filesystems /dev/sda1: ext3 ><fs> e2fsck-f /dev/sda1 ><fs> quit # qemu-img info Fedora_20_ext3.img image: Fedora_20_ext3.img file format: raw virtual size: 80G (85899345920 bytes) disk size: 80G # virt-df Fedora_20_ext3.img Filesystem 1K-blocks Used Available Use% Fedora_20_ext3.img:/dev/sda1 28899452 3369560 24061888 12% # qemu-img resize Fedora_20_ext3.img 30G Image resized. # qemu-img info Fedora_20_ext3.img image: Fedora_20_ext3.img file format: raw virtual size: 30G (32212254720 bytes) disk size: 30G
原文地址:http://www.mischiefblog.com/2014/09/16/resize-shrink-kvm-img-qcow2-virtual-machine-filesystem-disk-image/
相关文章推荐
- How to cleanup and shrink disk space usage of a Windows KVM virtual machine
- Renaming a virtual machine disk (VMDK) via the vSphere Management Assistant (vMA) or vSphere CLI (vC
- One of the disks in this virtual machine is already in use by a virtual machine or by a snapshot"
- Increasing virtual disk file partition size with DISKPART or GPartEd (较实用的方法)
- Antivirus and Hyper-V (or: Why can’t I start my virtual machine?)
- Best Practices of Resizing Windows Virtual Machine Disks on VMWARE ESX Server 3
- SharePoint Designer Check In and Check Out Error – Cannot perform this operation.The file is no longer check out or has been del
- vmware:Cannot open the disk 'XXX' or one of the snapshot disks it depends on. reason: failed to lock the file.
- Csharp: Create Excel Workbook or word from a Template File using aspose.Word 14.5 and aspose.Cell 8.1
- Install and use CentOS 7 or RHEL 7 as KVM virtualization host
- A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found after searching the following locations: /usr/local/eclipse/
- [Windows Azure] Virtual Machine and Cloud Service Sizes for Windows Azure
- Capture a Debug Log or Trace File and Diagnostics for AutoInvoice
- How to add, modify, or delete registry subkeys and values by using a registration entries (.reg) file
- Virtual machine online disk snapshots coming to Fedora 18
- JVM - Concept and Lifetime (From book "Inside the Java Virtual Machine")
- Cluster Technology and File Systems
- OCR File and Voting Disk Administration by Example - (Oracle 10g)
- Common Tasks :Powering Off or Suspending a Virtual Machine
- cannot write file to virtual machine aborting the file copy operation.