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

2 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