Closed3

[記事化済み] Debian12 で LXC と LXD を試す。

mnodmnod

Debian12 で LXC を試す

Raspi の KVM仮想マシンとして動かしている Debian12 (aarch64) にLXC インストールし、試してみます。

# uname -a
Linux debian12test 6.1.0-10-arm64 #1 SMP Debian 6.1.37-1 (2023-07-03) aarch64 GNU/Linux

# cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

LXCをインストールする。

# apt install lxc

インストールされたテンプレートの一覧

# ls -l /usr/share/lxc/templates                                                                                                                           
total 576
-rwxr-xr-x 1 root root 13630 May 24  2022 lxc-alpine
-rwxr-xr-x 1 root root 14184 May 24  2022 lxc-altlinux
-rwxr-xr-x 1 root root 11234 May 24  2022 lxc-archlinux
-rwxr-xr-x 1 root root  8601 Jan 17 11:53 lxc-busybox
-rwxr-xr-x 1 root root 30633 May 24  2022 lxc-centos
-rwxr-xr-x 1 root root 10368 May 24  2022 lxc-cirros
-rwxr-xr-x 1 root root 30414 May 24  2022 lxc-debian
-rwxr-xr-x 1 root root 25469 May 24  2022 lxc-devuan
-rwxr-xr-x 1 root root 14497 Jan 17 11:53 lxc-download
-rwxr-xr-x 1 root root 41919 May 24  2022 lxc-fedora
-rwxr-xr-x 1 root root 49755 May 24  2022 lxc-fedora-legacy
-rwxr-xr-x 1 root root 28405 May 24  2022 lxc-gentoo
-rwxr-xr-x 1 root root 24509 May 24  2022 lxc-kali
-rwxr-xr-x 1 root root  7178 Jan 17 11:53 lxc-local
-rwxr-xr-x 1 root root 10737 Jan 17 11:53 lxc-oci
-rwxr-xr-x 1 root root 13893 May 24  2022 lxc-openmandriva
-rwxr-xr-x 1 root root 16877 May 24  2022 lxc-opensuse
-rwxr-xr-x 1 root root 41706 May 24  2022 lxc-oracle
-rwxr-xr-x 1 root root 14170 May 24  2022 lxc-plamo
-rwxr-xr-x 1 root root 13967 May 24  2022 lxc-pld
-rwxr-xr-x 1 root root 14277 May 24  2022 lxc-sabayon
-rwxr-xr-x 1 root root 19300 May 24  2022 lxc-slackware
-rwxr-xr-x 1 root root 26656 May 24  2022 lxc-sparclinux
-rwxr-xr-x 1 root root  6845 May 24  2022 lxc-sshd
-rwxr-xr-x 1 root root 26276 May 24  2022 lxc-ubuntu
-rwxr-xr-x 1 root root 11747 May 24  2022 lxc-ubuntu-cloud
-rwxr-xr-x 1 root root  6018 May 24  2022 lxc-voidlinux

試しにUbuntu のコンテナを作成する。

# lxc-create -n debian-test -t debian

# lxc-ls -f
NAME        STATE   AUTOSTART GROUPS IPV4 IPV6 UNPRIVILEGED 
debian-test STOPPED 0         -      -    -    false        

コンテナを起動する。

# lxc-start -n debian-test -d

# lxc-ls -f
NAME        STATE   AUTOSTART GROUPS IPV4       IPV6 UNPRIVILEGED 
debian-test RUNNING 0         -      10.0.3.197 -    false        

コンテナに入る。

# lxc-attach -n debian-test

コンテナの内容を確認する。

# uname -a
Linux debian-test 6.1.0-10-arm64 #1 SMP Debian 6.1.37-1 (2023-07-03) aarch64 GNU/Linux

# cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

コンテナを停止する。

# lxc-stop -n debian-test

# lxc-ls -f
NAME        STATE   AUTOSTART GROUPS IPV4 IPV6 UNPRIVILEGED 
debian-test STOPPED 0         -      -    -    false        

コンテナを破棄する。

# lxc-destroy -n debian-test
mnodmnod

Debian12 で LXD を試す

LXD をインストールする。

# apt install lxd

初期化する。

# 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]: 
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]: 

ストレージプールを確認する。

# lxc storage list
+---------+--------+------------------------------------+-------------+---------+---------+
|  NAME   | DRIVER |               SOURCE               | DESCRIPTION | USED BY |  STATE  |
+---------+--------+------------------------------------+-------------+---------+---------+
| default | dir    | /var/lib/lxd/storage-pools/default |             | 1       | CREATED |
+---------+--------+------------------------------------+-------------+---------+---------+

# lxc storage info default
info:
  description: ""
  driver: dir
  name: default
  space used: 2.23GiB
  total space: 14.26GiB
used by:
  profiles:
  - default

仮想ブリッジを確認する

# lxc network list
+--------+----------+---------+-----------------+---------------------------+-------------+---------+---------+
|  NAME  |   TYPE   | MANAGED |      IPV4       |           IPV6            | DESCRIPTION | USED BY |  STATE  |
+--------+----------+---------+-----------------+---------------------------+-------------+---------+---------+
| enp0s1 | physical | NO      |                 |                           |             | 0       |         |
+--------+----------+---------+-----------------+---------------------------+-------------+---------+---------+
| lxcbr0 | bridge   | NO      |                 |                           |             | 0       |         |
+--------+----------+---------+-----------------+---------------------------+-------------+---------+---------+
| lxdbr0 | bridge   | YES     | 10.183.160.1/24 | fd42:be09:2f7d:46a9::1/64 |             | 1       | CREATED |
+--------+----------+---------+-----------------+---------------------------+-------------+---------+---------+

# lxc network info lxdbr0
Name: lxdbr0
MAC address: 00:16:3e:fb:9a:cc
MTU: 1500
State: up
Type: broadcast

IP addresses:
  inet  10.183.160.1/24 (global)
  inet6 fd42:be09:2f7d:46a9::1/64 (global)

Network usage:
  Bytes received: 0B
  Bytes sent: 0B
  Packets received: 0
  Packets sent: 0

Bridge:
  ID: 8000.00163efb9acc
  STP: false
  Forward delay: 1500
  Default VLAN ID: 1
  VLAN filtering: true
  Upper devices: 
# ip link show lxdbr0
6: lxdbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:16:3e:fb:9a:cc brd ff:ff:ff:ff:ff:ff

# ip address show lxdbr0
6: lxdbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 00:16:3e:fb:9a:cc brd ff:ff:ff:ff:ff:ff
    inet 10.183.160.1/24 scope global lxdbr0
       valid_lft forever preferred_lft forever
    inet6 fd42:be09:2f7d:46a9::1/64 scope global 
       valid_lft forever preferred_lft forever

プロファイルを確認する

# lxc profile list
+---------+---------------------+---------+
|  NAME   |     DESCRIPTION     | USED BY |
+---------+---------------------+---------+
| default | Default LXD profile | 1       |
+---------+---------------------+---------+

# lxc profile show default
config: {}
description: Default LXD profile
devices:
  eth0:
    name: eth0
    network: lxdbr0
    type: nic
  root:
    path: /
    pool: default
    type: disk
name: default
used_by:
- /1.0/instances/debian-test

イメージの確認

# lxc image list images:debian/12/arm64
+--------------------+--------------+--------+----------------------------------------+--------------+-----------------+----------+-------------------------------+
|       ALIAS        | FINGERPRINT  | PUBLIC |              DESCRIPTION               | ARCHITECTURE |      TYPE       |   SIZE   |          UPLOAD DATE          |
+--------------------+--------------+--------+----------------------------------------+--------------+-----------------+----------+-------------------------------+
| debian/12 (7 more) | 06b024a46661 | yes    | Debian bookworm arm64 (20230711_05:24) | aarch64      | CONTAINER       | 91.25MB  | Jul 11, 2023 at 12:00am (UTC) |
+--------------------+--------------+--------+----------------------------------------+--------------+-----------------+----------+-------------------------------+
| debian/12 (7 more) | 80c8a7734360 | yes    | Debian bookworm arm64 (20230711_05:24) | aarch64      | VIRTUAL-MACHINE | 337.31MB | Jul 11, 2023 at 12:00am (UTC) |
+--------------------+--------------+--------+----------------------------------------+--------------+-----------------+----------+-------------------------------+

# lxc image show images:debian/12/arm64
auto_update: false
properties:
  architecture: arm64
  description: Debian bookworm arm64 (20230711_05:24)
  os: Debian
  release: bookworm
  serial: "20230711_05:24"
  type: squashfs
  variant: default
public: true
expires_at: 1970-01-01T00:00:00Z
profiles: []

# lxc image info images:debian/12/arm64                                                                                                                    
Fingerprint: 06b024a4666144fd637928f9e092066037d1bbb7ae5127bf20082c792195dacc
Size: 91.25MB
Architecture: aarch64
Type: container
Public: yes
Timestamps:
    Created: 2023/07/11 00:00 UTC
    Uploaded: 2023/07/11 00:00 UTC
    Expires: never
    Last used: never
Properties:
    description: Debian bookworm arm64 (20230711_05:24)
    type: squashfs
    os: Debian
    release: bookworm
    architecture: arm64
    serial: 20230711_05:24
    variant: default
Aliases:
    - debian/bookworm/default
    - debian/bookworm/default/arm64
    - debian/12/default
    - debian/12/default/arm64
    - debian/bookworm
    - debian/bookworm/arm64
    - debian/12
    - debian/12/arm64
Cached: no
Auto update: disabled
Profiles: []
# lxc image list ubuntu:jammy/arm64
+------------+--------------+--------+---------------------------------------------+--------------+-----------------+----------+-------------------------------+
|   ALIAS    | FINGERPRINT  | PUBLIC |                 DESCRIPTION                 | ARCHITECTURE |      TYPE       |   SIZE   |          UPLOAD DATE          |
+------------+--------------+--------+---------------------------------------------+--------------+-----------------+----------+-------------------------------+
| j (9 more) | 4166efc1661c | yes    | ubuntu 22.04 LTS arm64 (release) (20230616) | aarch64      | CONTAINER       | 417.02MB | Jun 16, 2023 at 12:00am (UTC) |
+------------+--------------+--------+---------------------------------------------+--------------+-----------------+----------+-------------------------------+
| j (9 more) | a154c2142bb3 | yes    | ubuntu 22.04 LTS arm64 (release) (20230616) | aarch64      | VIRTUAL-MACHINE | 636.19MB | Jun 16, 2023 at 12:00am (UTC) |
+------------+--------------+--------+---------------------------------------------+--------------+-----------------+----------+-------------------------------+

# lxc image show ubuntu:jammy/arm64
auto_update: false
properties:
  architecture: arm64
  description: ubuntu 22.04 LTS arm64 (release) (20230616)
  label: release
  os: ubuntu
  release: jammy
  serial: "20230616"
  type: squashfs
  version: "22.04"
public: true
expires_at: 2027-06-01T00:00:00Z
profiles: []

# lxc image info ubuntu:jammy/arm64                                                                                                                        
Fingerprint: 4166efc1661cc063b26cedb7fabc1aa9a1c2d814b4acb20b5b7d317a53f995f3
Size: 417.02MB
Architecture: aarch64
Type: container
Public: yes
Timestamps:
    Created: 2023/06/16 00:00 UTC
    Uploaded: 2023/06/16 00:00 UTC
    Expires: 2027/06/01 00:00 UTC
    Last used: never
Properties:
    release: jammy
    version: 22.04
    architecture: arm64
    label: release
    serial: 20230616
    description: ubuntu 22.04 LTS arm64 (release) (20230616)
    type: squashfs
    os: ubuntu
Aliases:
    - 22.04
    - 22.04/arm64
    - j
    - j/arm64
    - jammy
    - jammy/arm64
    - lts
    - lts/arm64
    - default
    - default/arm64
Cached: no
Auto update: disabled
Profiles: []

コンテナの起動

# lxc launch images:debian/12 debian-test

# lxc list
+-------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
|    NAME     |  STATE  |         IPV4          |                     IPV6                      |   TYPE    | SNAPSHOTS |
+-------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+
| debian-test | RUNNING | 10.183.160.241 (eth0) | fd42:be09:2f7d:46a9:216:3eff:fea6:a024 (eth0) | CONTAINER | 0         |
+-------------+---------+-----------------------+-----------------------------------------------+-----------+-----------+

# lxc info debian-test
Name: debian-test
Status: RUNNING
Type: container
Architecture: aarch64
PID: 43302
Created: 2023/07/12 18:30 JST
Last Used: 2023/07/12 18:30 JST

Resources:
  Processes: 8
  CPU usage:
    CPU usage (in seconds): 2
  Memory usage:
    Memory (current): 38.19MiB
  Network usage:
    eth0:
      Type: broadcast
      State: UP
      Host interface: veth971c5b13
      MAC address: 00:16:3e:a6:a0:24
      MTU: 1500
      Bytes received: 2.12kB
      Bytes sent: 3.07kB
      Packets received: 14
      Packets sent: 27
      IP addresses:
        inet:  10.183.160.241/24 (global)
        inet6: fd42:be09:2f7d:46a9:216:3eff:fea6:a024/64 (global)
        inet6: fe80::216:3eff:fea6:a024/64 (link)
    lo:
      Type: loopback
      State: UP
      MTU: 65536
      Bytes received: 0B
      Bytes sent: 0B
      Packets received: 0
      Packets sent: 0
      IP addresses:
        inet:  127.0.0.1/8 (local)
        inet6: ::1/128 (local)

コンテナに接続する

# lxc exec debian-test -- /bin/bash
# uname -a
Linux distrobuilder-4e47e116-ac8a-4b83-9a0a-b35d5386a547 6.1.0-10-arm64 #1 SMP Debian 6.1.37-1 (2023-07-03) aarch64 GNU/Linux

# cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

コンテナのコンフィグの確認

# lxc config show debian-test
architecture: aarch64
config:
  image.architecture: arm64
  image.description: Debian bookworm arm64 (20230711_05:24)
  image.os: Debian
  image.release: bookworm
  image.serial: "20230711_05:24"
  image.type: squashfs
  image.variant: default
  volatile.base_image: 06b024a4666144fd637928f9e092066037d1bbb7ae5127bf20082c792195dacc
  volatile.cloud-init.instance-id: ac15cfc4-c2e0-4975-be81-097881849578
  volatile.eth0.host_name: veth971c5b13
  volatile.eth0.hwaddr: 00:16:3e:a6:a0:24
  volatile.idmap.base: "0"
  volatile.idmap.current: '[{"Isuid":true,"Isgid":false,"Hostid":165536,"Nsid":0,"Maprange":10000001},{"Isuid":false,"Isgid":true,"Hostid":165536,"Nsid":0,"Maprange":10000001}]'
  volatile.idmap.next: '[{"Isuid":true,"Isgid":false,"Hostid":165536,"Nsid":0,"Maprange":10000001},{"Isuid":false,"Isgid":true,"Hostid":165536,"Nsid":0,"Maprange":10000001}]'
  volatile.last_state.idmap: '[]'
  volatile.last_state.power: RUNNING
  volatile.uuid: 7d63d041-c162-4e4f-80f9-302fc3cf4056
devices: {}
ephemeral: false
profiles:
- default
stateful: false
description: ""

ネットワーク、ストレージプール、イメージの確認

# lxc network show lxdbr0
config:
  ipv4.address: 10.183.160.1/24
  ipv4.nat: "true"
  ipv6.address: fd42:be09:2f7d:46a9::1/64
  ipv6.nat: "true"
description: ""
name: lxdbr0
type: bridge
used_by:
- /1.0/instances/debian-test
- /1.0/profiles/default
managed: true
status: Created
locations:
- none
# lxc storage info default                                                                                                                                 
info:
  description: ""
  driver: dir
  name: default
  space used: 2.75GiB
  total space: 14.26GiB
used by:
  instances:
  - debian-test
  profiles:
  - default
# lxc image list  
+-------+--------------+--------+----------------------------------------+--------------+-----------+---------+------------------------------+
| ALIAS | FINGERPRINT  | PUBLIC |              DESCRIPTION               | ARCHITECTURE |   TYPE    |  SIZE   |         UPLOAD DATE          |
+-------+--------------+--------+----------------------------------------+--------------+-----------+---------+------------------------------+
|       | 06b024a46661 | no     | Debian bookworm arm64 (20230711_05:24) | aarch64      | CONTAINER | 91.25MB | Jul 12, 2023 at 5:51am (UTC) |
+-------+--------------+--------+----------------------------------------+--------------+-----------+---------+------------------------------+

# lxc image show 06b024a46661
auto_update: true
properties:
  architecture: arm64
  description: Debian bookworm arm64 (20230711_05:24)
  os: Debian
  release: bookworm
  serial: "20230711_05:24"
  type: squashfs
  variant: default
public: false
expires_at: 1970-01-01T00:00:00Z
profiles:
- default

# lxc image info 06b024a46661
Fingerprint: 06b024a4666144fd637928f9e092066037d1bbb7ae5127bf20082c792195dacc
Size: 91.25MB
Architecture: aarch64
Type: container
Public: no
Timestamps:
    Created: 2023/07/11 00:00 UTC
    Uploaded: 2023/07/12 05:51 UTC
    Expires: never
    Last used: 2023/07/12 09:30 UTC
Properties:
    description: Debian bookworm arm64 (20230711_05:24)
    os: Debian
    release: bookworm
    serial: 20230711_05:24
    type: squashfs
    variant: default
    architecture: arm64
Aliases:
Cached: yes
Auto update: enabled
Source:
    Server: https://images.linuxcontainers.org
    Protocol: simplestreams
    Alias: debian/12
Profiles:
    - default

コンテナを停止する

# lxc stop debian-test

# lxc list
+-------------+---------+------+------+-----------+-----------+
|    NAME     |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |
+-------------+---------+------+------+-----------+-----------+
| debian-test | STOPPED |      |      | CONTAINER | 0         |
+-------------+---------+------+------+-----------+-----------+

コンテナの削除

# lxc delete debian-test
このスクラップは2025/01/19にクローズされました