Linux LVM

Prepare physical volume (where diskname = sda, sdb, sdc,…)

  1. dd if=/dev/zero of=/dev/diskname bs=1k count=1 (NOTE: this is destructive to all data on this disk)
  2. blockdev –rereadpt /dev/diskname
  3. pvcreate /dev/diskname

Prepare Volume Group

  1. vgcreate –s 1g my_vol_group /dev/diskname

    1. you can modify the extent size during vg creation

Create Logical Volume

Defined Size

  1. lvcreate –Lsize-in-MB –n lv-name my_vol_group

oracle es: lvcreate –L 8g –n olp2_u01xplv olp2_archxpvg

Defined Size with Stripes

  1. lvcreate –istripe-count –Istripe-size –lsize-in-extents –nlv-name my_vol_group

oracle stripe ex: lvcreate –i 3 –I 8 –l 10 –n olp2_u07xplv olp2_u07xpvg

natcat stripe es: lvcreate –i 5 –I 8 –L 175g –n olp2_u37xplv olp2_data37xpvg

Full Physical volume

  1. vgdisplay my_vol_group |grep “Total PE”
  2. lvcreate  -l count-from-above my_vol_group –nlv-name

Create a file system

mkfs -t ext3 /dev/vg00/<volume name>

oracle stripe ex: mkfs –t ext3 –b 4096 –R stride=2 device (rhel3)

oracle stripe ex: mkfs –t ext3 –b 4096 –E stride=2 –T largefile  device(rhel4)

NOTE:  only specify –T largefile on /u02-/u09 file systems for oracle, allow default every where else

Modify a file system

Use tune2fs tp change the defaults of fsck every 30 mounts or 180 days

Activate Volume Group

  1. after a reboot or vgchange –an you will need to active the volume group
  2. vgchange –a y my_vol_group

Remove a volume group

  1. make the volume group inactive
    1. vgchange –a n my_vol_group
  2. remove the group
    1. vgremove my_vol_group

Adding Physical Device to Volume Group

  1. vgextend my_vol_group /dev/diskname

Removing Physical Device from Volume Group

  1. vgreduce my_vol_groupe /dev/diskname

Remove Logical Volume

  1. umount /file/sysmtem
  2. lvremove /dev/my_vol_group/lv-name

Extend a volume

Extend to defined size

  1. lvextend –L12G /dev/my_vol_group/lv-name

Extend by specific amount

  1. lvextend –L+1G /dev/my_vol_group/lv-name

Extend a filesystem

  1. resize2fs /dev/my_vol_group/lv-name

Extend volume and filesystem (1 command; not valid in 3.0 for online resize)

  1. e2fsadm –L+1G /dev/my_vol_group/lv-name

Extend a RHEL 4.0 file systems

  1. ext2online /mount-point will extend FS to end of the volume

Reduce a filesystem

  1. umount /filesystem
  2. resize2fs /dev/my_vol_group/lv-name size-in-blocks

Reduce a volume

  1. must be done umounted and after filesystem reduction
  2. lvreduce –L-1G /dev/my_vol_group/lv-name

Reduce both volume and fileystem (1 command; not valid 3.0)

  1. umount /filesystem
  2. e2fsadm –L-1G /dev/my_vol_group/lv-name
  3. mount /filesystem

Review summary of physical devices (4.0 only)

  1. pvs will show summary of physical device and volume groups

Review summary of volume group(4.0 only)

  1. vgs will show summary of volume group

Review summary of logical volume(4.0 only)

1.  lvs will show summary of volume information

fdisk

  1. fdisk disk
  2. n to add a new disk
  3. choose your sizes
  4. t to change type
  5. w to write

swap space

  1. mkswap /dev/diskname
  2. swapon /dev/diskname
  3. fstab: /dev/diskname swap    swap    defaults 0 0

Decided mdadm would not do the job for you?

mdadm --create -f -lmp -n2 -x1 /dev/md0 /dev/<channela> /dev/<channelb>

This works in fail over mode by explicitly telling md to treat one as a spare. 

Helpful Volume Management Commands

  1. To get a full list of all volume groups in 3.0: vgdisplay –s
  2. to get a full list of all logical volumes in 3.0: lvscan

Example volume creation

I did this:

dd if=/dev/zero of=/dev/sda bs=1k count=1

pvcreate /dev/sda

vgcreate -s 8M vg_oralp01_u01 /dev/sda

lvcreate -L 13.74G -n lvu01 vg_oralp01_u01

vgchange -a y vg_oralp01_u01

mkfs -t ext3 /dev/vg_oralp01_u01/lvu01

Example volume extension

Note: RHEL3 does not support online resizing of ext3 filesystems, RHEL4 does

dd if=/dev/zero of=/dev/sdj bs=1k count=1

blockdev –rereadpt /dev/sdj

pvcreate /dev/sdj

vgextend  vg_oralp01_u01 /dev/sdj

vgdisplay vg_oralp01_u01|grep Free

umount /u01

e2fsadm -L+size_from_above /dev/vg_oralp01_u01/lvu01

mount /u01

Business Copy Procedures

  1. following a split, the volume group showed up and seemed valid
  2. the logical volume showed up but was flagged as inactive
  3. ran vgchange –ay <vgname>
    1. now volume is live and mounted
  4. looking good to go
  5. testing how to export/import volume group
    1. vgchange –an <vgname>
    2. vgexport <vgname>
    3. vgimport <vgname>
    4. vgchange –ay <vgname>

Leave a Comment

Your email address will not be published. Required fields are marked *

CAPTCHA * Time limit is exhausted. Please reload the CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top