LXC to KVM

Pandry

Active Member
Jun 30, 2016
5
0
41
Hi, I would know if is possible to convert a LXC Container to a KVM Virtual Machine.
 
With linux, everything is possible :-D

There is no automatic solution for this, but it should go as follows:
  • boot live linux inside KVM
  • create partition layout, filesystem(s)
  • rsync stuff
  • chroot into new environment
  • install kernel
  • install and configure boot loader
  • Adapt fstab
  • reboot and hope everything works
Depending on the linux distribution, there could be other steps, filesystems, commands, tools necessary.
 
  • Like
Reactions: aasami and Andrii
With linux, everything is possible :-D

There is no automatic solution for this, but it should go as follows:
  • boot live linux inside KVM
  • create partition layout, filesystem(s)
  • rsync stuff
  • chroot into new environment
  • install kernel
  • install and configure boot loader
  • Adapt fstab
  • reboot and hope everything works
Depending on the linux distribution, there could be other steps, filesystems, commands, tools necessary.
Thanks for this. Very usefull!
 
  • Like
Reactions: Andrii
Did you succeed?

Btw. why are these steps necessary or can you expand on the idea please?
  • boot live linux inside KVM
  • create partition layout, filesystem(s)

can you share more details please, what exactly are we looking for here?
  • Adapt fstab

I'd have assumed that I install a new KVM with the exact same OS version running in the LXC and adapt it to use the same partitioning and the same sources then backup the LXC, shut it down and restore it into the KVM. Finish by making sure the hostnames and IP settings are identical.

Btw. any suggestion for backing up and restoring the full system? I'm currently looking at Veeam free Linux Agent but it has some problems with LXC. As far as I remember with LXC it can only do folder/partition backups not full system backups but I might be wrong.
 
Did you succeed?

Of course, just normal Linux guru business :-D
It works also the other way around to convert a KVM or real live physical machine to LXC. It's Linux so you're only limited by your capabilities and there are uncountable nice tweaks, hacks and howtos online, yet you have to find the good ones. Often people are hyper excited to get a connection via SSH from Putty and blog about that, so a lot of information is for beginners. I'd recommend to try out a lot. Destroy systems (test systems inside a VM of course!) and try to get then to work again.

Btw. why are these steps necessary or can you expand on the idea please?

Basis computer 101:

You need a Live Linux to have an operating system inside of your booted KVM vm to do the actual work.
There should also be at least one partition to be formatted as a default Linux filesystem to hold your data. Depending on your system, you also need to have a /boot and a swap, yet this depends heavily on the used flavour of Linux.

can you share more details please, what exactly are we looking for here?

Normally, you do not have a valid fstab in LXC, because you do not need it there. Therefore you need to create an fstab in your system to be able to mount e.g. your swap, your filesystems (besides root) and sometime also the pseudo filesystems (tmpfs, devfs, etc.).

If you really want to do hardcore, you can have only one partition and do not need to have a correct fstab, but I strongly advise against it.

The migration from LXC to KVM should only be done for versatile Linux users. Each step I described is normally only one command and consists of the same steps an ordinary installer would do, just manual. If you want to dig into this subject, please have a look at "Linux From Scatch", which is distribution based on the "do everything yourself" philosophy. For everything else, you need deep Linux know how and cannot do it while avoiding CLI.

I'd have assumed that I install a new KVM with the exact same OS version running in the LXC and adapt it to use the same partitioning and the same sources then backup the LXC, shut it down and restore it into the KVM. Finish by making sure the hostnames and IP settings are identical.

You cannot restore a PVE LXC backup to a KVM machines. The first is file backup, the second a block backup and even if you could, a restore in Proxmox VE destroys your data and will overwrite everything. This is necessary to ensure the correct state of the time of the backup.

You can compare that to an reinstall of windows in case of an error in the OS. Only reinstalling without formatting will probably not get rid of your problem, a reformat will probably do.

In your reinstall scenario, you describe a service migration, not a server migration. Never overwrite system files from the files of another system. You screw with your package manager, because not every installation is the same (only if you install ancient systems from CD/DVD and do not update them)

Btw. any suggestion for backing up and restoring the full system? I'm currently looking at Veeam free Linux Agent but it has some problems with LXC. As far as I remember with LXC it can only do folder/partition backups not full system backups but I might be wrong.

I'd never use a crippled third party program if Proxmox VE has a very nice backup mechanism. Why would you want to do that?

As I wrote previously: LXC is a container-based virtualisation that uses files to store its data and therefore will be backuped in that context. A KVM VM on the other side is a virtual computer with a virtual harddisk, which needs to be backuped on a block basis, so that you won't backup the files itself, but the space and the filesystem on which the files are stored. Both systems can be backuped by Proxmox VE but are not interchangeable.

I hope thinks are clearer now.
 
  • Like
Reactions: aasami
Thanks, you gave a lot of good pointers. I jsut wanted to quickly clarify why I mentioned a 3rd party tool:

Btw. any suggestion for backing up and restoring the full system? I'm currently looking at Veeam free Linux Agent but it has some problems with LXC. As far as I remember with LXC it can only do folder/partition backups not full system backups but I might be wrong.
I'd never use a crippled third party program if Proxmox VE has a very nice backup mechanism. Why would you want to do that?
veeam agent for linux can do a full machine backup which can be restored onto completely different hardware. Hence my question if it could be used to transform LXC into KVM.
On the other hand, it can also backup partitions or simply file based areas so it sounded as if it could be used to transfer data and configurations from a LXC to a KVM system.

Therefore you need to create an fstab in your system to be able to mount e.g. your swap, your filesystems (besides root) and sometime also the pseudo filesystems (tmpfs, devfs, etc.).
- not quite clear: at this point wanting to migrate from LXC to a KVM I assume I created a brand new KVM which obviously has an intact and working fstab hence my question. Basically, I was unsure why one would boot the brand new KVM from a live linux CD? I'm sure I am simply missing something here.
 
- not quite clear: at this point wanting to migrate from LXC to a KVM I assume I created a brand new KVM which obviously has an intact and working fstab hence my question. Basically, I was unsure why one would boot the brand new KVM from a live linux CD? I'm sure I am simply missing something here.

Creating a KVM will create an empty VM. There is no operating system installed and it does not need to be. You want to migrate your data, so you need to manually create a partition layout, sync your files, create a working fstab, install a kernel and bootloader then make the system bootable. Not an easy task and veeam cannot do that either, sorry.

It's simple to migrate LXC from PVE to another LXC or even inside of a Docker container, but containerization is much lighter than KVM and so is the operating system itself.
 

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!