Tux on VM

Last updated on:
Sunday, July 06, 2008

Software

Information

Community

News

Fun

Credits




Valid HTML 4.01!
Linux for Big Iron

Sample LVM Scripts

This information was contributed by Jim Sibley on June 28, 2002. A similar example can be found in Chapter 17 of the Linux for zSeries and S/390: Distributions, SG24-6264 Redbook.

Details of each command can be found using the man command.

The 7 scripts below show the 7 steps in implementing an LVM volume group with four (4) logical 8 GB volumes striped over 16 physical volumes.
  1. vgscan initializes LVM and looks for existing LVM structures
  2. pvcreate creates LVM physical volumes
  3. vgcreate creates a volume group
  4. vgextend adds the rest of the volumes to the volume group
  5. lvcreate creates 4 volumes, 8 gb each, striped over 16 physical volumes
  6. mkfs puts a file system on the volume
  7. mount mounts the logical volumes
If you need to move the LVM structure to another system, then put the new volumes in the appropriate zipl.conf or parmfile. After IPL, run vgscan. vgscan will show which volume groups are available, but they may not be active. To activate them, issue "vgchange -a y vgname".

Disclaimer: This may not be the optimal configuration for your installation and the scripts need to be manually modified to get the results you may want. No warranty is given or implied.

Sample Bash Scripts

  1. vgscan
    #!/bin/bash
    # 1-vgscan
    # setup up LVM and scan for existing configurations
    vgscan
         
  2. pvcreate
    #!/bin/bash
    # 2-pvcreate - the files system names must be changed to coincide with the 
    # volumes mounted by your system
    pvcreate -v /dev/dasdx1
    pvcreate -v /dev/dasdy1
    pvcreate -v /dev/dasdz1
    pvcreate -v /dev/dasdaa1
    pvcreate -v /dev/dasdab1
    pvcreate -v /dev/dasdac1
    pvcreate -v /dev/dasdad1
    pvcreate -v /dev/dasdae1
    pvcreate -v /dev/dasdaf1
    pvcreate -v /dev/dasdag1
    pvcreate -v /dev/dasdah1
    pvcreate -v /dev/dasdai1
    pvcreate -v /dev/dasdaj1
    pvcreate -v /dev/dasdak1
    pvcreate -v /dev/dasdal1
    pvcreate -v /dev/dasdam1
         
  3. vgcreate
    #!/bin/bash
    # 3-vgcreate
    # this script builds a volume group with a single physical volume. Additonal
    # volumes are added by 4-vgextend
    #
    vgchange -a n vgname
    vgremove vgname
    vgcreate -s 256k -v vgname /dev/dasdx1
    #
    # the -s parameter (PE size) determines the maximum logical volume size
    # so the maximum logical volume size is 65,536 x PE size
    # The logical volume has a maximum size of 65,536 Physical Elements (PE's),
    # (64K PE size x 65,536 = 4 GB)
    #  PE	Maximum
    #  size	logical Vol
    #  	size 
    #  512M	32,768 GB	absolute max
    #  32M	2,048 GB	linux 2.4.7 kernel limit
    #  4M	256 GB
    #  1M	64 GB
    #  512K	32 GB
    #  256K	16 GB
    #  128K	8 GB
    #  64K	4 GB
    #  32K 	2 GB
    #  16K	1 GB
    #  8K	512 MB
         
  4. vgextend
    #!/bin/bash
    # 4-vgextend
    vgextend vgname /dev/dasdx1
    vgextend vgname /dev/dasdy1
    vgextend vgname /dev/dasdz1
    vgextend vgname /dev/dasdaa1
    vgextend vgname /dev/dasdab1
    vgextend vgname /dev/dasdac1
    vgextend vgname /dev/dasdad1
    vgextend vgname /dev/dasdae1
    vgextend vgname /dev/dasdaf1
    vgextend vgname /dev/dasdag1
    vgextend vgname /dev/dasdah1
    vgextend vgname /dev/dasdai1
    vgextend vgname /dev/dasdaj1
    vgextend vgname /dev/dasdak1
    vgextend vgname /dev/dasdal1
    vgextend vgname /dev/dasdam1
         
  5. lvcreate
    #!/bin/bash
    # 5-lvcreate
    # create 4 logical volumes
    # -i 16 - 16 stripes
    # -I 16 - 16K per stripe
    # -L 8g - 8 gb logical volumes
    # - n   - logical volumes name (if -n is omitted, names would be lvol1 to 4)
    lvcreate -i 16 -I 16 -L 8g -v vgname -n lvol1
    lvcreate -i 16 -I 16 -L 8g -v vgname -n lvol2
    lvcreate -i 16 -I 16 -L 8g -v vgname -n lvol3
    lvcreate -i 16 -I 16 -L 8g -v vgname -n lvol4
         
  6. mkfs
    #!/bin/bash
    # 6-mkfs
    mke2fs -b 4096 /dev/vgname/lvol1
    mke2fs -b 4096 /dev/vgname/lvol2
    mke2fs -b 4096 /dev/vgname/lvol3
    mke2fs -b 4096 /dev/vgname/lvol4
         
  7. mount
    #!/bin/bash
    # 7-mount
    mkdir -p /mnt/lvmvol1
    mkdir -p /mnt/lvmvol2
    mkdir -p /mnt/lvmvol3
    mkdir -p /mnt/lvmvol4
    e2fsck -p /dev/vgname/lvol1
    e2fsck -p /dev/vgname/lvol2
    e2fsck -p /dev/vgname/lvol3
    e2fsck -p /dev/vgname/lvol4
    mount /dev/vgname/lvol1 /mnt/lvmvol1
    mount /dev/vgname/lvol2 /mnt/lvmvol2
    mount /dev/vgname/lvol3 /mnt/lvmvol3
    mount /dev/vgname/lvol4 /mnt/lvmvol4
         
 

Site hosting courtesy of Velocity Software