我正在尝试按照以下容器创建一个 LXC 容器。
我可以创建容器并启动它。但是当我df-h
从 lxc 容器执行命令时,我可以看到它具有与主机相同的文件系统名称(如何更改?)。
我的问题很简单,如何为创建的容器指定磁盘空间,以便磁盘有一个限制,就像在 openvz 中创建容器时我们可以同时指定磁盘空间一样。
我曾尝试添加
lxc-create -n test01 -t /usr/local/share/templates/lxc-centos --dir=/home/images/lxc/test01 -B lvm --fssize=2G
,但它不允许我创建它。
它允许我使用以下命令创建隔离容器
lxc-create -n test01 -t /usr/local/share/templates/lxc-centos -dir=/home/images/lxc/test01
,但无法知道容器的实际分配空间。
我被困在这一步。
任何帮助深表感谢。
答案1
答案2
下面是一个示例,说明如何将现有的 LXC 容器映像的大小从 30GB 调整为 40GB,以及如何将存储池的大小从 30GB 调整为 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:~#