How can a LVM thin volume be saved to a sparse file and then restored as a thin volume without making it "thick" ?

shodan

Active Member
Sep 1, 2022
219
61
33
I am searching for a filesystem agnostic method of taking any thin LVM volume, turning it into a file, copying that file to another system and then restoring a still-sparse LVM thin volume

Here are some suggestion I have found but not tried

Code:
rsync --sparse --progress /dev/pve/vm-600-disk-0 /root/vm-600-sparse.img
rsync --sparse /root/vm-600-sparse.img /dev/pve/vm-600-disk-0

dd if=/dev/pve/vm-600-disk-0 bs=1M status=progress | cp --sparse=always /dev/stdin /root/vm-600-sparse.img
cp --sparse=always /root/vm-600-sparse.img /dev/pve/vm-600-disk-0

qemu-img convert -O raw -p /dev/pve/vm-600-disk-0 /root/vm-600-sparse.img
dd if=/root/vm-600-sparse.img of=/dev/pve/vm-600-disk-0 bs=1M status=progress

I don't know if any of these would work or if there's another, better way to do this ?
 
I think you're trying to do this a too low-level. Why not make a backup of the VM with native proxmox tools, and restore it?

Barring that, you could backup in-vm to somewhere, recreate the thin disk / volume on another host, and in-vm restore...
 
  • Like
Reactions: leesteken
In this case this computer is borked, I'd like to know how to do it in low lever, so that it is filesystem-agnostic, would work regardless if it's a single filesystem of a whole partition table, not have to know what partition table format it is or how to recreate it.

And this method would work on anything that uses LVM not just promox.

Is it not possible at all to create a sparse file from a thin LVM volume and then recreate this volume exactly elsewhere ?

Barring that, how about creating a "thick" image file, compress it, write it down into a thin volume and somehow "re-sparsify" the thin volume ?
 
dd conv=sparse if=/dev/lvm/your-part of=sparsefile.dd.img should work (and vice versa on the other end) provided your filesystem supports sparse files. The restore may not initially be thin, but just run the zerofree or fstrim command from guest to re-thin it.
 
Last edited: