Create the VG consisting of 2 block devices (a slow and a fast)

apt install lvm2 &&
vg="vg_$(hostname)" &&
cat /proc/partitions &&
echo -n 'slow disk: ' && read slow &&
echo -n 'fast disk: ' && read fast &&
vgcreate "$vg" "$slow" "$fast"

Create the srv LV, but leave a few (like 50?) extents empty on the slow disk. (lvconvert needs this extra free space later. That's probably a bug.)

pvdisplay &&
echo -n "#extents: " && read extents &&
lvcreate -l "$extents" -n srv "$vg" "$slow"

The -cache-meta disk should be 1/1000 the size of the -cache LV. (if it is slightly more that also shouldn't hurt.)

lvcreate -L 100MB -n srv-cache-meta "$vg" "$fast" &&
lvcreate -l '100%FREE' -n srv-cache "$vg" "$fast"

setup caching

lvconvert --type cache-pool --cachemode writethrough --poolmetadata "$vg"/srv-cache-meta "$vg"/srv-cache

lvconvert --type cache --cachepool "$vg"/srv-cache "$vg"/srv


Assume we want to grow this partition to take the available free space in the PV:

root@vineale:/srv# lvs
  LV   VG         Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  srv  vg_vineale -wi-ao---- 35,00g                                                    
root@vineale:/srv# pvs
  PV         VG         Fmt  Attr PSize  PFree
  /dev/sdb   vg_vineale lvm2 a--  40,00g 5,00g
root@vineale:~# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sdb
  VG Name               vg_vineale
  PV Size               40,00 GiB / not usable 4,00 MiB
  Allocatable           yes 
  PE Size               4,00 MiB
  Total PE              10239
  Free PE               1279
  Allocated PE          8960
  PV UUID               CXKO15-Wze1-xY6y-rOO6-Tfzj-cDSs-V41mwe

extend the volume group

The procedures below assume there is free space on the volume group for the operation. If there isn't you will need to add disks to the volume group, and grow the physical volume. For example:

pvcreate /dev/md123
vgextend vg_vineale /dev/md123

If the underlying disk was grown magically without your intervention, which happens in virtual hosting environments, you can also just extend the physical volume:

pvextend /dev/sdb

Note that if there's an underlying crypto layer, it needs to be resized as well:

cryptsetup resize $DEVICE_LABEL

In this case, the $DEVICE_LABEL is the device's name in /etc/crypttab, not the device name. For example, it would be /dev/mapper/crypt_sdb, not /dev/sdb.

See also the upstream documentation.

online procedure (ext3 and later)

Online resize has been possible ever since ext3 came out and it considered reliable enough for use. If you are unsure that you can trust that procedure, or if you have an ext2 filesystem, do not use this procedure and see the ext2 procdure below instead.

To resize the partition to take up all available free space, you should do the following:

  1. extend the partition, in case of a logical volume:

    lvextend vg_vineale/srv -L +5G

    This might miss some extents, however. You can use the extent notation to take up all free space instead:

    lvextend vg_vineale/srv -l +1279

    If the partition sits directly on disk, use parted's resizepart command or fdisk to resize that first.

  2. resize the filesystem:

    resize2fs /dev/mapper/vg_vineale-srv

That's it! The resize2fs program automatically determines the size of the underlying "partition" (the logical volume, in most cases) and fixes the filesystem to fill the space.

Note that the resize process can take a while. Growing an active 20TB partition to 30TB took about 5 minutes, for example. The -p flag that could show progress only works in the "offline" procedure (below).

offline procedure (ext2)

To resize the partition to take up all available free space, you should do the following:

  1. stop services and processes using the partition (will obviously vary):

    service apache2 stop
  2. unmount the filesystem:

    umount /srv
  3. check the filesystem:

    fsck -y -f /dev/mapper/vg_vineale-srv
  4. extend the filesystem using the extent notation to take up all available space:

    lvextend vg_vineale/srv -l +1279
  5. grow the filesystem (-p is for "show progress"):

    resize2fs -p /dev/mapper/vg_vineale-srv
  6. recheck the filesystem:

    fsck  -f -y /dev/mapper/vg_vineale-srv
  7. remount the filesystem and start processes:

    mount /srv
    service apache2 start