Moving lvm raw storage from container/lxc to vm/qemu

valankar

New Member
Aug 10, 2023
6
2
3
I have an LXC container with a mountpoint defined in /etc/pve/lxc/101.conf:

Code:
mp0: local-lvm:vm-101-disk-0,mp=/mnt/storage,mountoptions=noatime,size=1500G

In my /etc/pve/storage.cfg, I have:

Code:
lvmthin: local-lvm
        thinpool data
        vgname pve
        content rootdir,images

Is it possible to move this storage to a VM/QEMU harddisk? The idea is I want to replace the LXC with a VM, so need to move the storage.

I'm assuming this is not possible with the UI, as I can detach it from the LXC but not sure how to attach it on the VM. I found this:

https://pve.proxmox.com/wiki/Moving_disk_image_from_one_KVM_machine_to_another

But it seems to be specific to moving storage between VMs, not LXC to VM.

Thanks!
 
I have an LXC container with a mountpoint defined in /etc/pve/lxc/101.conf:

Code:
mp0: local-lvm:vm-101-disk-0,mp=/mnt/storage,mountoptions=noatime,size=1500G

In my /etc/pve/storage.cfg, I have:

Code:
lvmthin: local-lvm
        thinpool data
        vgname pve
        content rootdir,images

Is it possible to move this storage to a VM/QEMU harddisk? The idea is I want to replace the LXC with a VM, so need to move the storage.

I'm assuming this is not possible with the UI, as I can detach it from the LXC but not sure how to attach it on the VM. I found this:

https://pve.proxmox.com/wiki/Moving_disk_image_from_one_KVM_machine_to_another

But it seems to be specific to moving storage between VMs, not LXC to VM.

Thanks!
Hey, not sure if this can be achieved on lvmthin type, on my case i managed to get this going with directory type storage and not lvmthin.

I am referring to PVE 7.4 version here:
So in summary you have the templates for lxc and VMs in /etc/pve/lxc/[lxcid].conf and /etc/pve/qemu-server/[vmid].conf.
On LXC conf file you will have usually mp0,1,etc full path for storage on VM you have usually scsi0,1,etc full path for storage.
On LXC the file type .raw format for storage while the VM has .qcow2 format.
In order to move storage from LXC to VM you need to convert .raw to .qcow2

Full guide here : https://docs.openstack.org/image-guide/convert-images.html

In short you need to do this :

qemu-img convert -f raw -O qcow2 image.img image.qcow2

Once that is done you need to move this new file to the correct path on your storage
Edit your template for VM file (/etc/pve/qemu-server/[vmid].conf) with new storage, you need to add manually same size as initial storage.
After you start the VM you need to mount the new storage and you should have same files as initial one.

PS: You will have an old type of FS and not LVM, if you want it as LVM that is different story.

Always backup all your data before you start playing with this as if you mess-up something along the way you will end up loosing all your data!

This is a "dirty" way in solving this up but it worked for me and I hope this will help you also !

GL!
 
Hello! I would like to revive this and leave additional information for later comers.

I am on PVE 8.0 and was originally trying to run some software installed in lxc container (ID: 207), installed at /opt that has its own (raw) disk. As the software requires additional hardware in later stage and lxc attaching the device doesn't work, I installed a virtual machine (ID: 114) passing through the device and intended to remount 207's disk over to the 114 to save the time and space reinstalling the /opt softwares.

Storage GUI on PVE shows separately the VM Disks and CT Volumes,

Screenshot 2024-08-14 at 6.48.37 PM.png

Screenshot 2024-08-14 at 6.48.22 PM.png

But doing lvs in Terminal shows they are just normal logical volume in one hierarchy,

Code:
root@h0:~# lvs
  LV                              VG  Attr       LSize    Pool Origin        Data%  Meta%  Move Log Cpy%Sync Convert
  ...                                
  vm-114-disk-0                   pve Vwi-a-tz--    4.00m data               14.06                                
  vm-114-disk-1                   pve Vwi-a-tz--   10.00g data               57.41                                
  ...                                
  vm-207-disk-0                   pve Vwi-a-tz--    8.00g data               99.53                                
  vm-207-disk-1                   pve Vwi-a-tz--   40.00g data               87.06                                
  vm-207-disk-2                   pve Vwi-a-tz--   20.00g data               54.46                                
  ...

So I have just remounted the volumes by editing the /etc/pve/qemu-server/114.conf by adding the following lines,

Code:
scsi0: local-lvm:vm-207-disk-1,iothread=1,ro=1,size=40G
scsi1: local-lvm:vm-207-disk-2,iothread=1

And booting up the system, I can already see the disks as /dev/sda and /dev/sdb .

Note: I have tried with adding virtio1 and virtio2 (as VirtIO Block like the installation disk) but that didn't get the VM recognising the disk (in OS as in BIOS).
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!