This is a recurrent operation I’m doing regularly these time : extending a Linux partition by adding new virtual disk I’ve attached to a growing VM. Nothing fantastic to expect in this post. Its purpose is to keep on my hand the solution I’ve used to stop searching google and getting a different one every time ;).
This tuto is applicable for centos 7. The content will be updated when I’ll have to perform different operations.
Install LVM
yum install lvm2
With default tools
- PV – Physical Volume = raw disk
- VG – Volume Group = group of PV
- LV – Logical Volume, partition of VG we can mount
Initialize a PV:
- use fdisk to create a partition type 8e (LVM)
- create the associated PV with pvcreate /dev/sdxy
Create a VG
- vgcreate name_of_the_group /dev/sdxy /dev/sd..
- verify : vgdisplay
Create the LV
- lvcreate -n lv_name –size XXG vg_name or lvcreate -l 100%FREE vg_name
- verify : lvdisplay
- format: mkfs.ext4 /dev/vg_name/lv_name
- add in fstab
/dev/vg_name/lv_name /mount_point ext4 defaults 0 0
When it is expected to spread data across different VG in a Raid0 type LV
lvcreate --type raid0 -l 100%FREE --stripes 3 --stripesize 4 -n ln_name vg_name
stripes 3 option is indicating to spread across 3 PV of the VG stripesize 4 is for block of 4K
BTRFS can be used for compression:
Install on ubuntu : apt install btrfs-progs Create fs: mkfs.btrfs /dev/vg_name/lv_name Add in /etc/fstab /dev/vg_name/lv_name /mount_point btrfs defaults,compress 0 1
Install some tool for helping
# yum install system-storage-manager
Display the running configuration
# ssm list
Create a volume ready for being extended from scratch
Here is an example for a LVM Pool initialized with 1 drive
# ssm create -s 50G -n disk0 --fstype xfs -p pool-name /dev/sdX /mnt/point
we can add drives to the pool :
# ssm add -p pool-name /dev/sdX
Add the entry into the fstab
/dev/dm-0 /mnt/point xfs defaults 0 0
References
- http://xmodulo.com/manage-lvm-volumes-centos-rhel-7-system-storage-manager.html