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.comClonezilla / Discussion / Clonezilla live: Clonezilla and LVM2
Clonezilla / Discussion / Open Discussion: How to restore disk with thin-lvm volumes?
Shrinking Proxmox Data LVM for Cloning to Slightly Smaller Disk?
thin lvm | Proxmox Support Forum
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
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"
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/sdais the source (internal harddisk) and/dev/sdbis the destination (USB external harddisk). For instance, dodd if=/dev/sdb of=/dev/nulland 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.
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.
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
I need to clone a disk with a LVM onto a larger disk. I have dd'ed the entire disk onto the new disk - but once I try to boot it, it will not as the id's do not match. Now how can I fix this?
is dd the right way to clone the entire disk?