Lxd: Unterschied zwischen den Versionen

Aus Vosp.info
Wechseln zu:Navigation, Suche
Zeile 1: Zeile 1:
 +
 +
 +
= Migration lxc Container zu lxd Container =
 +
 +
<source lang=bash>
 +
#!/bin/bash
 +
if [ "$1" == "" ]; then
 +
echo Beispiel: $0 containername betriebsystem
 +
exit 1
 +
fi
 +
 +
if ! [ -d "/var/lib/lxc/$1" ] ; then
 +
        echo /var/lib/lxc/$1 existiert nicht!
 +
        exit
 +
fi
 +
 +
if [ "$2" == "" ]; then
 +
 +
echo Beispiel: $0 containername betriebsystem
 +
echo lxc image list images:
 +
echo es wird ubuntu:20.04 genomme
 +
        besys='ubuntu:20.04'
 +
else
 +
        besys=$2
 +
fi
 +
 +
echo $0 $1 $besys
 +
 +
CONTAINER_NAME=$1
 +
STORAGE_POOL=default
 +
STORAGEPATH=/var/snap/lxd/common/lxd/storage-pools/${STORAGE_POOL}/containers/
 +
 +
lxc-stop -n ${CONTAINER_NAME}
 +
lxc init $besys ${CONTAINER_NAME} -c security.privileged=true -c boot.autostart=true
 +
#lxc stop ${CONTAINER_NAME}
 +
#lxc config set ${CONTAINER_NAME} boot.autostart true
 +
###
 +
# zfs list
 +
## Benutze NAME z.B default/containers/ncsync
 +
zfs mount default/containers/${CONTAINER_NAME}
 +
verschiebt den orginalen rootfs
 +
mv ${STORAGEPATH}${CONTAINER_NAME}/rootfs{,.org}
 +
rsync -ah --stats --progress  --numeric-ids /var/lib/lxc/${CONTAINER_NAME}/rootfs ${STORAGEPATH}${CONTAINER_NAME}/
 +
mv ${STORAGEPATH}${CONTAINER_NAME}/rootfs/dev{,.org}
 +
rsync -ah --stats --progress  ${STORAGEPATH}${CONTAINER_NAME}/rootfs.org/dev ${STORAGEPATH}${CONTAINER_NAME}/rootfs/
 +
rm -r ${STORAGEPATH}${CONTAINER_NAME}/rootfs.org
 +
umount ${STORAGEPATH}${CONTAINER_NAME}
 +
#sed -i 's|lxc.start.auto = .*|lxc.start.auto = 0|g' /var/lib/lxc/${CONTAINER_NAME}/config
 +
lxc config set ${CONTAINER_NAME} volatile.eth0.hwaddr $(grep lxc.net.0.hwaddr /var/lib/lxc/${CONTAINER_NAME}/config | cut -d"=" -f2)
 +
lxc config show ${CONTAINER_NAME}
 +
#lxc-ls -n ${CONTAINER_NAME} -f
 +
lxc start ${CONTAINER_NAME}
 +
 +
lxc stop ${CONTAINER_NAME}
 +
lxc config set ${CONTAINER_NAME}  security.privileged false
 +
lxc start ${CONTAINER_NAME}
 +
 +
lxc stop ${CONTAINER_NAME}
 +
lxc config set ${CONTAINER_NAME}  security.privileged true
 +
lxc start ${CONTAINER_NAME}
 +
 +
lxc stop ${CONTAINER_NAME}
 +
lxc config set ${CONTAINER_NAME}  security.privileged false
 +
lxc start ${CONTAINER_NAME}
 +
 +
lxc list
 +
</source>
 +
* http://www.panticz.de/migrate-lxc-container-to-lxd-with-zfs-storage
 +
 +
 +
= Quellen =
 
* verwendete links
 
* verwendete links
 
** https://www.cyberciti.biz/faq/install-lxd-on-ubuntu-20-04-lts-using-apt/
 
** https://www.cyberciti.biz/faq/install-lxd-on-ubuntu-20-04-lts-using-apt/

Version vom 20. November 2020, 17:33 Uhr


Migration lxc Container zu lxd Container

#!/bin/bash
if [ "$1" == "" ]; then
 echo Beispiel: $0 containername betriebsystem
 exit 1
fi

if ! [ -d "/var/lib/lxc/$1" ] ; then
        echo /var/lib/lxc/$1 existiert nicht!
        exit
fi

if [ "$2" == "" ]; then

 echo Beispiel: $0 containername betriebsystem
 echo lxc image list images:
 echo es wird ubuntu:20.04 genomme
        besys='ubuntu:20.04'
else
        besys=$2
fi

echo $0 $1 $besys

CONTAINER_NAME=$1
STORAGE_POOL=default
STORAGEPATH=/var/snap/lxd/common/lxd/storage-pools/${STORAGE_POOL}/containers/

lxc-stop -n ${CONTAINER_NAME}
lxc init $besys ${CONTAINER_NAME} -c security.privileged=true -c boot.autostart=true
#lxc stop ${CONTAINER_NAME}
#lxc config set ${CONTAINER_NAME} boot.autostart true
###
# zfs list
## Benutze NAME z.B default/containers/ncsync
zfs mount default/containers/${CONTAINER_NAME}
verschiebt den orginalen rootfs
mv ${STORAGEPATH}${CONTAINER_NAME}/rootfs{,.org}
rsync -ah --stats --progress  --numeric-ids /var/lib/lxc/${CONTAINER_NAME}/rootfs ${STORAGEPATH}${CONTAINER_NAME}/
mv ${STORAGEPATH}${CONTAINER_NAME}/rootfs/dev{,.org}
rsync -ah --stats --progress  ${STORAGEPATH}${CONTAINER_NAME}/rootfs.org/dev ${STORAGEPATH}${CONTAINER_NAME}/rootfs/
rm -r ${STORAGEPATH}${CONTAINER_NAME}/rootfs.org
umount ${STORAGEPATH}${CONTAINER_NAME}
#sed -i 's|lxc.start.auto = .*|lxc.start.auto = 0|g' /var/lib/lxc/${CONTAINER_NAME}/config
lxc config set ${CONTAINER_NAME} volatile.eth0.hwaddr $(grep lxc.net.0.hwaddr /var/lib/lxc/${CONTAINER_NAME}/config | cut -d"=" -f2)
lxc config show ${CONTAINER_NAME}
#lxc-ls -n ${CONTAINER_NAME} -f
lxc start ${CONTAINER_NAME}

lxc stop ${CONTAINER_NAME}
lxc config set ${CONTAINER_NAME}  security.privileged false
lxc start ${CONTAINER_NAME}

lxc stop ${CONTAINER_NAME}
lxc config set ${CONTAINER_NAME}  security.privileged true
lxc start ${CONTAINER_NAME}

lxc stop ${CONTAINER_NAME}
lxc config set ${CONTAINER_NAME}  security.privileged false
lxc start ${CONTAINER_NAME}

lxc list


Quellen