Monday, May 27, 2013

Logical Volume basic command

Create LVM

show all HDD currently available
# fdisk -cul

select hdd that you wish to make into LVM
# fdisk -cu /dev/sdb

create partition and set it the system type to LVM
# p  ( print all partition )
# n  ( create new partition )
# t  ( change system type )
# 8e ( change it to LVM type )
# w  ( save it )

After done, you will see /dev/sdb1 was created
now we proceed to create LVM
# pvcreate /dev/sdb1
# vgcreate vg00 /dev/sdb1
This will create a volume group name vg00

# lvcreate -L 10G --name lvdata vg00
This will create a logical volume name lvdata with 10G size from vg00

# mkfs.ext4  /dev/mapper/vg00-lvdata
This will format the LV we created to ext4 format so we can use it

------------------------------------------------------------------------

Replace HDD for LVM


# pvscan
# vgextend vg00 /dev/xvdk1 
# pvmove /dev/xvdf1
# vgreduce vg00 /dev/xvdf1
#  pvremove /dev/xvdf1



------------------------------------------------------------------------

Adding existing VG into new server

# vgexport vg00
# vgimport vg00
# vgchange -ay vg00

-----------------------------------------------------------------------

Reduce LV

# unmount /home
# e2fsck -f /dev/mapper/vg00-lvhome
# resize2fs -p /dev/mapper/vg00-lvhome 3G
# lvreduce -L 3G /dev/mapper/vg00-lvhome
# e2fsck -f /dev/mapper/vg00-lvhome

----------------------------------------------------------------------

Extend LV

#  lvextend -l +100%FREE /dev/mapper/vg00-lvvar
# resize2fs -p /dev/mapper/vg00-lvvar