Creative Commons License

Unless otherwise expressly stated, all original material of whatever nature created by and included in this weblog is licensed under a Creative Commons License.


Moving a KVM guest to another machine

  1. Properly shutdown the guest:
    guest# poweroff
  2. Create an LVM volume of the same size on the new machine:
    newmachine# lvcreate -L 120G -n myguest myvolgroup
  3. Copy the disk from the old machine over to the new one:
    oldmachine# dd if=/dev/vg_foo/lv_bar | ssh newmachine dd of=/dev/volgroup/myguest
  4. Wait for the transfer to complete (on a 100Mbit/s connection it took about 3.5 hours to transfer the 120GB).
  5. Copy /etc/libvirt/qemu/myguest.xml from the old machine over to the new machine and adapt the LVM path for the disk.
  6. Reload the libvirt configuration:
    newmachine# /etc/init.d/libvirt-bin reload
  7. Start up the guest on the new machine:
    newmachine# virsh start myguest

20:02 | Linux | Permalink

Shrinking a LVM root partition

  1. Boot from a helper system and get a root shell (I used the rescue mode of the Debian installer)
  2. Check the filesystem of the partition to resize:
    e2fsck -f /dev/vg_foo/lv_bar
  3. Resize the filesystem (make it a bit smaller than the target size, to have a safety margin when resizing the logical volume):
    resize2fs /dev/vg_foo/lv_bar 180G
  4. Reduce size of the logical volume:
    lvreduce -L 190G /dev/vg_foo/lv_bar
  5. Grow the filesystem to the new size of the logical volume:
    resize2fs /dev/vg_foo/lv_bar
  6. For good measure run another filesystem check:
    e2fsck -f /dev/vg_foo/lv_bar

19:02 | Linux | Permalink