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+).
- Add multiple disks to be used as PVs to the machine.
- Optionally, Only in case of KVM VM we can add disks using:
- 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
- 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
- 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
- Power on the VM
- Shutdown the VM. If we dont shutdown we get error such as:
- SSH/Connect to machine and Validate that required no. of disks of matching size are visible
- fdisk -l
- 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
- 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.
- Create LV with 4 partitions in striping using:
- lvcreate -l '100%VG' -i 4 -n lvtest vgtest
- lvdisplay -m vgtest/lvtest
- Create filesystem xfs or ext4 based on requirement
- mkfs.ext4 /dev/mapper/vgtest-lvtest
- #OR mkfs.xfs /dev/mapper/vgtest-lvtest
- 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
- Add same no. of more disks to the server / VM for extension.
- Optionally, Only in case of KVM VM we can add disks using:
- 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
- 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
- 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
- Power on the VM
- Shutdown the VM. If we dont shutdown we get error such as:
- SSH/Connect to machine and Validate that required no. of disks of matching size are visible
- fdisk -l
- 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
- Mount the partion if not done already
- mount /dev/mapper/vgtest-lvtest /mnt/test/
- df -h
- Extend vg with pvs
- vgextend vgtest /dev/vd[f-i]
- vgdisplay -v vgtest | grep -i name
- 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.
- (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.
- Extend filesystem using
- resize2fs /dev/mapper/vgtest-lvtest
- #OR xfs_grow /dev/mapper/vgtest-lvtest
- #OR btrfs filesystem resize max /
- Validate the new size
- df -h
- #OR btrfs filesystem usage /
Refer:
- https://www.basezap.com/create-lvm-using-striping-io/
- https://debiantjw.blogspot.com/2016/07/attach-qcow2-disk-to-kvm-guest-with.html
- https://unix.stackexchange.com/questions/570166/libvirtd-no-more-available-pci-slots
- https://www.suse.com/support/kb/doc/?id=000018798
Home > CentOS > CentOS 8.x > System Administration > Filesystem management > CentOS 8.x create or extend lvm partition with striping