“LXD and ZFS in Ubuntu 18.04 LTS Server Edition″

LXD & ZFS

What is LXD?

The LXD container hypervisors is supported and created by Ubuntu team. To obtain more info about this project look these links

https://www.ubuntu.com/containers/lxd

and that

https://stgraber.org/2016/03/11/lxd-2-0-blog-post-series-012/

What is a ZFS?

To obtain an answer to this Q. we’ve to read these links:

https://wiki.ubuntu.com/ZFS

One time we have view all informations about LXD and ZFS we can proceed with our howto

In order to setup our environment we need to make some steps and having some requirements:

  • Create a bridge network (see this howto);
  • Install LXD and ZFS;
  • Create a Container profile for our lab;

our VM is so configured

Screen Shot 2016-11-04 at 17.16.14.png

screen-shot-2016-11-04-at-22-34-38

01 STEP – PREPARE HDD FOR ZFS

The first thing to do is assigned a new partition on /dev/sdb, run

$: ssh rs@10.20.40.22
$: sudo fdisk /dev/sdb
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition number (1-128, default 1): 1
First sector (34-7804682206, default 2048): 2048 
Last sector, +sectors or +size{K,M,G,T,P} (2048-7804682206, default 7804682206):7804682206 

Created a new partition 1 of type 'Linux filesystem' and of size 3.6 TiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Synching disks.

then create its partition, the result will be that

Screen Shot 2016-11-04 at 17.20.13.png

02 STEP – INSTALL LXD

Then we can proceed installing LXD and ZFS utility with the following commands:

$: sudo sh -c 'apt update && apt upgrade'

create the “lxd” group and add yourself to it.

$: sudo groupadd --system lxd
$: sudo usermod -G lxd -a <username>

install LXD by

$: sudo apt install lxd

its own virtual network adapter will have to be so configured

$: sudo more /etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto ens33
iface ens33 inet manual
auto br0
iface br0 inet dhcp
        bridge_ports ens33

03 STEP – INSTALL ZFS

After Lxd it’s time of that:

$: sudo apt-get install zfsutils-linux 
$: sudo modprobe zfs

reboot the VM

$: sudo reboot

04 STEP – INITIALISE LXD

In order the networking establishes the connection between LXC containers host, we need to set up a bridge device.

$: groups
$: sudo lxd init

Name of the storage backend to use (dir or zfs): zfs
Create a new ZFS pool (yes/no)? yes
Name of the new ZFS pool: lxd
Would you like to use an existing block device (yes/no)? yes
Path to the existing block device: /dev/sdb1
Would you like LXD to be available over the network (yes/no)? no
Do you want to configure the LXD bridge (yes/no)? yes
Warning: Stopping lxd.service, but it can still be activated by:
  lxd.socket
LXD has been successfully configured.

05 STEP – CREATE A LXC PROFILE

Lets create a container profile by copying the default:

$: lxc profile copy default svrlab

06 STEP – LAUNCH LXD CONTAINER

Once the profile has been created, we can now launch the LXC container:

$: lxc launch ubuntu:xenial xenial-svr
Creating xenial-svr
Retrieving image: 100%
Starting xenial-svr

wait few second and then check list with that command

$: lxc list
+-------------+---------+----------------------+------+------------+-----------+
| NAME        |  STATE  |        IPV4          | IPV6 |    TYPE    | SNAPSHOTS |
+-------------+---------+----------------------+------+------------+-----------+
| xenial-svr  | RUNNING | 10.20.40.39 (eth0)   |      | PERSISTENT | 0         |
+-------------+---------+----------------------+------+------------+-----------+

then to connect on its bash run that command.

$: lxc exec xenial-svr bash

07 STEP – HOW TO LIST CONTAINERS

List the existing containers:

$: lxc list --fast
$: lxc list | grep RUNNING
$: lxc list | grep STOPPED
$: lxc list

08 STEP – HOW TO GET BASH SHELL

To gain login and gain shell access in a container named file-server , enter:

$: lxc exec xenial-svr bash

09 STEP – HOW TO STOP THE CONTAINERS

Stop containers using the following syntax:

$: lxc stop xenial-svr

10 STEP – HOW TO RESTART THE CONTAINERS

Want to restart your containers for any reasons? Try:

$: lxc restart xenial-svr

11 STEP – HOW TO DELETE THE CONTAINERS

The command is (be careful as the LXD containers are deleted immediately without any confirmation prompt i.e. keep backups):

$: lxc delete xenial-svr

this how-to at moment is ended..


“cya to the next 1…. Njoy !”
bye dakj

Disclaimer: All the tutorials included on this site are performed in a lab environment to simulate a real world production scenario. As everything is done to provide the most accurate steps to date, we take no responsibility if you implement any of these steps in a production environment.

“We learn from our mistakes”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.