{{tag>[kvm lvm]}} =====KVM shrink nested LVM===== **Note! Backup your data first!** * Remove content in VM. Free some space, reduce filesystems, logical volumes etc. For example reduce home directory. # log in as root via serial, or via SSH. umount /home fsck /dev/mapper/VolGroup-lv_home lvresize --resizefs -L1G /dev/mapper/VolGroup-lv_home mount /home * If you need to reduce the rootfs, boot from network, usb or cd/dvd. Then resize the filesystem. For example, edit guest to boot from systemrescuecd. lvresize -r -L8G /dev/VolGroup/lv_root * Shrink physical volume. First move LV's to beginning. pvdisplay -m pvmove -v /dev/vda2:2296-2551 /dev/vda2:0-255 --alloc anywhere pvmove -v /dev/vda2:2552-2799 /dev/vda2:256-503 --alloc anywhere pvmove -v /dev/vda2:10428-12475 /dev/vda2:504-2551 --alloc anywhere pvresize -v --setphysicalvolumesize 16G /dev/vda2 * On the KVM host, reduce the LV. lvresize -L16G /dev/vg_kvm1/vmns2 * On the guest force fsck check at next boot, and reboot. touch /forcefsck reboot ====Boot guest from systemrescuecd iso==== * Add cdrom device. virsh edit vmns2
* Boot from cdrom first. hvm * Boot VM and reduce rootfs. When finished, remove the cdrom device and boot device. ====Auto expand root fs from initrd==== * See: [[https://github.com/flegmatik/linux-rootfs-resize]] cd /opt rpm -ivh http://ftp-stud.hs-esslingen.de/pub/epel/6/i386/epel-release-6-8.noarch.rpm yum install git parted cloud-utils git clone https://github.com/flegmatik/linux-rootfs-resize.git cd linux-rootfs-resize ./install