CentOS - LVM quick notes

Please refer to full documentation online - LVM Administrator's Guide

Am not responsible if you break your server by following my notes.

TIP: If not sure, always try on TEST server before running your commands on PRODUCTION.

SCENARIO: There is a Fresh install of CentOS on VM (TEST Server)

[root@localhost ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root  6.7G  1.1G  5.3G  17% /
tmpfs                         250M  4.0K  250M   1% /dev/shm
/dev/sda1                     485M   31M  430M   7% /boot

By default LVM is used.

REQUIREMENT: Add new logical volume to the server (use existing Volume Group called "VolGroup").

1. add new Virtual Hard Disk (at VMWARE or VIRTUALBOX level)
2. fdisk -l ( e.g newly added disk is /dev/sdb)
3. pvcreate /dev/sdb
4. pvs (verify)
5. vgextend VolGroup /dev/sdb
6. vgs (verify)
7. lvcreate -L 450M -n mydata VolGroup  (create new logical volume of 450MB named "mydata")
8. lvs (verify, view newly create lvm)
9. ls -l /dev/mapper/ (location of logical volumes)
10.mkfs.ext4 /dev/mapper/VolGroup-mydata (format the new logical volume with ext4)
11.mount /dev/mapper/VolGroup-mydata /mnt/data (mount)
12.vim /etc/fstab and add the following line:
/dev/mapper/VolGroup-mydata     /mnt/data       ext4    defaults        1 1

REQUIREMENT: Remove the newly added logical volume (Rollback above procedure)

1. umount /mnt/data
2. remove the following  line  from /etc/fstab
/dev/mapper/VolGroup-mydata     /mnt/data       ext4    defaults        1 1
3. lvremove /dev/mapper/VolGroup-mydata
4. vgreduce VolGroup /dev/sdb (Remove physical volume from volume group)
5. pvs (verify)
6. pvremove /dev/sdb (remove the LVM label)

Have a nice time with LVM :)