How to launch Ubuntu 18.04 container on Ubuntu 21.04

To Launch Ubuntu 18.04 container on Ubuntu 21.04

Introduction:

A Linux Container (LXC) is a method of operating-system-level virtualization that allows multiple isolated Linux systems (containers) on a single host using a single Linux kernel. An end-user perceives a Linux container as a virtual machine, yet it's much lighter. The container doesn't demand a different Linux kernel and doesn't require any CPU hardware virtualization support.

Installation Procedure:

Step 1:Check the version of the OS by using the following command

root@linuxhelp:~#  lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 21.04
Release:	21.04
Codename:	hirsute

Step 2: Update apt source list

root@linuxhelp:~#  apt update
Hit:1 http://in.archive.ubuntu.com/ubuntu hirsute InRelease
Get:2 http://in.archive.ubuntu.com/ubuntu hirsute-updates InRelease [115 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu hirsute-backports InRelease [101 kB] 
Get:4 http://in.archive.ubuntu.com/ubuntu hirsute-updates/main amd64 Packages [446 kB]
Get:5 http://security.ubuntu.com/ubuntu hirsute-security InRelease [110 kB]
Get:6 http://in.archive.ubuntu.com/ubuntu hirsute-updates/main i386 Packages [215 kB]
Get:7 http://in.archive.ubuntu.com/ubuntu hirsute-updates/main Translation-en [116 kB]
Get:8 http://in.archive.ubuntu.com/ubuntu hirsute-updates/main amd64 c-n-f Metadata [8,160 B]
Get:9 http://in.archive.ubuntu.com/ubuntu hirsute-updates/universe amd64 Packages [349 kB]
Get:10 http://in.archive.ubuntu.com/ubuntu hirsute-updates/universe i386 Packages [248 kB]
Get:11 http://in.archive.ubuntu.com/ubuntu hirsute-updates/universe Translation-en [88.0 kB]
Get:21 http://security.ubuntu.com/ubuntu hirsute-security/universe amd64 Packages [233 kB]
Get:22 http://security.ubuntu.com/ubuntu hirsute-security/universe i386 Packages [199 kB]
Get:23 http://security.ubuntu.com/ubuntu hirsute-security/universe Translation-en [52.2 kB]
Get:24 http://security.ubuntu.com/ubuntu hirsute-security/universe amd64 c-n-f Metadata [5,940 B]
Fetched 2,821 kB in 5s (588 kB/s)                      
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
15 packages can be upgraded. Run 'apt list --upgradable' to see them.

Step 3:Install the zfs utility by using the following command

root@linuxhelp:~# apt install -y zfsutils-linux
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
  libllvm11
Use 'apt autoremove' to remove it.
The following additional packages will be installed:
  libnvpair3linux libuutil3linux libzfs4linux libzpool4linux zfs-zed
Suggested packages:
  nfs-kernel-server zfs-initramfs | zfs-dracut
The following NEW packages will be installed:
  libnvpair3linux libuutil3linux libzfs4linux libzpool4linux zfs-zed
  zfsutils-linux
0 upgraded, 6 newly installed, 0 to remove and 15 not upgraded.
Need to get 2,060 kB of archives.
After this operation, 6,929 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu hirsute-updates/main amd64 libnvpair3linux amd64 2.0.2-1ubuntu5.3 [49.5 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu hirsute-updates/main amd64 libuutil3linux amd64 2.0.2-1ubuntu5.3 [42.3 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu hirsute-updates/main amd64 libzfs4linux amd64 2.0.2-1ubuntu5.3 [210 kB]
Get:4 http://in.archive.ubuntu.com/ubuntu hirsute-updates/main amd64 libzpool4linux amd64 2.0.2-1ubuntu5.3 [1,237 kB]
insmod /lib/modules/5.11.0-41-generic/kernel/zfs/spl.ko 
zfs-import-scan.service is a disabled or a static unit, not starting it.
Setting up zfs-zed (2.0.2-1ubuntu5.3) ...
Created symlink /etc/systemd/system/zed.service → /lib/systemd/system/zfs-zed.se
rvice.
Created symlink /etc/systemd/system/zfs.target.wants/zfs-zed.service → /lib/syst
emd/system/zfs-zed.service.
Processing triggers for man-db (2.9.4-2) ...
Processing triggers for libc-bin (2.33-0ubuntu5) ...

Step 4: Install linux container package by using the following command

root@linuxhelp:~# apt install -y lxd
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following package was automatically installed and is no longer required:
  libllvm11
Use 'apt autoremove' to remove it.
The following NEW packages will be installed:
  lxd
0 upgraded, 1 newly installed, 0 to remove and 15 not upgraded.
Need to get 5,444 B of archives.
After this operation, 79.9 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu hirsute/universe amd64 lxd all 1:0.9 [5,444 B]
Fetched 5,444 B in 0s (33.6 kB/s)
Preconfiguring packages ...
Selecting previously unselected package lxd.
(Reading database ... 289303 files and directories currently installed.)
Preparing to unpack .../archives/lxd_1%3a0.9_all.deb ...
=> Installing the LXD snap
==> Checking connectivity with the snap store
==> Installing the LXD snap from the latest track for ubuntu-21.04
lxd 4.21 from Canonical* installed
=> Snap installation complete
==> Cleaning up leftovers
Failed to stop lxd.socket: Unit lxd.socket not loaded.
Failed to stop lxd.service: Unit lxd.service not loaded.
Failed to stop lxd-containers.service: Unit lxd-containers.service not loaded.
Failed to disable unit: Unit file lxd.socket does not exist.
Unpacking lxd (1:0.9) ...
Setting up lxd (1:0.9) ...

Step 5: Configure the linux container by using the following command

root@linuxhelp:~#  lxd init
Would you like to use LXD clustering? (yes/no) [default=no]: 
Do you want to configure a new storage pool? (yes/no) [default=yes]: 
Name of the new storage pool [default=default]: 
Name of the storage backend to use (ceph, btrfs, dir, lvm, zfs) [default=zfs]: 
Create a new ZFS pool? (yes/no) [default=yes]: 
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]: 
Size in GB of the new loop device (1GB minimum) [default=7GB]: 5GB
Would you like to connect to a MAAS server? (yes/no) [default=no]: 
Would you like to create a new local network bridge? (yes/no) [default=yes]: 
What should the new bridge be called? [default=lxdbr0]: 
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: 
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: 
Would you like the LXD server to be available over the network? (yes/no) [default=no]: 
Would you like stale cached images to be updated automatically? (yes/no) [default=yes] 
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]: 

Step 6: Listi the available containers

root@linuxhelp:~#  lxc list
To start your first container, try: lxc launch ubuntu:20.04
Or for a virtual machine: lxc launch ubuntu:20.04 --vm

+------+-------+------+------+------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+-------+------+------+------+-----------+

Step 7:Launch the Ubuntu 18:04 container by using the following command

root@linuxhelp:~#  lxc launch ubuntu:18.04 testserver
Creating testserver
Starting testserver      

Step 8:Listing the available containers

root@linuxhelp:~#  lxc list
+------------+---------+----------------------+----------------------------------------------+-----------+-----------+
|    NAME    |  STATE  |         IPV4         |                     IPV6                     |   TYPE    | SNAPSHOTS |
+------------+---------+----------------------+----------------------------------------------+-----------+-----------+
| testserver | RUNNING | 10.44.186.177 (eth0) | fd42:45e:652c:4c51:216:3eff:fed6:974a (eth0) | CONTAINER | 0         |
+------------+---------+----------------------+----------------------------------------------+-----------+-----------+

Step 9:Restart the container

root@linuxhelp:~#  lxc restart testserver

Step 10:Execute the container by using the following command

root@linuxhelp:~#  lxc shell testserver

Step 11:Check the OS version of the container by using the following command

root@testserver:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.6 LTS
Release:	18.04
Codename:	bionic

By this to launch Ubuntu 18.04 container on Ubuntu 21.04 has been completed

FAQ
Q
What are resources on namespaces?
A
Resources are process IDs, hostnames, user IDs, file names, and some names associated with network access, and interprocess communication.
Q
What is Namespaces?
A
Namespaces are a feature of the Linux kernel that partitions kernel resources such that one set of processes sees one set of resources while another set of processes sees a different set of resources.
Q
What is the fundamental aspect of containers on Linux
A
Namespaces are a fundamental aspect of containers on Linux.
Q
What is cgroups?
A
cgroups (abbreviated from control groups) is a Linux kernel feature that limits, accounts for, and isolates the resource usage (CPU, memory, disk I/O, network, etc.) of a collection of processes.
Q
What are Linux Containers?
A
Linux Containers (LXC) is an operating-system-level virtualization method for running multiple isolated Linux systems (containers) on a control host using a single Linux kernel