How do I restore or recreate a CT using an exisitng subvol (on ZFS)?

Aug 17, 2020
23
1
8
89
After doing something very stupid that looks like it may have destroyed my install, it looks like I might have to do a fresh install and create my containers from scratch.

I still have the ZFS dataset subvols for the containers from my old, borked Proxmox install (as they were stored on a separate disk) but after looking through the GUI, the docs, and searching online... I can't find / figure out how I can recreate or restore an LXC container and use an existing subvol.

One possible method I have read about involves creating a new CT with an id number different to the subvol you want to reuse, and then you do a zfs rename of the newly created CTs subvol, and then the original subvol, so that the original subvol uses the ID number of the new CT. I haven't been able to test it out but... would that really work?!

Could someone please point me in the right direction?
 
Is it the root disk of the container or a separate mountpoint?

If it is a separate mountpoint, you could create a new container with the same VMID and then run pct rescan to scan for volumes. Proxmox VE should find it and add it as "unsued" volume to the container which you then can edit and add.

If it is the root volume of the container, things might be a bit trickier. You could go ahead, create a new container and then manually remove that newly create root volume and do a rename on the old one to match the one you just deleted.

Ideally, create a clone of something like it to have a good copy on the side, in case things go wrong.
 
Hi !
How can I create a CT with the same VMID ?
In fact, when I remove a CT, proxmox also removes others mountpoints.
So after "remove CT", pct rescan scans nothing.

I have a new template and I want to install it on an existing CT while keeping data.
Is i possible natively ?

Thanks
 
Is it the root disk of the container or a separate mountpoint?

If it is a separate mountpoint, you could create a new container with the same VMID and then run pct rescan to scan for volumes. Proxmox VE should find it and add it as "unsued" volume to the container which you then can edit and add.

If it is the root volume of the container, things might be a bit trickier. You could go ahead, create a new container and then manually remove that newly create root volume and do a rename on the old one to match the one you just deleted.

Ideally, create a clone of something like it to have a good copy on the side, in case things go wrong.
It's the root disk.


FYI, the old subvols that I want to restore are on "nvme-pool", and my new container subvols are in "rpool/data".

I have just tried the following procedure-

  1. I used syncoid to send | recv subvol-101-disk-0 from "nvme-pool" to "rpool/data".
  2. I renamed the "rpool/data/subvol-101-disk-0" to "rpool/data/subvol-101-disk-0.old" using zfs rename.
  3. I then created a new container with an ID of 101 but I didn't start it.
  4. Creating the container created a new "rpool/data/subvol-101-disk-0". So I used zfs rename again to name it ""rpool/data/subvol-101-disk-0.new" and renamed "rpool/data/subvol-101-disk-0.old" to ""rpool/data/subvol-101-disk-0".
  5. I then booted the container, in this case a Nextcloud container.
When I went to the IP of the container, the Nextcloud splash screen was there, saying something along the lines of not being able to log in, please contact the administrator.

So it looks like a promising start.

Tomorrow, when I have some more time, I'm going to recreate my lxc.idmap's and bind mounts, and see if I have any luck.

I'll post an update soon.
 
  • Like
Reactions: aaron
Hi !
How can I create a CT with the same VMID ?
In fact, when I remove a CT, proxmox also removes others mountpoints.
So after "remove CT", pct rescan scans nothing.

I have a new template and I want to install it on an existing CT while keeping data.
Is i possible natively ?

Thanks
Please open a new thread for your own, separate, questions!
 
I don't know if its a good solution, but it prevent proxmox from deleting subvolume.
When you create a CT, detach volume, make zfs rename of the volume, remove volume from CT from GUI, rename back the volume,then attach the volume from console without : sign as for zfs
pct set 110 -mp0 rpool/subvol-110-disk-1,mp=/mnt/data,size=2000G
After this, volume will not be deleted on remove or on restore.
Just one small thing, when you do restore it will create disk-2, just detach,remove and then go to console and pct set disk-1 manually.
 

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!