Cloning a thin volume is as simple as taking a snapshot of the to-be-cloned volume. When using thin volumes, snapshot and new volumes really are the same thing, with different default flags.

From the kernel docs:

Once created, the user doesn't have to worry about any connection between the origin and the snapshot. Indeed the snapshot is no different from any other thinly-provisioned device and can be snapshotted itself via the same method. It's perfectly legal to have only one of them active, and there's no ordering requirement on activating or removing them both. (This differs from conventional device-mapper snapshots.)

So it is perfectly legal to snapshot a thinly-provisioned volume to create a CoW clone. From the man page:

Example
       Create first snapshot of an existing ThinLV:
       # lvcreate -n thin1s1 -s vg/thin1
Answer from shodanshok on serverfault.com
🌐
Proxmox
forum.proxmox.com › home › forums › proxmox virtual environment › proxmox ve: installation and configuration
Cloning and recovery problems on LVM-thin | Proxmox Support Forum
May 29, 2020 - I use LVM-thin as the main storage and have repeatedly noticed that cloning VMs or recovering using proxmox often means that the VM is broken if LVM-thin is used as the target storage.
🌐
Quantum
quantum5.ca › 2024 › 02 › 17 › cloning-proxmix-with-lvm-thin-pools
Cloning Proxmox with LVM Thin Pools | Quantum
February 18, 2024 - You would think that for a tool that purports to understand filesystems and copy intelligently, it would understand LVM, but you would also be wrong. No, it just happily spent the next half hour copying the LVM partition as a raw image. Then, 464 GiB in, it failed with ENOSPC (i.e. no space left on device). Shocking. Well, with Clonezilla failing, what else is left to do?
Discussions

Clonezilla / Discussion / Clonezilla live: Clonezilla and LVM2
It may be helpful to clarify how the current Clonezilla version handles LVM2 in general (supported and unsupported LVM setup scenarios), especially where there are some regular volumes as well as a thin pool inside the same volume group. As a feature request, the following idea might be senseful for a future version: Consider LVMs as a container of sub hard drives. So a outer ... loop should run. On every LV try ... More on sourceforge.net
🌐 sourceforge.net
June 10, 2024
Clonezilla / Discussion / Open Discussion: How to restore disk with thin-lvm volumes?
Consider using option --force to ... pve with thin volumes. Restore failed. I did the backup with dd, hoping that a block-for-block copy would go trought, but it does not. Any idea how could I solve this? If you would like to refer to this comment somewhere else in this project, copy and paste the following link: ... Due to some technical issue, Clonezilla does not support LVM thin provisioning ... More on sourceforge.net
🌐 sourceforge.net
Shrinking Proxmox Data LVM for Cloning to Slightly Smaller Disk?
What did you google for? Coz when I type in "reduce size of lvm position" I get several step by step guides... More on reddit.com
🌐 r/Proxmox
2
1
November 4, 2023
thin lvm | Proxmox Support Forum
I setup a single 120GB SSD non-UEFI computer with the storage defaults (Not ZFS). I customized a great many things and then used a HDD duplicator to clone to a 250GB destination disk. To my surprise the cloned... ... Hi ! Proxmox is great and i'm pretty new with this mix of technologies. LVM is ... More on forum.proxmox.com
🌐 forum.proxmox.com
🌐
GitHub
github.com › harvester › harvester › issues › 11781
[ENHANCEMENT] LVM CSI: use dm-thin snapshots for same-pool PVC clones · Issue #11781 · harvester/harvester
2 days ago - A cross-pool clone also silently falls back to copying the full source volume, which is not desired for the dm-thin-only design. For CSI PVC-to-PVC cloning (VolumeContentSource.Volume): Support dm-thin sources and destinations only. When source and destination use the same thin pool, create the destination as an LVM dm-thin snapshot of the source. When they do not use the same thin pool, reject CreateVolume with a clear error.
Author: harvester
🌐
SourceForge
sourceforge.net › home › browse › clonezilla › bugs
Clonezilla / Bugs / #330 LVM thin volumes aren't detected and causing errors
September 13, 2019 - If you use dd to process the whole disk, of course you do not care about the file system. ... If you would like to refer to this comment somewhere else in this project, copy and paste the following link: ... Clonezilla does have some issue to process LVM thin provisioning...
🌐
SourceForge
sourceforge.net › home › browse › clonezilla › discussion
Clonezilla / Discussion / Clonezilla live: Clonezilla and LVM2
June 10, 2024 - I have used option -k0 to keep the same partition size, and I double-checked and made sure the option "-r" in the advance options was not selected, is there any other option I can try to see if it fix the issue? ... If you would like to refer to this comment somewhere else in this project, copy and paste the following link: ... LVM thin provisioning is not supported ATM, as mentioned here: https://sourceforge.net/p/clonezilla/discussion/Open_discussion/thread/6a5322bf85/
🌐
SourceForge
sourceforge.net › home › browse › clonezilla › discussion
Clonezilla / Discussion / Open Discussion: How to restore disk with thin-lvm volumes?
I did the backup with dd, hoping ... somewhere else in this project, copy and paste the following link: ... Due to some technical issue, Clonezilla does not support LVM thin provisioning at the moment....
Top answer
1 of 4
3

Cloning a thin volume is as simple as taking a snapshot of the to-be-cloned volume. When using thin volumes, snapshot and new volumes really are the same thing, with different default flags.

From the kernel docs:

Once created, the user doesn't have to worry about any connection between the origin and the snapshot. Indeed the snapshot is no different from any other thinly-provisioned device and can be snapshotted itself via the same method. It's perfectly legal to have only one of them active, and there's no ordering requirement on activating or removing them both. (This differs from conventional device-mapper snapshots.)

So it is perfectly legal to snapshot a thinly-provisioned volume to create a CoW clone. From the man page:

Example
       Create first snapshot of an existing ThinLV:
       # lvcreate -n thin1s1 -s vg/thin1
2 of 4
2

I believe this hasn't been correctly answered (yet) because the OP appears to be indicating two different volume groups, a source and a destination. So I'll try to answer it.

Note: This response assumes that a reference like /dev/mapper/vg_thin02 indicates a volume group in accordance with the usual Linux convention, and that any pool or thin volume in that group would be followed by a dash like so: /dev/mapper/vg_thin02-volA.

When cloning between two volume groups (or two thin pools) on the same machine, for each source volume do:

fstrim /mnt/volA
umount /mnt/volA
lvcreate -kn -ay -V sizeofvolA -T vg_thin02/poolname -n volA
dd if=/dev/mapper/vg_thin01-volA of=/dev/mapper/vg_thin02-volA conv=sparse

Continue with "volB", "volC", etc. as necessary. The conv=sparse argument stores the new copy in a sparse, thin-provisioned way.

The fstrim and umount lines show that some form of trim/discard is necessary on the source volume before it is taken offline and duplicated. If the volume is normally mounted with the discard option this may not be necessary.

For cloning between two different machines, you can use ssh on the source machine in conjunction with dd on the destination:

gzip -2 </dev/mapper/vg_thin01-volA | ssh user@address "zcat | sudo dd of=/dev/mapper/vg_thin02-volA conv=sparse"
🌐
Proxmox VE
pve.proxmox.com › wiki › Storage:_LVM_Thin
Storage: LVM Thin - Proxmox VE
LVM thin is a block storage, but fully supports snapshots and clones efficiently.
Find elsewhere
Top answer
1 of 4
5

Closing this issue, after a year. I have written the answer in my personal website. I hope it is useful to somebody else.

I use several levels of backup, from rsync to an external disk to rsync+ZFS over a remote computer. One of the backups I do is a -from time to time- "dd" from my laptop harddisk to an external USB attached (connected only for the duration of the backup procedure). I do this, for instance, before taking my laptop for a trip.

This procedure worked well for ages. Until I started using LVM on my laptop.

If you use LVM on your computer, you copy your harddisk using dd (booting from a LiveCD) and you plug the external harddisk while the computer is running normally, later, YOU WILL CORRUPT YOUR DATA, EVEN LOSE ALL YOUR FILESYSTEM BEYOND ANY REPAIR!!!.

Why?. Because when you plug the external harddisk the OS will see the same LVM configuration in both disks and will naively assume that both disks are the same, accessible via a multipath link, so it will spread reads and writes between both disks, irredeemably corrupting BOTH. You will trash both your live data and your backup!.

This happened to me once. I lost data. I had other backups, for a few days before, so I didn't lose anything very important, but it was quite annoying and exposed a flaw in my backup strategy.

Solution: Make sure the LVM configuration in the backup disk is different. The problem is... How to do it?

I posted the question on superuser.com (Stack Exchange) but I didn't get any good answer. So I developed my own procedure and, after more than a year of battletesting it, I am posting it here and closing the original question:

  • Be sure that if something goes bad, your computer will not boot automatically. In my case, my laptop doesn't boot automatically if the power goes off and on again. Moreover, the harddisk is encrypted, so it will ask for a password.

    This is necessary because you can corrupt BOTH disks if you reboot with the backup disk attached before completing the procedure.

  • Boot from a Live CD. You can not do a "dd" from a live partition, if you expect to be able to recover your data :-).

    Something to try in the future would be to use LVM snapshots to be able to do the backup while I am using the computer, but then I have the duplicate LVM issue, that I am trying to avoid here. Another option would be to reconfigure LVM to mirror the data live to the external harddisk, and break the mirror after the sync is complete. But that sounds risky, and wouldn't backup my Windows partition or the data I don't keep in LVM volumes.

  • After booting the LiveCD, plug the external USB harddisk.

  • Login as "root" and execute vgchange -a n. This command will disable LVM in both disks. I execute the command a couple of times, to be sure.

  • Be sure /dev/sda is the source (internal harddisk) and /dev/sdb is the destination (USB external harddisk). For instance, do dd if=/dev/sdb of=/dev/null and check which harddisk LED blinks.

  • When you are sure about which disk is which, you do the copy with dd if=/dev/sda of=/dev/sdb bs=65536. With my configuration, the backup takes four hours. My internal harddisk is 500GB, and my USB is copying at 35MB/s. I do this at night, while I sleep.

    Your external USB harddisk must be, AT LEAST, as big as your internal harddisk. It is obvious, isn't it?

  • After this copy is done, you have an exact clone of your internal harddisk. The backup is done. But now you will have an issue if you ever plug this harddisk to your computer while you are working with your internal harddisk, as already described. We need to change the LVM configuration.

  • Now, after the "dd" is done, do "sync" and unplug the external UDB harddisk.

  • You execute pvchange --uuid /dev/sda*. This command will change the UUID of all the physical volumes in your internal harddisk. This command is safe even if you have partitions that are not physical volumes for LVM, because they will be automatically and safely skipped.

    The system knows which partitions are physical volumes because the partition type and because you executed "pvcreate" when you created the LVM.

  • You execute vgchange -u LVM. This command will change the UUID of the LVM volume group. My volume group is called "LVM", by the way.

  • You execute vgscan. This command will scan internal harddisk (the only currently attached) and will locate your LVM volume group there.

  • You execute vgrename LVM LVM2, to change the name of your Volume Group.

  • Now you plug your external USB harddisk.

  • You "vgscan" again, this time to locate the Volume Group in the external USB harddisk. Now you will have two Volume Groups. One called "LVM2" in your internal harddisk and other called "LVM" in your USB external harddisk.

  • Rename the Volume Group in the external USB harddisk with vgrename LVM LVM_BACKUP.

  • And rename the Volume Group in the internal harddisk back to the original name: vgrename LVM2 LVM.

  • You are done. You can review the situation with vgdisplay -v.

    You will see that Logical Volumes UUIDs are the same in both Volume Groups, but that doesn't seem to cause any problem, and I don't know how to change them.

  • Unplug your external USB harddisk, store it in a safe place, reboot your computer, eject the LiveCD and go back to business.

2 of 4
4

I agree with one of the previous answers -- running dd on the whole disk is not a great solution here. If the reason you're stuck on dd has to do with backing up another OS, then you can use dd only for those other OS partitions, and rsync for the linux partitions.

Part of the problem is that if you run dd of the whole disk while you have filesystems up and mounted from it, there is no way to ensure the backup is consistent. It may work 9 times out of 10, but under any load, the resultant backup could be corrupted. The only way to ensure this doesn't happen is to unmount all filesystems and deactivate all volume groups for the entire time that the dd is running. Not very convenient if your / is mounted from LVM.

In any event, if you insist on sticking with this approach, the tool you're looking for to rename a duplicated vg is called "vgimportclone". It's intended for use with device level snapshots, but it will work with dd as well.

🌐
Reddit
reddit.com › r/proxmox › shrinking proxmox data lvm for cloning to slightly smaller disk?
r/Proxmox on Reddit: Shrinking Proxmox Data LVM for Cloning to Slightly Smaller Disk?
November 4, 2023 -

Hi community,

I switch from ESXi a few months ago and I have been loving proxmox! Hoping the community can provide some guidance as my Google-fu doesn't seem to be yielding many results.

Scenario:

I currently have a 512 GB SSD installed and I want to replace it with a 500 GB NVME drive due to physical space issues. Trying to clone with clonezilla is of course resulting in errors as the NVME drive I would be trying to clone to is smaller than the source disk.

Goal/Objective:

I am only utilizing approximately 50% of my lvm-thin. Is it possible to shrink it by about 20GB? At that point I would imagine I could clone the drive.

Another option. I have my VMs backed up to a NFS share. The VMs originate on the lvm-thin data volume as well. Should I just blow the LVM-thin away (with the vms) then shrink the drive, clone it, then make a new LVM-thin on the new NVME drive to take up the whole space and restore from backups?

Not sure which approach is best. My main objective is just so I do not have to reconfigure proxmox from scratch again. Any insight or suggestions are appreciated.

Some outputs in case they are useful to anyone:

root@pve:~# lsblk
NAME                         MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda                            8:0    0 476.9G  0 disk 
├─sda1                         8:1    0  1007K  0 part 
├─sda2                         8:2    0   512M  0 part /boot/efi
└─sda3                         8:3    0 476.4G  0 part 
  ├─pve-swap                 253:0    0     8G  0 lvm  [SWAP]
  ├─pve-root                 253:1    0    96G  0 lvm  /
  ├─pve-data_tmeta           253:2    0   3.6G  0 lvm  
  │ └─pve-data-tpool         253:4    0 349.3G  0 lvm  
  │   ├─pve-data             253:5    0 349.3G  1 lvm  
  │   ├─pve-vm--100--disk--0 253:6    0    10G  0 lvm  
  │   ├─pve-vm--101--disk--0 253:7    0   150G  0 lvm  
  │   ├─pve-vm--102--disk--0 253:8    0    25G  0 lvm  
  │   └─pve-vm--103--disk--0 253:9    0    10G  0 lvm  
  └─pve-data_tdata           253:3    0 349.3G  0 lvm  
    └─pve-data-tpool         253:4    0 349.3G  0 lvm  
      ├─pve-data             253:5    0 349.3G  1 lvm  
      ├─pve-vm--100--disk--0 253:6    0    10G  0 lvm  
      ├─pve-vm--101--disk--0 253:7    0   150G  0 lvm  
      ├─pve-vm--102--disk--0 253:8    0    25G  0 lvm  
      └─pve-vm--103--disk--0 253:9    0    10G  0 lvm  
root@pve:~# lvs
  LV            VG  Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  data          pve twi-aotz-- <349.31g             48.49  2.04                            
  root          pve -wi-ao----   96.00g                                                    
  swap          pve -wi-ao----    8.00g                                                    
  vm-100-disk-0 pve Vwi-aotz--   10.00g data        81.15                                  
  vm-101-disk-0 pve Vwi-aotz--  150.00g data        87.26                                  
  vm-102-disk-0 pve Vwi-a-tz--   25.00g data        88.71                                  
  vm-103-disk-0 pve Vwi-aotz--   10.00g data        81.95 
oot@pve:~# vgs
  VG  #PV #LV #SN Attr   VSize    VFree  
  pve   1   7   0 wz--n- <476.44g <16.00g
root@pve:~# pvs
  PV         VG  Fmt  Attr PSize    PFree  
  /dev/sda3  pve lvm2 a--  <476.44g <16.00g
🌐
Proxmox
forum.proxmox.com › home › tags
thin lvm | Proxmox Support Forum
I setup a single 120GB SSD non-UEFI computer with the storage defaults (Not ZFS). I customized a great many things and then used a HDD duplicator to clone to a 250GB destination disk. To my surprise the cloned... ... Hi ! Proxmox is great and i'm pretty new with this mix of technologies. LVM is extremely powerful and i need to deal with it to increase , wisely , a thin pool without breaking anything.
🌐
Red Hat
bugzilla.redhat.com › show_bug.cgi
1825147 – Creation of thin-clone LUNs leads to lvm problems on the hypervisor
Red Hat Bugzilla – 1825147 – Creation of thin-clone LUNs leads to lvm problems on the hypervisor ... Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
🌐
Proxmox
forum.proxmox.com › home › forums › proxmox virtual environment › proxmox ve: installation and configuration
lvm-thin on SSD stalls/fails clone or create | Proxmox Support Forum
April 14, 2022 - ... i always get problem with adding disk and the solution quite easy is to just boot over a partition manager soft and create lvm there. Then reboot and hop all detect in prox. ... i always get problem with adding disk and the solution quite ...
🌐
SourceForge
sourceforge.net › home › browse › clonezilla › discussion
Clonezilla / Discussion / Open Discussion: LVM Clone Problem - LVM Volume Setting Not Found
August 8, 2013 - Dear all, I have uploaded some versions of Clonezilla live to address this issue: 20150731-wily 20150731-vivid and 2.4.2-29 You can find them on http://clonezilla.org/downloads.php These releases all include the above patches. If you can, please give that a try and let me know the results. Thanks. ... If you would like to refer to this comment somewhere else in this project, copy and paste the following link: Andrzej .. - 2015-08-03 · I have checked 20150731-vivid version for LVM compatibility (backup and restore) and must admit - works great.
🌐
GitHub
github.com › lxc › lxc › issues › 807
lxc-clone on top of LVM thin provisioning + XFS doesn't quite work · Issue #807 · lxc/lxc
February 7, 2016 - In fact the cloned container is fine. However, to start it I need to: lvchange -kn /dev/data/cloname -- because thin provisioned LVs are skip-autostart by default · lvchange -ay /dev/data/cloname -- because the LV doesn't get activated due to skip-autostart
Author: lxc
🌐
Proxmox
forum.proxmox.com › home › forums › proxmox virtual environment › proxmox ve: installation and configuration
Not able to clone VM to LVM-Thin | Proxmox Support Forum
June 10, 2020 - Dear friends, I am having some trouble while cloning VM to LVM-Thin, but able to place disk image in LVM-Thin. Please share your experience with me in regards to a similar encounter. Proxmox Version: 6.2-4 Error: UPID:dr01:00000B65:0000ECEE:5EE0A528:qmclone:1000:root@pam: 1 5EE0A6E4 clone failed: command '/sbin/lvs --separator : --noheadings --units b --unbuffered --nosuffix --options lv_size /dev/pve/vm-400-disk-0' failed: got timeout LVM-Thin Capacity 1.7TB Hardware: DELL PowerEdge R710 (16 Cores, 64GB RAM) Drive Type: RAID5 500GB x 6 Units + 1spare
🌐
Proxmox
forum.proxmox.com › home › forums › proxmox virtual environment › proxmox ve: installation and configuration
[SOLVED] - Problem in creating template and cloning with an LVM VG | Proxmox Support Forum
March 25, 2020 - Click to expand... and it's only possible create a full clone. Is there anything I'm missing here? ... Regular LVM does not support thin clones - only full ones.
🌐
Proxmox VE
pve.proxmox.com › wiki › VM_Templates_and_Clones
VM Templates and Clones - Proxmox VE
January 31, 2018 - Linked Clones works for theses storages: files in raw, qcow2, vmdk format (either on local storage or nfs); LVM-thin, ZFS, rbd, sheepdog, nexenta.