cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Etc


Reference














.

middleware:virtualization:lxd:index.html



LXD

Directory structure

File Note
/var/lib/lxd/lxd.db LXD has an internal database which stores all of that information.
/var/lib/lxd/containers/CONTAINER/rootfs/
/var/lib/lxd/snapshots


Installation of LXD

How to install LXD in Ubuntu

$ sudo apt-get update
$ sudo apt-get upgrade

$ dpkg -l |grep lxd   <- checking
$ sudo apt install lxd
$ dpkg -l |grep lxd   <- checking

$ sudo systemctl status lxd.service  <- checking
$ sudo systemctl start lxd.service
$ sudo systemctl enable lxd.service
$ sudo systemctl status lxd.service  <- checking
$ lxd --version
2.0.0
$ lxc --version
2.0.0
If you want to use bridged network, you install bridge-utils
sudo apt-get install bridge-utils
If you want to use zfs, you install zfsutils-linux.
sudo apt-get install zfsutils-linux


Preparation

Crete A New Bridge

/etc/network/interfaces

source /etc/network/interfaces.d/*

auto lo
iface lo inet loopback

auto br0
iface br0 inet dhcp
        bridge_ports enp0s3

iface enp0s3 inet manual
source /etc/network/interfaces.d/*

auto lo
iface lo inet loopback

auto enp0s3
iface enp0s3 inet manual

auto br0
iface br0 inet dhcp
    bridge-ifaces enp0s3
    bridge-ports enp0s3
    ip link set enp0s3 up
source /etc/network/interfaces.d/*

auto lo
iface lo inet loopback

auto ens1f1
iface ens1f1 inet manual

auto br0
iface br0 inet static
  address 192.168.0.100
  network 192.168.0.0
  netmask 255.255.255.0
  gateway 192.168.0.1
  bridge_ports ens1f1

To enable packet forwarding for IPv4

# sysctl net.ipv4.ip_forward  < - checking the parameter
net.ipv4.ip_forward = 0
# vi /etc/sysctl.conf
...
net.ipv4.ip_forward=1
...
# sysctl -p
# sysctl net.ipv4.ip_forward  < - checking the parameter
net.ipv4.ip_forward = 1


Disable IPv6

$ sudo vi /etc/sysctl.conf
....
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
....
$ sudo sysctl -p


Disable iptalbes

$ sudo iptalbes -F
$ sudo iptables-save


Initialization

Initialization with Dialog

Example for bridged network
# ip a  <- check

# lxd init
Name of the storage backend to use (dir or zfs) [default=zfs]: 
Create a new ZFS pool (yes/no) [default=yes]? 
Name of the new ZFS pool [default=lxd]: 
Would you like to use an existing block device (yes/no) [default=no]? 
Size in GB of the new loop device (1GB minimum) [default=15]: 30
Would you like LXD to be available over the network (yes/no)? no
Do you want to configure the LXD bridge (yes/no)? yes

Would you like to setup a network bridge for LXD containers now? yes
Do you want to use an existing bridge? yes  
Bridge interface name:  br0

Do you want to setup an IPv4 subnet?
No

Do you want to setup an IPv6 subnet?
No

LXD has been successfully configured. 
Example for nat network
$ sudo lxd init
Name of the storage backend to use (dir or zfs) [default=dir]: dir
Would you like LXD to be available over the network (yes/no) [default=no]?no
Do you want to configure the LXD bridge (yes/no) [default=yes]?yes

Would you like to setup a network bridge for LXD containers now? yes
Do you want to use an existing bridge? yes  
Bridge interface name:  br0

Do you want to setup an IPv4 subnet?
No

Do you want to setup an IPv6 subnet?
No

LXD has been successfully configured. 



Reconfigure after Initialization

# dpkg-reconfigure -p medium lxd


Configuration for Profile

Commands Note
lxc profile list list of all available profiles
lxc profile show <profile> To see the content of a profile
lxc profile edit <profile> change profile
lxc profile apply <container> <profile1>,<profile2>,<profile3>,.. apply profile to container
Local configuration
Commands Note
lxc config show <container> read the container local configuration
lxc config show --expanded <container> including all the profile keys
lxc config edit <container>



middleware/virtualization/lxd/index.html.txt ยท Last modified: 2017/06/29 by admin

Page Tools