2009-08-13

LINUX LVM

1 Create LVM partition

1.1 Create LVM partition:

  • fdisk /dev/[disk]
  • change partition type from LINUX to LVM

1.2 Initialize LVM partition:

  • pvcreate /dev/[disk_partiton1] /dev/[disk_partition2]
  • verifycommands:
    • pvs
    • pvdisplay

1.3 Create LVM group:

  • vgcreate [group_name] /dev/[disk_partition1] /dev/[disk_partition2]
  • verify commands:
    • vgs
    • vgdisplay

1.4 Create logical volumes which is attached to group:

  • lvcreate -L[size]M -n [vol_name] [group_name]
  • verify commands:
    • lvs
    • lvdisplay

1.5 Volume format:

  • mkfs.ext3 [lv_name_from_lvdisplay]

2 Snapshot

2.1 Desc

  • Snapshot covers process of writing block to special area before writing to this block, so if you want to make changes to block at first you must copy this block to special area
  • So it is neccesary to set volume snapshot size, and when it will be full the snapshot is broken

2.2 Steps

  1. lvcreate -s -L[size]G -n [lv_snap] /dev/[vg_name]/[lv_2snap]
  2. dd if=/dev/[vg_name]/[lv_snap] of=[file_name].img
    • The size of file is similar to "lvdisplay /dev/[vg_name]/[lv_snap]"
    • If snapshot size is oversized the warning is "input/ouput error"
  3. lvcreate -n [lv_new] -L[size_bigger_then_above] [vg_name]
    • It is possible to expand by resize2fs
  4. dd if=[file_name].img of=/dev/[vg_name]/[lv_new]
  5. lvremove /dev/[vg_name]/[lv_snap]

3 Move data inside group

  1. pvs
  2. pvmove /dev/sd...
  3. pvs

4 Remove disk from group

  • lvreduce [vg_name] /dev/sd...

5 Add disk to group

  1. pvcreate /dev/sd...
  2. pvs
  3. vgextend [vg_name] /dev/sd...

6 Reduce volume size

  1. umount...
  2. e2fsck -f /dev/[vg_name]/[lv_name]
  3. resize2fs /dev/[vg_name]/[lv_name] [nr]G
  4. lvreduce -L[nr]G /dev/[vg_name]/[lv_name]
  5. mount...

7 Extend volume size

  1. lvextend /dev/[vg_name]/[lv_name]
  2. e2fsck -f /dev/[vg_name]/[lv_name]
  3. resize2fs /dev/[vg_name\/[lv_name]

8 Activate group

  • vgscan
  • vgchange -ay

9 Extend partition

  • fdisk
  • d #remove partition
  • n #make a new one with start section at the same point