Does it make sense to put btrfs on lvm?

32,884

Maybe this explains ( from the btrfs wiki by the way )

A subvolume in btrfs is not the same as an LVM logical volume or a ZFS subvolume. With LVM, a logical volume is a block device in its own right (which could for example contain any other filesystem or container like dm-crypt, MD RAID, etc.) - this is not the case with btrfs. A btrfs subvolume is not a block device (and cannot be treated as one) instead, a btrfs subvolume can be thought of as a POSIX file namespace. This namespace can be accessed via the top-level subvolume of the filesystem, or it can be mounted in its own right.

see also https://btrfs.wiki.kernel.org/index.php/FAQ

Interaction with partitions, device managers and logical volumes

Btrfs has subvolumes, does this mean I don't need a logical volume manager and I can create a big Btrfs filesystem on a raw partition?

There is not a single answer to this question. Here are the issues to think about when you choose raw partitions or LVM:

  • Performance
    • raw partitions are slightly faster than logical volumes
    • btrfs does write optimisation (sequential writes) across a filesystem subvolume write performance will benefit from this algorithm creating multiple btrfs filesystems, each on a different LV, means that the algorithm can be ineffective (although the kernel will still perform some optimization at the block device level)
  • Online resizing and relocating the filesystem across devices: the pvmove command from LVM allows filesystems to move between devices while online
    • raw partitions can only be moved to a different starting cylinder while offline
    • raw partitions can only be made bigger if there is free space after the partition, while LVM can expand an LV onto free space anywhere in the volume group - and it can do the resize online
  • subvolume/logical volume size constraints
    • LVM is convenient for creating fixed size logical volumes (e.g. 10MB for each user, 20GB for each virtual machine image, etc)
    • subvolumes don't currently enforce such rigid size constraints, although the upcoming qgroups feature will address this issue

.... the FAQ continues to explain the scenario's in which LVM+BTRFS make sense

Share:
32,884

Related videos on Youtube

r0berts
Author by

r0berts

I am a hobbyist in statistical programming and my main field is psychological medicine. I like the StackExchange community. What else - oh, yes, I am a linux fan and most computers I have run linux on them - Manjaro or Debian.

Updated on September 18, 2022

Comments

  • r0berts
    r0berts over 1 year

    This is OpenSUSE Leap 42. I have a computer with 2x 500 GB SATA HDD drives and to speed it up I put in a small 30GB SSD drive for the system. During installation HDDs were disconnected as they confused the installer (and me). Once system was up I quite easily exchanged the /home directory for a XFS logical volume (I use LVM primarily to add space easily). Then /opt filled up (chrome and botanicula) and I wanted to put that on a volume on HDD. So I created a volume and formatted it with BTRFS. After some head scratching - the @ subvolumes in fstab made me read up on BTRFS I did what I needed - /opt now is 100 GB in size.

    But the question is: Does it make sense to format a LVM volume with btrfs? Essentially they both are volume handling systems.

    For illustration I paste my fstab (# comments show my edits) and vgscan + lvscan output:

    ~> cat /etc/fstab
    
    UUID=1b511986-9c20-4885-8385-1cc03663201b swap swap defaults 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af / btrfs defaults 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /boot/grub2/i386-pc btrfs subvol=@/boot/grub2/i386-pc 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /boot/grub2/x86_64-efi bt
    
    rfs subvol=@/boot/grub2/x86_64-efi 0 0
    UUID=3e103686-52e9-44ac-963f-5a76177af56b /opt                 btrfs      defaults              0 0
    #UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /opt btrfs subvol=@/opt 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /srv btrfs subvol=@/srv 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /tmp btrfs subvol=@/tmp 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /usr/local btrfs subvol=@/usr/local 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /var/crash btrfs subvol=@/var/crash 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /var/lib/libvirt/images btrfs subvol=@/var/lib/libvirt/images 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /var/lib/mailman btrfs subvol=@/var/lib/mailman 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /var/lib/mariadb btrfs subvol=@/var/lib/mariadb 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /var/lib/mysql btrfs subvol=@/var/lib/mysql 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /var/lib/named btrfs subvol=@/var/lib/named 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /var/lib/pgsql btrfs subvol=@/var/lib/pgsql 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /var/log btrfs subvol=@/var/log 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /var/opt btrfs subvol=@/var/opt 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /var/spool btrfs subvol=@/var/spool 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /var/tmp btrfs subvol=@/var/tmp 0 0
    UUID=30e20531-b7f1-4bde-b2d2-fab8eeca23af /.snapshots btrfs subvol=@/.snapshots 0 0
    UUID=c4c4f819-a548-4881-b854-a0ed62e7952e /home     xfs defaults 1 2
    #UUID=e14edbfa-ddc2-4f6d-9cba-245d828ba8aa /home                xfs        defaults              1 2
    

    ~>

    # vgscan
      Reading all physical volumes.  This may take a while...
      Found volume group "r0data" using metadata type lvm2
      Found volume group "r0sys" using metadata type lvm2
    
    # lvscan
      ACTIVE            '/dev/r0data/homer' [699.53 GiB] inherit
      ACTIVE            '/dev/r0sys/optr' [100.00 GiB] inherit
    

    After the answer: Thanks, I understand now the key differences. To me LVM is indeed better for managing space with whatever filesystems on top of it, but BTRFS should be used for features specific to it - mainly snapshots. In simple home network use it is probably better to stay away from it. I've had too much grief managing space on a small drive, but I'd imagine space would be eaten away also on big drives.

  • r0berts
    r0berts over 7 years
    Thanks, I understand now the key differences. LVM is indeed better for managing space with whatever filesystems on top of it, but BTRFS should be used for features specific to it - mainly snapshots. In simple home network use it is probably better to stay away from it.