2022年12月14日 星期三

[lxd, zfs, pool, expand] How to expand the lxd default zfs pool capacity

How to expand the LXD default zfs pool capacity 

井民全, Jing, mqjing@gmail.com

FAQ:  The Docker, KVM, Vagrant, VirtualBox, VMWare, Hyper-V

You can follow the instructions to expand the LXD default zfs pool capacity if it is not enough. 


Table of contents

1. Quick 1

2. Procedure 2

2.1. Step 1: Stop all running containers 2

2.2. Step 2: Resize the storage device 3

2.2.1. Get the virtual disk location 3

2.2.2. Resize the device 3

2.3. Step 3: Expand the pool size 4

2.4. Step 4: Restart all containers 5

3. References 5




1. Quick

# stop all container

lxd list # get the container name

lxd stop ubuntu-container


# resize the virtual disk

zpool status  # get the virtual disk location

sudo ls -la  /var/snap/lxd/common/lxd/disks/default.img  # check the original size

sudo truncate -s +20G /var/snap/lxd/common/lxd/disks/default.img

sudo ls -la  /var/snap/lxd/common/lxd/disks/default.img  # check the expended size


# expend the pool

zpool list  # check size

sudo zpool status -vg default # get the device id for the pool

sudo zpool online -e default 14277165744894305174 #  aware the zfs 


# check the pool capacity

zpool list


# restart containers

lxd start ubuntu-container


2. Procedure

2.1. Step 1: Stop all running containers

E.g.

lxd list


lxd stop ubuntu-container


2.2. Step 2: Resize the storage device

Here, this is a virtual disk. 

2.2.1. Get the virtual disk location

zpool status


2.2.2. Resize the device

sudo ls -la  /var/snap/lxd/common/lxd/disks/default.img  # check the original size

sudo truncate -s +20G /var/snap/lxd/common/lxd/disks/default.img

sudo ls -la  /var/snap/lxd/common/lxd/disks/default.img  # check the expended size


E.g. 

Fig.Before expending the file size.

Fig. After expanding the file size.

2.3. Step 3: Expand the pool size

zpool list  # check size

sudo zpool status -vg default # get the device id for the pool

sudo zpool online -e default 14277165744894305174 #  aware the zfs 

Fig. Chck the default pool capacit. 

Fig. Get the pool device ID.


Fig. Run the pool expansion.


Verification

zpool list

Fig. Check the capacity after 

2.4. Step 4: Restart all containers

lxc start ubuntu-container 


3. References

  1. https://discuss.linuxcontainers.org/t/how-to-resize-zfs-used-in-lxd/1333/10

  2. https://sites.google.com/site/itmyshare/storage/storage-disk/zfs-device-autoreplace-and-autoexpand

  3. https://docs.oracle.com/cd/E19253-01/819-5461/githb/index.html