Lvm

From Notepedia
Jump to: navigation, search

Creating a Logic Volume

First run cfdisk and convert to LVM partitions, then

# lvm
# lvm> pvcreate /dev/sdaX /dev/sdaY
# lvm> vgcreate davavg /dev/sdaX /dev/sdaY 
# lvm> lvcreate --name downloads --size 40G datavg

To maximise all space in the that VG in just one LV use the following command

# lvm> lvcreate --name backup -l 100%FREE datavg

This will write the file system to the LVM partiton:

# mkfs.ext4 /dev/datavg/downloads

Edit /etc/fstab and mount the partitons mount -a, done!

To Disable and enable LVM Volume Groups

Best done when pulling out the drives etc... doe this *after* unmounting

To disable Volume Groups (Optional Name, otherwise it will disable all VG's)

# /sbin/vgchange -a n <Optional_VG_Name>

To enable them again:

# /sbin/vgchange -a y <Optional_VG_Name>

To Disable and enable Logic Volumes

  • first* make sure you unount

List the Logic Volumes to see what's happening

# lvdisplay


To disable Volume Groups (Optional Name, otherwise it will disable all VG's)

# lvchange -a n <LV_Name>

To enable them again:

# lvchange -a y <LV_Name>


To Extend the LV

First see how much room in the PV you have to play with, this shows 598 Gigs free in the PV unused

# pvs
  PV         VG     Fmt  Attr PSize PFree  
  /dev/md0   datavg lvm2 a-   2.73T 598.73G

Next give the LV of your choice more room, we give total amounts, you can also use +0.5G to add that much, so this:

# lvextend -L1.5G /dev/datavg/downloads

OR, this:

# lvextend --size +150G /dev/datavg/video 
  Extending logical volume video to 1.99 TB
  Logical volume video successfully resize

Unmount

# umount /dev/datavg/downloads

Disk check for ext2/3/4

# e2fsck -f /dev/datavg/downloads 
Grow EXT filesystem disk
# resize2fs /dev/datavg/downloads

Remount

# mount -a
Grow XFS filesystem disk

It's slightly different to grow an xfs file system:

# xfs_growfs /location/of/partition

Excellent How Tos

http://www.howtoforge.com/linux_lvm
http://tldp.org/HOWTO/LVM-HOWTO/
http://tldp.org/HOWTO/LVM-HOWTO/extendlv.html

This how to combines LVM and mdadm:
http://linuxdevcenter.com/pub/a/linux/2006/04/27/managing-disk-space-with-lvm.html