CentOS 8.x create or extend lvm partition with striping

From Notes_Wiki

Home > CentOS > CentOS 8.x > System Administration > Filesystem management > CentOS 8.x create or extend lvm partition with striping

Create striped lvm partition

In case of physical disks (not in case of central storage where LUNs are coming from same pool), we can increase performance of a partition by doing striping (RAID 0) over various independent disks. To configure the same use below steps: (In below example doing striping over 4 disks. The RAID 0 can be done from 2 to a large no. of disks 6+).

  1. Add multiple disks to be used as PVs to the machine.
  2. Optionally, Only in case of KVM VM we can add disks using:
    1. Shutdown the VM. If we dont shutdown we get error such as:
      error: Failed to attach disk
      error: internal error: No more available PCI slots
    2. Create disks
      qemu-img create -f qcow2 testdisk01.qcow2 1G
      qemu-img create -f qcow2 testdisk02.qcow2 1G
      qemu-img create -f qcow2 testdisk03.qcow2 1G
      qemu-img create -f qcow2 testdisk04.qcow2 1G
    3. Attach disks to VM using domain-name:
      sudo virsh attach-disk <vm-domain-name> $PWD/testdisk01.qcow2 vdb --driver qemu --subdriver qcow2 --targetbus virtio --persistent
      sudo virsh attach-disk <vm-domain-name> $PWD/testdisk02.qcow2 vdc --driver qemu --subdriver qcow2 --targetbus virtio --persistent
      sudo virsh attach-disk <vm-domain-name> $PWD/testdisk03.qcow2 vdd --driver qemu --subdriver qcow2 --targetbus virtio --persistent
      sudo virsh attach-disk <vm-domain-name> $PWD/testdisk04.qcow2 vde --driver qemu --subdriver qcow2 --targetbus virtio --persistent
      Change vdb, vdc, etc. appropriately based on existsing no. and naming of disks
    4. Power on the VM
  3. SSH/Connect to machine and Validate that required no. of disks of matching size are visible
    fdisk -l
  4. Create physical volume on appropriate disks
    pvcreate /dev/vdb
    pvcreate /dev/vdc
    pvcreate /dev/vdd
    pvcreate /dev/vde
    Again replace names vdb-vde with approporiate names
  5. Create volume group using the PVs
    vgcreate vgtest /dev/vd[b-e]
    vgdisplay -v vgtest | grep -i name
    In case of production give appropriate name instead of vgtest. Replace vdb-e with correct names based on environment.
  6. Create LV with 4 partitions in striping using:
    lvcreate -l '100%VG' -i 4 -n lvtest vgtest
    lvdisplay -m vgtest/lvtest
  7. Create filesystem xfs or ext4 based on requirement
    mkfs.ext4 /dev/mapper/vgtest-lvtest
    #OR mkfs.xfs /dev/mapper/vgtest-lvtest
  8. Mount and test the new partition
    mkdir /mnt/test
    mount /dev/mapper/vgtest-lvtest /mnt/test/
    df -h
    In production names would be different and also add /etc/fstab entry with UUID (blkid command)


Extending the lvm partition

  1. Add same no. of more disks to the server / VM for extension.
  2. Optionally, Only in case of KVM VM we can add disks using:
    1. Shutdown the VM. If we dont shutdown we get error such as:
      error: Failed to attach disk
      error: internal error: No more available PCI slots
    2. Create disks
      qemu-img create -f qcow2 testdisk05.qcow2 3G
      qemu-img create -f qcow2 testdisk06.qcow2 3G
      qemu-img create -f qcow2 testdisk07.qcow2 3G
      qemu-img create -f qcow2 testdisk08.qcow2 3G
    3. Attach disks to VM using domain-name:
      sudo virsh attach-disk <vm-domain-name> $PWD/testdisk05.qcow2 vdf --driver qemu --subdriver qcow2 --targetbus virtio --persistent
      sudo virsh attach-disk <vm-domain-name> $PWD/testdisk06.qcow2 vdg --driver qemu --subdriver qcow2 --targetbus virtio --persistent
      sudo virsh attach-disk <vm-domain-name> $PWD/testdisk07.qcow2 vdh --driver qemu --subdriver qcow2 --targetbus virtio --persistent
      sudo virsh attach-disk <vm-domain-name> $PWD/testdisk08.qcow2 vdi --driver qemu --subdriver qcow2 --targetbus virtio --persistent
      Change vdf, vdg, etc. appropriately based on existsing no. and naming of disks
    4. Power on the VM
  3. SSH/Connect to machine and Validate that required no. of disks of matching size are visible
    fdisk -l
  4. Create physical volume on appropriate disks
    pvcreate /dev/vdf
    pvcreate /dev/vdg
    pvcreate /dev/vdh
    pvcreate /dev/vdi
    Again replace names vdb-vde with approporiate names
  5. Mount the partion if not done already
    mount /dev/mapper/vgtest-lvtest /mnt/test/
    df -h
  6. Extend vg with pvs
    vgextend vgtest /dev/vd[f-i]
    vgdisplay -v vgtest | grep -i name
  7. Extend lvm using
    lvextend -l '100%VG' vgtest/lvtest
    lvdisplay -m vgtest/lvtest
    Here -l is for extents. If we want to use size then we can use -L. For example to increase size by 30GB we can use 'lvextend -L +30G <device>'. Note the + in front of 30 to indicate increase.
  8. (Alternatively) Resize both Logical partition and filesystem using:
    lvextend -l '100%VG' --resizefs vgtest/lvtest
    This is very good as we dont have to resize file-system separately. Both partition and filesystem get resized in a single step.
  9. Extend filesystem using
    resize2fs /dev/mapper/vgtest-lvtest
    #OR xfs_grow /dev/mapper/vgtest-lvtest
    #OR btrfs filesystem resize max /
  10. Validate the new size
    df -h
    #OR btrfs filesystem usage /


Refer:


Home > CentOS > CentOS 8.x > System Administration > Filesystem management > CentOS 8.x create or extend lvm partition with striping