Moving LVM Volumes Between Hosts Without an Intermediate File
At [Xeriom Networks](http://xeriom.net/) we provide virtual machines for clients to run their applications. Clients quite sensibly start with the smallest VM that meets their needs, then upgrade as they grow. Unfortunately, we can only fit so much disk space in each physical server, so when clients upgrade we sometimes need to move their [LVM](http://en.wikipedia.org/wiki/Logical_Volume_Manager_(Linux)) volumes to another physical server with enough free space for the expanded disk image.
The obvious approach would be to use [dd](http://en.wikipedia.org/wiki/Dd_(Unix)) to copy the volume to a file, [SCP](http://en.wikipedia.org/wiki/Secure_copy) that file to the new server, then dd it back into a volume on the other end. The problem is that some of these volumes are hundreds of gigabytes, and the local disk often doesn't have enough room for the intermediate file. It also just feels messy.
After some investigation, I discovered you can pipe dd's output directly through SSH and into a dd process on the remote end, skipping the intermediate file entirely.
There are two steps:
**1. On the destination host, create a volume large enough for the data:**
```
sudo lvcreate -L 10G -n destination-lvm-volume-name destination-vg-name
```
**2. From the source host, stream the volume across the network:**
```
sudo dd if=/dev/source-vg-name/source-volume-name | ssh -c arcfour -l root host-b 'dd of=/dev/destination-vg-name/destination-lvm-volume-name'
```
That's it. Much easier than I was expecting.
The `-c arcfour` flag selects a fast cipher for SSH, which helps with throughput on large transfers. The main downside compared to SCP is that you don't get a progress bar, so you're largely left guessing when the transfer will finish. If you know a good way to add progress indication to piped transfers like this, I'd love to hear about it.
These posts are LLM-aided. Backbone, original writing, and structure by Craig. Research and editing by Craig + LLM. Proof-reading by Craig.