目的
ZFS の lxc storage の拡張方法を備忘録として残す
参考資料
忙しい人向け
# 準備 # zpool コマンドがなければインストール sudo apt install zfsutils-linux # POOL_NAME を確認する lxc config device show CONTAINER_NAME # POOL_NAME の SOURCE を確認する lxc storage list # POOL_NAME の DEVICE_ID を取得する sudo zpool status -vg POOL_NAME # 拡張する sudo truncate -s +SIZE SOURCE sudo zpool set autoexpand=on POOL_NAME sudo zpool online -e POOL_NAME DEVICE_ID sudo zpool set autoexpand=off POOL_NAME
現状確認
syntax highlight のために、分割しています
takashi@mini01:~$ lxc list c1 +------+---------+------+------+-----------+-----------+ | NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS | +------+---------+------+------+-----------+-----------+ | c1 | RUNNING | | | CONTAINER | 0 | +------+---------+------+------+-----------+-----------+ takashi@mini01:~$
takashi@mini01:~$ lxc storage info test-pool info: description: "" driver: zfs name: test-pool space used: 659.26MiB total space: 9.20GiB used by: images: - 6de3bbd44fa9fdaeef6e5a96b03bb0c09b59b6be7d594bcd3beb92c1956250b6 instances: - c1 takashi@mini01:~$ takashi@mini01:~$ lxc storage show test-pool config: size: 5GB source: /var/snap/lxd/common/lxd/disks/test-pool.img zfs.pool_name: test-pool description: "" name: test-pool driver: zfs used_by: - /1.0/images/6de3bbd44fa9fdaeef6e5a96b03bb0c09b59b6be7d594bcd3beb92c1956250b6 - /1.0/instances/c1 status: Created locations: - none takashi@mini01:~$
takashi@mini01:~$ lxc exec c1 -- df -hT | grep -i -e type -e zfs Filesystem Type Size Used Avail Use% Mounted on test-pool/containers/c1 zfs 9.2G 648M 8.6G 7% / takashi@mini01:~$
ということで、 test-pool
をもつ c1
コンテナでテストする
lxc storage show POOL_NAME
コマンドの config -> size
には、設定が書いてあるだけで、現在の容量ではないので注意
用意するパラメータ
SOURCE
POOL_NAME
DEVICE_ID
が必要
SOURCE
/var/snap/*/POOL_NAME.img
のファイルである
確認方法
# 下記コマンドの source を見る lxc storage list # もしくは下記コマンドの config -> source を見る lxc storage show POOL_NAME
ということで、今回の SOURCE
パラメータはこれ
/var/snap/lxd/common/lxd/disks/test-pool.img
POOL_NAME
storage pool の名前である
lxc で container を作るときに指定することもあるだろうが、コマンドで確認するなら以下だろう
lxc config device show CONTAINER_NAME
今回では以下
root -> pool
の値が POOL_NAME
となる
takashi@mini01:~$ lxc config device show c1 root: path: / pool: test-pool type: disk takashi@mini01:~$
なので test-pool
が今回の対象 POOL_NAME
DEVICE_ID
zpool
コマンドが必要
sudo apt install zfsutils-linux
でインストールすること
確認コマンドは以下
sudo zpool status -vg POOL_NAME
今回の場合は以下
takashi@mini01:~$ sudo zpool status -vg test-pool [sudo] password for takashi: pool: test-pool state: ONLINE config: NAME STATE READ WRITE CKSUM test-pool ONLINE 0 0 0 1086430804337025345 ONLINE 0 0 0 errors: No known data errors takashi@mini01:~$
で、この結果の
1086430804337025345
これが DEVICE_ID
である
手順
sudo truncate -s +SIZE SOURCE sudo zpool set autoexpand=on POOL_NAME sudo zpool online -e POOL_NAME DEVICE_ID sudo zpool set autoexpand=off POOL_NAME
やっていき
今回は 10GB 増量する
現在は 10GB(9.2GiB)
である
sudo truncate -s +10GB /var/snap/lxd/common/lxd/disks/test-pool.img sudo zpool set autoexpand=on test-pool sudo zpool online -e test-pool 1086430804337025345 sudo zpool set autoexpand=off test-pool
特段のエラーなしで終わった
takashi@mini01:~$ sudo truncate -s +10GB /var/snap/lxd/common/lxd/disks/test-pool.img takashi@mini01:~$ sudo zpool set autoexpand=on test-pool takashi@mini01:~$ sudo zpool online -e test-pool 1086430804337025345 takashi@mini01:~$ sudo zpool set autoexpand=off test-pool takashi@mini01:~$
確認する
lxc の pool デバイスの容量
lxc storage info POOL_NAME
結果
takashi@mini01:~$ lxc storage info test-pool info: description: "" driver: zfs name: test-pool space used: 659.34MiB total space: 17.92GiB used by: images: - 6de3bbd44fa9fdaeef6e5a96b03bb0c09b59b6be7d594bcd3beb92c1956250b6 instances: - c1 takashi@mini01:~$
増えている
GiB
なので少なく見える点に注意
コンテナ内部からも見てみる
lxc exec CONTANER_NAME -- df -hT | grep -i -e type -e zfs
結果
takashi@mini01:~$ lxc exec c1 -- df -hT | grep -i -e type -e zfs Filesystem Type Size Used Avail Use% Mounted on test-pool/containers/c1 zfs 18G 648M 18G 4% / takashi@mini01:~$
できてる
感想
素晴らしい
オンラインで出来るのとても良い
lxc はこの調子でどんどん機能追加して欲しい