Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tips:lxd [2017/11/21 11:07] – [migration] scipiotips:lxd [2019/11/19 19:12] (current) – [container] scipio
Line 5: Line 5:
  
 <code> <code>
-sudo add-apt-repository --yes ppa:ubuntu-lxc/lxd-stable +apt remove lxd lxd-client 
-sudo apt update +snap install lxd
-sudo apt install lxd+
  
 # create zfs dataset on pool rpool # create zfs dataset on pool rpool
Line 129: Line 128:
 lxc list lxc list
 </code> </code>
 +
 +create custom image from local container
 +<code>
 +lxc publish local-container --alias mycustomimage
 +</code>
 +
 +create container from previous image
 +<code>
 +lxc launch mycustomimage newcontainer
 +</code>
 +
 +
  
 bash inside bash inside
Line 162: Line 173:
 </file> </file>
  
 +
 +===== network =====
 +
 +<code>
 +lxc network create br0
 +lxc network show br0
 +lxc network edit br0
 +</code>
 +
 +static IP container
 +<code>
 +istance=c1
 +
 +lxc stop $instance
 +lxc network attach lxdbr0 $istance eth0 eth0
 +lxc config device set $istance eth0 ipv4.address 10.99.10.42
 +lxc start $istance
 +</code>
 ===== servers ===== ===== servers =====
  
Line 192: Line 221:
 <code bash> <code bash>
 NAME=x11test NAME=x11test
-lxc launch images:ubuntu/xenial/amd64 $NAME+lxc launch images:ubuntu/bionic/amd64 $NAME
 </code> </code>
  
Line 198: Line 227:
 <code bash> <code bash>
 lxc exec $NAME -- apt install xterm lxc exec $NAME -- apt install xterm
 +lxc exec $NAME bash
 +apt install mesa-utils x11-apps
 </code> </code>
  
-set DISPLAY env to xorg server on host + 
-<code bash+<code> 
-lxc config set x11test environment.DISPLAY <ip-of-host-lxdbr0-bridge>:0+NAME=nvidia-sdk-manager 
 +lxc config set $NAME environment.DISPLAY <ip-of-host-lxdbr0-bridge>:0 
 +lxc config set $NAME environment.DISPLAY :0 
 +lxc config device add $NAME X0 disk path=/tmp/.X11-unix/X0 source=/tmp/.X11-unix/X0 
 +lxc config device add $NAME Xauthority disk path=/root/.Xauthority source=${XAUTHORITY}
 </code> </code>
  
Line 251: Line 286:
 # only first time # only first time
 echo "root:$UID:1" | sudo tee -a /etc/subuid echo "root:$UID:1" | sudo tee -a /etc/subuid
-echo "root:$GID:1" | sudo tee -a /etc/subgid+echo "root:${id -d}:1" | sudo tee -a /etc/subgid 
 +lxc profile set default security.privileged true
  
 # for every share  # for every share 
 # lxc init stretch giano # lxc init stretch giano
 +lxc config set gianocop security.privileged true
 lxc config set giano raw.idmap "both $UID $UID" lxc config set giano raw.idmap "both $UID $UID"
 # source is on host, path is inside container # source is on host, path is inside container
Line 289: Line 326:
   volatile.last_state.power: STOPPED   volatile.last_state.power: STOPPED
 </code> </code>
 +===== export image from container =====
 +{{tag>[wiki lxd 'profile network' apache vlan]}}
 +
 +
 +===== Vlan attach =====
 +<code>apt-get install vlan </code>
 +<code>sudo modprobe 8021q </code>
 +<code>sudo vconfig add eth1 10 </code>
 +
 +<code>sudo ip addr add 10.0.0.1/24 dev eth1.10 </code>
 +
 +<code>ip addr del 10.22.30.44/16 dev eth0 </code>
 +
 +<code>sudo ip link set up eth1.10</code>
 +<code> sudo su -c 'echo "8021q" >> /etc/modules'</code>
 +<code>
 +auto eth1.10
 +iface eth1.10 inet static
 +    address 10.0.0.1
 +    netmask 255.255.255.0
 +    vlan-raw-device eth1 </code>
 +
 +===== Send file to your new host =====
 +
 +On image hosts
 +
 +<code>lxc publish --force 'name of container" --alias 'new name' </code>
 +example
 +<code>lxc publish --force 'lxc-limesurvey' --alias 'lxc-docuwiki' </code>
 +
 +Export image
 +<code>lxc image  export 'new name' </code>
 +
 +Output is in efaa243331f0a7c175376edaf796545a01ad09bb47f25a297b798e09fe66ee66.tar.gz
 +Show size of export
 +<code>du -h efaa243331f0a7c175376edaf796545a01ad09bb47f25a297b798e09fe66ee66.tar.gz </code>
 +
 +==== check sum of image ====
 +
 +<code>
 +md5sum efaa243331f0a7c175376edaf796545a01ad09bb47f25a297b798e09fe66ee66.tar.gz > exportmd5.txt
 +
 +cat exportmd5.txt | nc 10.18.49.73 1234
 +
 +cat efaa243331f0a7c175376edaf796545a01ad09bb47f25a297b798e09fe66ee66.tar.gz | nc 10.18.49.73 1234
 +</code>
 +**NB**: 10.18.49.73 is your new lxd host
 +
 +1234 is a free port
 +
 +===== Transfer image and checksum to new LXD host =====
 +<code>
 +nc -l 1234 > efaa243331f0a7c175376edaf796545a01ad09bb47f25a297b798e09fe66ee66.tar.gz
 +nc -l 1234 > exportmd5.txt </code>
 +
 +check file
 +<code>
 +md5sum efaa243331f0a7c175376edaf796545a01ad09bb47f25a297b798e09fe66ee66.tar.gz 
 +md5sum -c exportmd5.txt 
 +</code>
 +
 +===== Import image to new LXD host ======
 +
 +<code> lxc image import efaa243331f0a7c175376edaf796545a01ad09bb47f25a297b798e09fe66ee66.tar.gz --alias lxc-docuwiki </code>
 +
 +Transferring image: 100%
 +
 +<code>lxc launch image_name container_name </code>
 +Creating container_name
 +Starting container_name
 +
 +In some instances the publish command may lead to a split xz tar-ball --- but both formats are supported. Simply import the meta-data and rootfs components with
 +
 +    lxc image import <metadata tarball> <rootfs tarball> --alias image_name
 +=== Edit LXD default profile: networking ===
 +
 +Put lxc network interface to host network
 +
 +<code>
 +lxc stop lxc-docuwiki 
 +lxc profile device set default eth0 parent ens3
 +lxc profile device set  default eth0 nictype macvlan
 +service lxd restart
 +service lxd-containers restart </code>
 +
 +launch your container
 +<code>
 +lxc start lxc-docuwiki 
 +lxc exec lxc-docuwiki /bin/bash
 +
 +</code>
 +
 +
  
  • tips/lxd.1511258848.txt.gz
  • Last modified: 2017/11/21 11:07
  • by scipio