Simple script to convert any gnu/linux machine into a proxmox lxc container

Hello,

i wrote this simple script for migrating a mid size legacy enterprise infrastucture with a batch of diffuse scattered gnu/linux machines. it worked pretty well for my needs. maybe it can be usefull for somebody.

thanks :slight_smile:

https://github.com/my5t3ry/machine-to-proxmox-lxc-ct-converter

3 Likes

Is a proxmox lxc container just an lxc container? Or is there other baggage to consider?

Also, how different are the sizes before and after? Thanks.

Hi,

the new container will be the size of /** excluding:
–exclude=“sys”
–exclude=“dev”
–exclude=“proc”
–exclude=".log"
–exclude="
.log*"
–exclude=".gz"
–exclude="
.sql"
–exclude=“swap.img” \

After the proxmox tools ‘pct’ has imported the resulting tar, it’s just a lxc container including the ./apparmor and ./config. The containers are located at ‘/var/lib/lxc/{machineId}’.

i hope i could answer your questions adequately.

: )

1 Like

Thanks. So if I had just lxc, I could import this tar into an appropriate empty container without much issue? Thanks.

Just to chime in, Proxmox LXC, is LXC. In my experience, they mostly stick to what Ubuntu/Debian ships. They may also cherry-pick and backport fixes from LXC master.

1 Like

for what i understand it should be possbile to take a appropiate ./conf ./apparmor and extract the tar to ./rootfs

i created a tar with a example config of what pct created for a debian machine ->
http://data.shitkatapult.org/lxc.debian.cfg.example.tar.xz

maybe you can try if it works to create a lxc container with this. if it works, i will modify my script to work with templates instead of pct instead.

thx : )

1 Like

I will try it. Apologies for being ignorant - I’ve never done a restore. Looking at documentation it says that lxc-restore is what I need but I can’t find that in /usr/bin/ This is what I have:

I will definitely test your export as soon as I figure how to do so with lxc. I’m on Debian Buster.

Hello. Apologies for the long delay, it appears I can’t test with vanilla lxc because it asking for the pct tool. I’ll look to see if I can run the tool without some switches and remove it.

I know it’s niche, but might be useful for those who use only lxc.

./convert.sh: line 63: pct: command not found

edit: that was easy! I commented out the relevant sections for pct and it’s copying its ass off as we speak. Will update soon.

The container runs, which is great, but the software isn’t working. Networking isn’t automatic and I have to manually start the service. Also, the following services show failed:

` >

systemd-journald-audit.socket loaded failed failed Journal Audit Socket

systemd-udevd-control.socket loaded failed failed udev Control Socket
systemd-udevd-kernel.socket loaded failed failed udev Kernel Socket
systemd-udev-trigger.service loaded failed failed udev Coldplug all Devices
systemd-udevd.service loaded failed failed udev Kernel Device Manager
systemd-remount-fs.service loaded failed failed Remount Root and Kernel File Systems

systemd-hwdb-update.service loaded failed failed Rebuild Hardware Database
sys-kernel-debug.mount loaded failed failed Kernel Debug File System
`
I don’t expect you to fix or troubleshoot, just reporting what I found.

I had gitlab installed on this and it wasn’t running. SSH for example, which is to be expected. I decided to just see if reinstalling the packages (I don’t recommend, see below) in the container would fix issues:

dpkg-query -f ‘${binary:Package}\n’ -W > packages.txt
xargs apt install --reinstall -y < packages.txt

Naturally Gitlab doesn’t like this at all. BUT… if you dig deep enough for problems and prune the package list accordingly - I think you could have a viable system. Would it save time? I think so, depending on complexities of host physical system.

Last update. This article had something particular with lxc and gitlab, so I’m thinking this might work fine for other installations. Just need to do some homework beforehand. Thanks for the work. [SOLVED] - Running GitLab in LXC | Proxmox Support Forum

Hello, maybe you run script convert.sh not on on the proxmox node, but on the target machine you want to convert? On the target machine pct command not available.
Script runs on proxmox node, need root user on the target machine and fetch all data to the proxmox node.

At the end of process of collect all data, the script shows error:
tar: Exiting with failure status due to previous errors
400 too many arguments
pct create [OPTIONS]
root@srv:~/machine-to-proxmox-lxc-ct-converter#

In log i see the warnings that some files cannot be read: access denied. Full log contains 20mb, i can load it.
Can you help me to fix this problem?
Thanks in advance.

Wow! this is amazing.

I was looking for a way to convert a VM to LXC, and this one just worked like magic! I wasted several hours but am glad that I stumbled upon this. Thank you.

For anyone looking for something like this for importing into LXD we have lxd-migrate:

1 Like

Hello Sasha @my5t3ry

I find it really odd that such a thing did not get the amount of recognition it truly deserves, not only for the simplicity of it but since it explains in the best manner possible what the files we use as templates for LXC containers, really are.

I have been wondering if these files contain any meta data, or if they are just root filesystems, then was wondering if they are root filesystems that are somehow altered. I continued scratching my head wondering why I cannot run any of the minimal Ubuntu images found on the Ubuntu website to function as LXC containers (after failing to run them as VMs): Ubuntu Minimal Cloud Images (RELEASED) … it seemed like it is a real shame, and like some basic education about this stuff was somehow missing on the internet.

Your script proved my intuition which was that it was indeed, not too hard at all to convert most systems into LXC containers. However, this information is buried under lots and lots of irrelevant and complex information online, suggesting that:

  1. creating an LXC image is a complex process that requires a deep understanding of the operating system.
  2. that it requires a variety of tools to be downloaded and installed.

As it turns out, any cloud image can be made into a container, once “repackaged”, and by that I mean:

  1. extracting the tarball into a folder
  2. recreate the archive while excluding the kernel folders

Seriously. This information is highly, highly obscured.

I would really appreciate it if you guide me into a place where I can read about this stuff while not losing the big picture in the details. For example, where can I read about this very simple realisation that your script helped me achieve? I have been reading about LXC and LXD, and in all honesty, our literature is an effing mess.