1

I am trying to create an LXC container by following the below containers.

"Introduction to Containers on Linux using LXC"

I am able to create the container and start it. But when I execute the df-h command from lxc container I can see that it has the same file system name as of the host machine (how to change that? ).

My query is simple, how to specify a disk space for the container created, so that the disk has a limit, like in openvz when we create a container we can specify the diskspace along with it.

I have tried to add

lxc-create -n test01 -t /usr/local/share/templates/lxc-centos --dir=/home/images/lxc/test01 -B lvm --fssize=2G

, but it is not allowing me to create it..

It is allowing me to create the isolated container by using the following command

lxc-create -n test01 -t /usr/local/share/templates/lxc-centos -dir=/home/images/lxc/test01

, but unable to know the actual allotted space for the container.
I am stuck with this step.

Any help is much appreciated.

1
  • I am not able to add the disk quota limit and the memory limit for each container. It still uses the entire host disk space and memory Feb 6, 2017 at 17:16

2 Answers 2

0

I was able to limit space for a container with the following command

lxc-create -B loop -t debian -n mydebianvm --fssize=5G -- -r buster

I had to read the man page more than once to understand to use loop. I find it does give you the impression that you can use lvm, but it didn't work for me either.

I struggle with trying to understand how to expand the disk once created. I think it work more with expanding the disk pool more than the container itself. lxc documentation is not easy to find, not LXD, but LXC. All online search mostly wraps around linuxcontainers, but they talk more about LXD that is a service on top of LXC.

Here is a howto that I found useful.

0

Below is an example how one can resize an existing LXC container image from 30GB to 40GB and also resize the storage pool from 30GB to 40GB.

# ls -latrh /var/lib/lxd/disks/default.img 
-rw------- 1 root root 30G Sep 15 12:54 /var/lib/lxd/disks/default.img
# qemu-img info /var/lib/lxd/disks/default.img 
image: /var/lib/lxd/disks/default.img
file format: raw
virtual size: 30 GiB (32212254720 bytes)
disk size: 11.7 GiB
Child node '/file':
    filename: /var/lib/lxd/disks/default.img
    protocol type: file
    file length: 30 GiB (32212254720 bytes)
    disk size: 11.7 GiB
#
# qemu-img resize /var/lib/lxd/disks/default.img 40G
WARNING: Image format was not specified for '/var/lib/lxd/disks/default.img' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
# qemu-img resize -f raw /var/lib/lxd/disks/default.img 40G
Image resized.
# qemu-img info /var/lib/lxd/disks/default.img 
image: /var/lib/lxd/disks/default.img
file format: raw
virtual size: 40 GiB (42949672960 bytes)
disk size: 11.7 GiB
Child node '/file':
    filename: /var/lib/lxd/disks/default.img
    protocol type: file
    file length: 40 GiB (42949672960 bytes)
    disk size: 11.7 GiB
#
# ls -latrh /var/lib/lxd/disks/default.img 
-rw------- 1 root root 40G Sep 15 13:00 /var/lib/lxd/disks/default.img
#

# lxc storage list
+---------+--------+--------------------------------+-------------+---------+---------+
|  NAME   | DRIVER |             SOURCE             | DESCRIPTION | USED BY |  STATE  |
+---------+--------+--------------------------------+-------------+---------+---------+
| default | btrfs  | /var/lib/lxd/disks/default.img |             | 3       | CREATED |
+---------+--------+--------------------------------+-------------+---------+---------+
# lxc storage info default
info:
  description: ""
  driver: btrfs
  name: default
  space used: 11.95GiB
  total space: 30.00GiB
used by:
  images:
  - 70afa800b43588184693c38eafb46c6e3484c561fe901150c29615608ecfe504
  instances:
  - bionic
  profiles:
  - default
#

$ lxc storage get default size
30GiB
$ lxc storage set default size 40GB
$ lxc storage get default size
40GB
$
$ lxc storage info default
info:
  description: ""
  driver: btrfs
  name: default
  space used: 11.95GiB
  total space: 30.00GiB
used by:
  images:
  - 70afa800b43588184693c38eafb46c6e3484c561fe901150c29615608ecfe504
  instances:
  - bionic
  profiles:
  - default
$ lxc profile list
+---------+---------------------+---------+
|  NAME   |     DESCRIPTION     | USED BY |
+---------+---------------------+---------+
| default | Default LXD profile | 1       |
+---------+---------------------+---------+
$

$ lxc profile show default
config:
  limits.cpu: "2"
  limits.memory: 4GB
description: Default LXD profile
devices:
  eth0:
    name: eth0
    network: lxdbr0
    type: nic
  root:
    path: /
    pool: default
    size: 50GB
    type: disk
name: default
used_by:
- /1.0/instances/bionic
$ lxc storage info default
info:
  description: ""
  driver: btrfs
  name: default
  space used: 11.95GiB
  total space: 30.00GiB
used by:
  images:
  - 70afa800b43588184693c38eafb46c6e3484c561fe901150c29615608ecfe504
  instances:
  - bionic
  profiles:
  - default
$ 
$ lxc storage edit default
$ lxc start bionic
$ lxc exec bionic -- sudo -i
root@bionic:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.8G     0  1.8G   0% /dev
tmpfs           367M  692K  366M   1% /run
/dev/sda2        45G  9.5G   36G  22% /
tmpfs           1.8G     0  1.8G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           1.8G     0  1.8G   0% /sys/fs/cgroup
tmpfs            50M   18M   33M  36% /run/incus_agent
/dev/sda1        99M  4.0M   95M   4% /boot/efi
tmpfs           367M     0  367M   0% /run/user/1001
root@bionic:~#
1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Sep 15 at 12:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .