Skip to content

Reduce BTRFS on LVM (quick recipe)

This is a quick recipe on reducing a btrfs FS inside a LMV structure.

First, the will reduce the “content”, then we will operate over the “container”.

This is the algorithm:

  1. umount /path/to/fs
  2. resize2fs /dev/mapper/vol SIZE (see man resize2fs)
  3. deactivate the volume
  4. lvreduce -L nG /dev/mapper/vol
  5. resize2fs /dev/mapper/vol nG

btrfs is actually considered “experimental”, but is included since stable kernel 3.0.0. Btrfs is the answer from the GNU/Linux community to Sun Microsystems ZFS. You will find more info on wikipedia:

http://es.wikipedia.org/wiki/Btrfs
http://es.wikipedia.org/wiki/ZFS_%28sistema_de_archivos%29

The Volume Group VGxen has 1,80 TiB within 2 volumes:

root (139,70 GiB)
datos (1,66 TiB)

We will reduce the FS contained in /dev/mapper/VGxen-datos.

[shell]
root@xen:~# vgdisplay
— Volume group —
VG Name VGxen
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 1,80 TiB
PE Size 4,00 MiB
Total PE 472068
Alloc PE / Size 472068 / 1,80 TiB
Free PE / Size 0 / 0
VG UUID mfys39-Kmpq-5qPC-dO1j-rXzm-cxRf-bP5qdo

root@xen:~#
root@xen:~#
root@xen:~#
root@xen:~# lvdisplay
— Logical volume —
LV Name /dev/VGxen/root
VG Name VGxen
LV UUID aG30Iz-Afyr-JNil-GILm-KOyh-4xEN-isuBsC
LV Write Access read/write
LV Status available
# open 1
LV Size 139,70 GiB
Current LE 35762
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 254:0

— Logical volume —
LV Name /dev/VGxen/datos
VG Name VGxen
LV UUID cD0Mmk-EHCb-tbii-4ije-wmTz-Du1Y-BF1hGk
LV Write Access read/write
LV Status available
# open 0
LV Size 1,66 TiB
Current LE 436306
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 254:1
[/shell]

Some info of th btrfs:

[shell]
root@xen:~# btrfsck /dev/mapper/VGxen-datos
found 29395595264 bytes used err is 0
total csum bytes: 28649972
total tree bytes: 58023936
total fs tree bytes: 10014720
btree space waste bytes: 10497514
file data blocks allocated: 211368005632
referenced 25943769088
Btrfs Btrfs v0.19
root@xen:~#
[/shell]

We will follow 4 simple steps:

  1. Umount FS
  2. (not needed in btrfs, we can do it with the FS already mounted! :-DD)

  3. Reduce the FS
  4. [shell]
    root@xen:~# btrfsctl -r 500g /MaquinasVirtuales/
    operation complete
    Btrfs Btrfs v0.19
    root@xen:~#
    [/shell]

  5. Reduce the volumen
  6. [shell]
    root@xen:~# umount /MaquinasVirtuales

    root@xen:~# lvreduce -L 512G /dev/mapper/VGxen-datos
    WARNING: Reducing active logical volume to 512,00 GiB
    THIS MAY DESTROY YOUR DATA (filesystem etc.)
    Do you really want to reduce datos? [y/n]: y
    Reducing logical volume datos to 512,00 GiB
    Logical volume datos successfully resized
    root@xen:~#
    [/shell]

  7. Readjust the FS size
  8. [shell]
    root@xen:~# btrfsctl -r max /MaquinasVirtuales/
    operation complete
    Btrfs Btrfs v0.19
    root@xen:~#
    [/shell]

    Now, VGxen has free space.

Published inlinux