1

I'm using LXD few years and I'm glad to use this platform in my testing environment. But few days ago, I couldn't install Microsoft SQL server 2017. The reason was, that I used default ZFS backend.

Ok, I checked, that if I need ext4. I have to use LVM. No problem, I created "Volume Group" and i marked to use this group in LXD. But ... First problem, that I saw, that LXD creates logical volumes not more, than 10GB.

After this command,

lxc init ubuntu:16.04 container2

I received this volume:

Disk /dev/mapper/mainVG-containers_container2: 10 GiB, 10737418240 bytes, 20971520 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 65536 bytes / 65536 bytes

I tried to add size via lvextend:
lvextend -L +10G /dev/mapper/mainVG-containers_container2

But I received following error:

Logical volume containers_container2 not found in volume group mainVG

Ok, I tried to create logical volume without LXD.

I made:

lvcreate -n lv_data1 --size 12G mainVG

And received:

Disk /dev/mapper/mainVG-lv_data1: 12 GiB, 12884901888 bytes, 25165824 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

And I made:

lvextend -L +10G /dev/mapper/mainVG-lv_data1
  Size of logical volume mainVG/lv_data1 changed from 12.00 GiB (3072 extents) to 22.00 GiB (5632 extents).
  Logical volume mainVG/lv_data1 successfully resized.

As you can see, in this case I can successfully resize my logical volume.

Maybe I don't know something ?
Maybe I have to add something in some security group ? Can you help me please ?
If you know other way to resize my Logical Volume, I will glad to hear it from you. Thanks

kofemann
  • 4,308
  • 1
  • 21
  • 27
Piduna
  • 501
  • 3
  • 10
  • 23

2 Answers2

2

And there is another option. You can ask LXD to do the resize for you.

But it would not handle the resizing of the thinpool for you(if it isn't big enough).

root@hawk:~# lxc config set CONTAINER root size 100GB

Keep in mind, that in most cases, you need to restart the container.

And also, there is a limitation of LVM, if there are snapshots from this volume, you can not resize it, until they are removed.

  • This is the far better choice - see the discussion thread: https://discuss.linuxcontainers.org/t/resize-lxd-container/9424/17 It's a shame that LXC has such dreadfully terse documentation. – tink Aug 28 '22 at 21:14
0

You can simply extend the LV by using lvextend. Here is an example.

You start by heaving pool0 with 600GB storage and containers_mirrors volume with 10GB storage.

root@hawk:~# lvs
  LV                VG   Attr       LSize   Pool  Origin     Data%  Meta%  Move Log Cpy%Sync Convert
  containers_lugbg   main Vwi-a-tz--  10.00g pool0 images_15 8.31                                   
  containers_mirrors main Vwi-a-tz--  10.00g pool0 images_33 7.59                                   
  containers_ubuntu  main Vwi-aotz--  10.00g pool0 images_39 7.03                                   
  images_15          main Vwi-a-tz--  10.00g pool0           6.10
  images_33          main Vwi-a-tz--  10.00g pool0           5.86                                   
  images_39          main Vwi-a-tz--  10.00g pool0           6.22
  pool0              main twi-aotz-- 600.00g 0.63            3.39                            
  root               main -wi-ao----  40.00g                                                                                               

Then you extend the volume(containers_mirrors):

root@hawk:~# lvextend -L +800G main/containers_mirrors 
  WARNING: Sum of all thin volume sizes (880.00 GiB) exceeds the size of thin pool main/pool0 (600.00 GiB).
  WARNING: You have not turned on protection against thin pools running out of space.
  WARNING: Set activation/thin_pool_autoextend_threshold below 100 to trigger automatic extension of thin pools before they get full.
  Size of logical volume main/containers_mirrors changed from 10.00 GiB (2560 extents) to 810.00 GiB (207360 extents).
  Logical volume main/containers_mirrors successfully resized.

You may disregard the error if this is what you need, but in case you want to actually extend the thinpool, you now need to do:

root@hawk:~# lvextend -l +300G main/pool0
  Invalid argument for --extents: +300G
  Error during parsing of command line.
root@hawk:~# lvextend -L +300G main/pool0  
  Size of logical volume main/pool0_tdata changed from 600.00 GiB (153600 extents) to 900.00 GiB (230400 extents).
  Logical volume main/pool0_tdata successfully resized.

The result is now:

root@hawk:~# lvs
  LV                 VG   Attr       LSize   Pool  Origin    Data%  Meta%  Move Log Cpy%Sync Convert
  containers_lugbg   main Vwi-a-tz--  10.00g pool0 images_15 8.31
  containers_mirrors main Vwi-a-tz-- 810.00g pool0 images_33 0.09
  containers_ubuntu  main Vwi-aotz--  10.00g pool0 images_39 7.03
  images_15          main Vwi-a-tz--  10.00g pool0           6.10
  images_33          main Vwi-a-tz--  10.00g pool0           5.86
  images_39          main Vwi-a-tz--  10.00g pool0           6.22
  pool0              main twi-aotz-- 900.00g                 0.42   3.59
  root               main -wi-ao----  40.00g

Finally you need to resize the filesystem of the container, which is done with resize2fs. In order to prevent any problems, you should first stop the container:

root@hawk:~# lxc stop mirrors

Then check the fs:

root@hawk:~# e2fsck -f /dev/main/containers_mirrors
e2fsck 1.45.0 (6-Mar-2019)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/main/containers_mirrors: 16531/655360 files (0.2% non-contiguous), 203696/2621440 blocks

And finally resize the fs:

root@hawk:~# resize2fs /dev/main/containers_mirrors
resize2fs 1.45.0 (6-Mar-2019)
Resizing the filesystem on /dev/main/containers_mirrors to 212336640 (4k) blocks.
The filesystem on /dev/main/containers_mirrors is now 212336640 (4k) blocks long.