my5t3ry / machine-to-proxmox-lxc-ct-converter Goto Github PK
View Code? Open in Web Editor NEWconvert any gnu/linux machine into a proxmox lxc container
convert any gnu/linux machine into a proxmox lxc container
Trying to convert a LCX container from a non-proxmox machine to a proxmox machine, but getting:
./convert.sh: line 63: pct: command not found
Apparently it can't run this part:
pct create $id "/tmp/$name.tar.gz" \
-description LXC \
-hostname $name \
--features nesting=1 \
-memory $memory -nameserver 8.8.8.8 \
-net0 name=eth0,ip=$ip/24,gw=$gateway,bridge=$bridge \
--rootfs $rootsize -storage $storage -password $password
Is this supposed to happen?
I have moved opensuse to LXC. Looks all okay, except I have no console in Proxmox for this container.
I see that it is expected be tty1(when I an sending to tty1 i see output) but no login prompts.
Any idea? Apparmor already off.
I followed the instructions and this is my experience :
Proxmox by default does not have 'git' installed. I created the files manually :
mkdir /usr/local/convertvmtolxc
nano /usr/local/convertvmtolxc/convert.sh
paste in content of https://github.com/my5t3ry/machine-to-proxmox-lxc-ct-converter/blob/master/convert.sh
nano /usr/local/convertvmtolxc/bashconvert
paste in content of https://github.com/my5t3ry/machine-to-proxmox-lxc-ct-converter/blob/master/bashconvert
chmod +x /usr/local/convertvmtolxc/convert.sh /usr/local/convertvmtolxc/bashconvert
Install 'git' :
apt-get install git
I had difficulties with the RSA-keys. The instruction does not give any detailed information. In the first place it didn't work, but I saw that the script uses the root-user for RSA-key and I setup the RSA-key in my own account with sudo rights.
It's also a bit confusing it asks for the SSH Uri what is like root@ip-address-remote-server but in the end I had only type the ip-address of the remote server.
Proxmox :
sudo su
ssh-keygen -b 4096
enter for creating key
overwrite > y
2x enter for create without password
cat ~/.ssh/id_rsa.pub
copy public key begins with 'ssh -rsa' and end with '@host'.
Remote server :
sudo su
sudo echo YOURPUBLICKEY >> ~/.ssh/authorized_keys
sudo chmod -R go= ~/.ssh
sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config && systemctl restart ssh
Test from Proxmox :
ssh root@ip-address-remote-server -p portnumber
typ 'yes' and press to add the connection to the list of known hosts.
typ 'exit' and press to exit the ssh connection.
Bashconvert :
With script ./convert.sh it doesn't show any output. It keeps waiting and looks like it hangs. But with ./bashconvert you do have an output. Conversion does also take a very long time and is for the remote server very CPU intensive and uses a lot of memory; I had to expand memory to 4GB and cores to 4 for this job, and even then it uses almost continu all resources. My machine uses a enterpise SSD so that should not be the cullprit. The machine normally uses only 1 core and 2GB memory.
**Edit :
On the remote-server there are mnt-points configured, it looks like the conversion follows the path of the mnt-points and copies that information. The mnt-points pointing to a Synology NAS with a lot of data...
I had to stop the script and unmount first all mnt-points on the remote-server :
umount -a
and/or nano /etc/fstab
and add #
before the line(s) to unmount.
Show mounts : mount -l
or cat /proc/mounts
./bashconvert -n 'name-of-new-lxc-server' -t 'ip-address-of-remote-server' -P 'ssh-port-number-remote-server' -i 'proxmox-new-server-id' -s 'number-storage-in-gb-new-lxc-server' -a 'ip-address-of-new-lxc-server' -b 'name-of-bridge-network-like-vmbr0' -g 'ip-address-of-network-gateway' -m 'number-memory-in-mb-new-lxc-server' -d 'storage-location-proxmox-like-local-zfs' -p 'password-new-lxc-server'
Example :
./bashconvert -n LXCNewServer -t 10.1.1.216 -P 26 -i 207 -s 4 -a 10.1.0.216 -b vmbr0 -g 10.1.1.254 -m 2048 -d local-zfs -p 'Password@!123.!'
Summary :
If set before, enter passphrase RSA public key. Then conversion starts.
I looked into the script 'bashconvert' and in the first place I see the following :
Change the following and copy paste in Proxmox to execute :
remote_rootuser='root'
remote_ip='10.1.1.214'
remote_port='26'
proxmox_lxcid='214'
proxmox_lxchostname='LXCHOSTNAME'
proxmox_lxcdescription='LXC'
proxmox_lxcmemory='2048'
proxmox_lxcnameserver='10.1.1.100'
proxmox_lxcip='10.1.0.214'
proxmox_lxcipcidr='23'
proxmox_lxcgateway='10.1.1.254'
proxmox_lxcbridge='vmbr0'
proxmox_lxcdisksize='4'
proxmox_lxcstoragelocation='local-zfs'
proxmox_lxcstorageswapfile='512'
proxmox_lxccpucores='1'
proxmox_lxcpassword='YOURPASSWORD'
proxmox_lxcunprivileged='0'
proxmox_lxcstartonproxmoxboot='1'
CreateTar(){
tar -czvvf - --one-file-system -C / --exclude="sys" --exclude="dev" --exclude="run" --exclude="proc" --exclude="*.log" --exclude="*.log*" --exclude="*.gz" --exclude="*.sql" --exclude="swap.img" --exclude="*.zip" --exclude="*.journal~" --exclude="*debug.*.txt" --exclude="*/drivers/*" --exclude="*/logs/*" /
}
ssh -p $remote_port $remote_rootuser@$remote_ip "$(typeset -f CreateTar); CreateTar" > '/tmp/pct_tmp.tar.gz'
pct create $proxmox_lxcid '/tmp/pct_tmp.tar.gz' \
--description $proxmox_lxcdescription \
--hostname $proxmox_lxchostname \
--features mknod=1,nesting=1,keyctl=1 \
--memory $proxmox_lxcmemory \
--nameserver $proxmox_lxcnameserver \
-net0 name=eth0,ip=$proxmox_lxcip/$proxmox_lxcipcidr,gw=$proxmox_lxcgateway,bridge=$proxmox_lxcbridge \
--rootfs $proxmox_lxcdisksize \
--unprivileged $proxmox_lxcunprivileged \
--storage $proxmox_lxcstoragelocation \
--swap $proxmox_lxcstorageswapfile \
--cores $proxmox_lxccpucores \
--onboot $proxmox_lxcstartonproxmoxboot \
-password $proxmox_lxcpassword
rm -rf '/tmp/pct_tmp.tar.gz'
Documentation pct : https://pve.proxmox.com/pve-docs/pct.1.html
Finally :
Login via ssh to LXC container and execute :
apt-get update -y && apt-get upgrade -y
sed -i 's/PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config && systemctl restart ssh
sudo nano /etc/apt/sources.list
Docker :
I run LXC in Ubuntu 24.04.
Proxmox :
echo -e "overlay\naufs" >> /etc/modules-load.d/modules.conf
Reboot.
LXC container :
Install Docker, see instructions : https://docs.docker.com/engine/install/ubuntu/
Use the following configuration to get Docker working :
Old docker-compose.yaml : remove ' version' information, and add as part of your configuration file :
Problem solving :
Use 'docker compose' instead of 'docker-compose' :
Problem starting LXC in Proxmox :
run_apparmor_parser: 916 Failed to run apparmor_parser on "/var/lib/lxc/200/apparmor/lxc-200<-var-lib-lxc>": Found reference to variable PROC, but is never declared
apparmor_prepare: 1088 Failed to load generated AppArmor profile
lxc_init: 877 Failed to initialize LSM
_lxc_start: 2034 Failed to initialize container "200"
TASK ERROR: startup for container '200' failed
If in Proxmox file not exists create nano /etc/apparmor.d/tunables/proc
and add the following line :
@{PROC}=/proc/
No reboot required.
From the outside the LXC container is reachable, but I don't have access to the Docker containers. I understand that LXC and Docker are some sort the same and it's not best practice having Docker within a LXC container.
I was blind trying to get this solved, and I will get this solved but on the other hand it's better for me to have my Docker applications running directly in LXC/Ubuntu and not in a container. I have to reinstall and reconfigure my webapplications to get this working but then not prone to any future updates.
Documentation 'apparmor-profiles' in Docker : https://docs.docker.com/engine/security/apparmor/
Check this other cool script for creating LXC containers : https://github.com/tteck/Proxmox
Like timings of an example case ubuntu full proxmox vm into an lxc instance?
Also limitations on use, etc
Enter new password: **************
Retype new password: **************
400 Parameter verification failed.
rootfs: invalid format - format error
rootfs.volume: property is missing and it is not optional
memory: type check ('integer') failed - got ''
vmid: type check ('integer') failed - got ''
net0: invalid format - missing key in comma-separated list property
storage: invalid format - storage ID '' contains illegal characters
pct create [OPTIONS]
-bash: -i: command not found
command run:
./convert.sh
-n NewTestCTConvert
-t 192.168.1.119
-P 22 \
-i 109
-s 130
-a 192.168.1.121
-b vmbr0
-g 192.168.1.1
-m 2048
-d default
-p Somepassword
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.