2022年12月16日 星期五

[btrfs, raid5, lxd] How to setup a RAID5 btrfs pool from 3 disks as LXD storage pool

  1. How to setup a RAID5 btrfs pool from 3 disks

    井民全, Jing, mqjing@gmall.com


    1. Quick

    1.1. Clean all disc

    lsblk #check all your block storage devices


    # umount all partitions

    declare -a  arr=("/dev/sda" "/dev/sdb" "/dev/sdc")

    for i in "${arr[@]}"; do echo "${i}";sudo umount "${i}"?; sudo wipefs --all --force "${i}"?; sudo wipefs --all --force "${i}"; done



    1.2. Install the system

    # install btrfs

    sudo apt-get install btrfs-progs  

    sudo mkfs.btrfs -L mybtrfs-pool -d raid5 -m raid5 -f /dev/sda /dev/sdb /dev/sdc


    # mount and create subvolume

    mkdir /home/pi/data

    sudo mount /dev/sdb /home/pi/data 

    sudo btrfs subvolume create /home/pi/data/sub1


    # create the lxd storage pool as the btrfs volume

    lxd init


    Interactive

    Name of hte new storage pool: mylxd-btrfspool

    Name of the existing BTRFS pool or dataset: /home/pi/data/sub1



    # fstab

    sudo btrfs filesystem show

    vi /etc/fstab

    UUID=56bd1605-9358-466d-b45c-a988957d7945 /home/pi/data           btrfs   defaults      0  0




    2. Procedure

    2.1. Step 1: Install BTRFS

    sudo apt-get install btrfs-progs

    E.g.


    2.2. Step 2: Create BTRFS pool with RAID-5 using three disks

    sudo mkfs.btrfs -L mybtrfs-pool -d raid5 -m raid5 -f /dev/sda /dev/sdb /dev/sdc


    E.g. 



    2.3. Step 3: Mount and create btrfs subvolume on it

    To mount the RAID-5 pool, you can reference either device when your file system contains multiple devices. Here, the /dev/sdb was chosen.

    mkdir /home/pi/data

    sudo mount /dev/sdb /home/pi/data 

    sudo btrfs subvolume create /home/pi/data/sub1


     

    2.4. Step 4 Create a new lxd storage pool


    lxd init


    Interactive

    Name of hte new storage pool: mylxd-btrfspool

    Name of the existing BTRFS pool or dataset: /home/pi/data/sub1





    2.4.1. Check the storage

    lxc storage list


    2.4.2. Check the storage size

    lxc  storage info mylxd-btrfspool


    3. Mounting the btrfs filesystem

    3.1. Get btrfs filesystem UUID

    sudo btrfs filesystem show

    E.g.


    3.2. Setup fstab

    We mount the mybtrfs-pool (56bd1605-9358-466d-b45c-a988957d7945) on /home/pi/data.

    vi /etc/fstab



    UUID=56bd1605-9358-466d-b45c-a988957d7945 /home/pi/data           btrfs   defaults      0  0



    4. References

    1. Mount & resize the btrfs system, https://www.thegeekdiary.com/centos-rhel-how-to-create-and-mount-btrfs-file-system-explained-with-examples/

    2. UUID=e7e5c123-fg76-5gxx-a87d-gt5fed9r768e /data           btrfs   defaults      0  0