Commit db1bb752 authored by Ballabriga Clément's avatar Ballabriga Clément
Browse files

Initial revision

parents
# Template used to create this container: /usr/share/lxc/templates/lxc-download
# Parameters passed to the template: -d debian -r buster -a amd64
# For additional config options, please look at lxc.container.conf(5)
# Uncomment the following line to support nesting containers:
#lxc.include = /usr/share/lxc/config/nesting.conf
# (Be aware this has security implications)
# Distribution configuration
lxc.include = /usr/share/lxc/config/common.conf
lxc.include = /usr/share/lxc/config/userns.conf
lxc.arch = linux64
# Container specific configuration
lxc.include = /usr/share/lxc/config/nesting.conf
lxc.idmap = u 0 @UID_START@ 65536
lxc.idmap = g 0 @GID_START@ 65536
lxc.rootfs.path = dir:/var/lib/lxc/@MACHINE_NAME@/rootfs
lxc.uts.name = @MACHINE_NAME@
# Network configuration
lxc.net.0.type = veth
lxc.net.0.link = lxcbr0
lxc.net.0.flags = up
lxc.net.0.hwaddr = @MACHINE_HWADDR@
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address @MACHINE_IP@
netmask 255.255.255.0
gateway 10.0.3.1
#!/bin/bash -e
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/snap/bin
LXCUSER="root"
if [ "$4" == "" ]; then
echo "usage: migrate.sh <srcdir> <machine name> <machine hwaddr> <machine ip>"
exit 1
fi
SRC="$1"
NAME="$2"
HWADDR="$3"
IP="$4"
DST="/var/lib/lxc/$NAME/rootfs"
UID_START=$(grep "$LXCUSER": /etc/subuid |cut -d ':' -f 2)
GID_START=$(grep "$LXCUSER": /etc/subgid |cut -d ':' -f 2)
mkdir /var/lib/lxc/$NAME
echo "Generating config from template..."
cat config |sed "s/@MACHINE_NAME@/$NAME/g;s/@MACHINE_HWADDR@/$HWADDR/g;s/@UID_START@/$UID_START/g;s/@GID_START@/$GID_START/g" > /var/lib/lxc/$NAME/config
echo "Migration source: $SRC"
echo "Migration dest: $DST"
echo "Container UID start: $UID_START"
echo "Container GID start: $GID_START"
UIDS=$(cat $SRC/etc/passwd |cut -d ':' -f 3 |xargs echo)
GIDS=$(cat $SRC/etc/group |cut -d ':' -f 3 |xargs echo)
echo "List of UIDs to convert: $UIDS"
echo "List of GIDs to convert: $GIDS"
UIDMAP=""
for U in $UIDS ; do
if [ "$UIDMAP" != "" ]; then
UIDMAP="$UIDMAP,"
fi
UIDMAP="$UIDMAP$U:$(($U + $UID_START))"
done
echo "UID mapping: $UIDMAP"
GIDMAP=""
for U in $GIDS ; do
if [ "$GIDMAP" != "" ]; then
GIDMAP="$GIDMAP,"
fi
GIDMAP="$GIDMAP$U:$(($U + $GID_START))"
done
echo "GID mapping: $GIDMAP"
echo "Copying..."
rsync -aHSAXx --numeric-ids --usermap $UIDMAP --groupmap $GIDMAP $SRC $DST
echo "Generating /etc/network/interfaces from template ..."
cat interfaces |sed "s/@MACHINE_IP@/$IP/g" > /var/lib/lxc/$NAME/rootfs/etc/network/interfaces
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment