You are hereBlogs / Matt's blog / Copying a Virtual Machine lv or Partition Over SSH

Copying a Virtual Machine lv or Partition Over SSH


By Matt - Posted on 20 February 2010

Copying a Logical Volume or Partition over SSH

This should only be attempted on either a snapshot lvm volume, or an unmounted hard drive partition!

Using ssh and dd you can copy any LVM or (unmounted) hard drive partition over the internet to a new machine easily.  You can do a "push" or "pull" copy.  Here's a "push" copy:

dd if=/dev/vg0/partition-snapshot bs=1k |
   ssh remotehost dd of=/dev/vg0/partition-destination bs=1k

Or, if you want to "pull" the partition from a remote host to the destination machine:

ssh remotehost dd if=/dev/vg0/partition-snapshot bs=1k |
   dd of=/dev/vg0/partition-destination bs=1k

If you want to monitor progress, you can open another terminal on the same machine and run something like

watch -n 5 "killall -USR1 dd"

This will cause dd to output informative data every 5 seconds on the terminal where the copying is going on.

Making a LVM Snapshot

Making a snapshot is not as straightforward as it should be on LVM2.  Here's how I do it using an imaginary logical volume called "partition" in a volume group called "vg0."  First create a partition to hold the snapshot that is the same size as the live partition.

lvcreate -n partition-snapshot -L 10g vg0

lvconvert -s vg0/partition vg0/partition-snapshot

When you're done with it, you can deactivate it with

lvremove vg0/partition-snapshot

Create Live Bookmark

Syndicate content

Recent comments

Latest images