Linux LVM

IBM has given parts of the AIX LVM to Linux, so it would only stand to reason that there is a set of AIX-like commands for linux to use. This shows how to basically create a filesystem. A more comprehensive introduction to LVM is at:

HowtoForge

I have created 4 new partitions and got them available to linux for a test:

cd /dev
ls
brw-r----- 1 root disk   8,  32 Nov  3 10:52 sdc
brw-r----- 1 root disk   8,  48 Nov  3 10:52 sdd
brw-r----- 1 root disk   8,  64 Nov  3 10:52 sde
brw-r----- 1 root disk   8,  80 Nov  3 10:52 sdf

And the LVM command that I find are:

lvm
lvmchange
lvmdiskscan
lvmsadc
lvmsar

pvchange
pvcreate
pvdisplay
pvmove
pvremove
pvresize
pvs
pvscan

vgcfgbackup
vgcfgrestore
vgchange
vgck
vgconvert
vgcreate
vgdisplay
vgexport
vgextend
vgimport
vgmerge
vgmknodes
vgreduce
vgremove
vgrename
vgs
vgscan
vgsplit

I start with pvcreate:

 pvcreate /dev/sdc /dev/sdd /dev/sde /dev/sdf
  Physical volume "/dev/sdc" successfully created
  Physical volume "/dev/sdd" successfully created
  Physical volume "/dev/sde" successfully created
  Physical volume "/dev/sdf" successfully created

Next I display what I have done:

 pvdisplay
  --- Physical volume ---
  PV Name               /dev/sdb1
  VG Name               system
  PV Size               15.00 GB / not usable 0
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              3839
  Free PE               24
  Allocated PE          3815
  PV UUID               Vydyz4-Njvf-6Wyk-Xl2s-UQM1-VcG4-Gbdk9a

  --- NEW Physical volume ---
  PV Name               /dev/sdc
  VG Name
  PV Size               3.75 GB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               dYMnY2-V4By-N21v-s4Bh-nfMz-TKOp-xrmT2s

I already had one volume created (sdb1) and it clearly shows up a little different. The new
ones all say ‘NEW’ for one thing, and don’t yet show Allocatable, probably because they aren’t associated with a logical volume yet. First, they need a volume group, though:

vgcreate testvg /dev/sdc /dev/sdd /dev/sde /dev/sdf
  Volume group "testvg" successfully created

And the display command shows what we did:

vgdisplay
  --- Volume group ---
  VG Name               system
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  2
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               15.00 GB
  PE Size               4.00 MB
  Total PE              3839
  Alloc PE / Size       3815 / 14.90 GB
  Free  PE / Size       24 / 96.00 MB
  VG UUID               F8PeFV-TIJj-YHqB-SpYv-Qxgn-UuwH-yE8eQH

Just like in AIX, the volume group can now be split into logical volumes:

lvcreate --name testlv1 --size 2G testvg
  Logical volume "testlv1" created
lvcreate --name testlv2 --size 2G testvg
  Logical volume "testlv2" created
lvdisplay
  --- Logical volume ---
  LV Name                /dev/testvg/testlv1
  VG Name                testvg
  LV UUID                ixjAYJ-A8Uz-CUga-OCmo-HBvv-OaC0-wkR0pN
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                2.00 GB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:1

The maps flag is probably something close to AIX’s lsvg -l:

lvdisplay --maps
  --- Logical volume ---
  LV Name                /dev/testvg/testlv1
  VG Name                testvg
  LV UUID                ixjAYJ-A8Uz-CUga-OCmo-HBvv-OaC0-wkR0pN
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                2.00 GB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     0
  Block device           253:1

  --- Segments ---
  Logical extent 0 to 511:
    Type                linear
    Physical volume     /dev/sdc
    Physical extents    0 to 511

Even though we can make reference to volume group names (testvg) directly, logical
volumes seem to be named specifically as their device location. To extend and reduce
the size of the logical volume, we have to say:

lvextend -L 2.5G /dev/testvg/testlv2
  Extending logical volume testlv2 to 2.50 GB
  Logical volume testlv2 successfully resized

lvreduce -L 2G /dev/testvg/testlv2
  WARNING: Reducing active logical volume to 2.00 GB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce testlv2? [y/n]: y
  Reducing logical volume testlv2 to 2.00 GB
  Logical volume testlv2 successfully resized

Next, lets build a filesystem:

 mkfs.ext3 /dev/testvg/testlv1
mke2fs 1.38 (30-Jun-2005)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
262144 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=0
16 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912

Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Finally, all we have to do is mount the filesystem and add a line to /etc/fstab for it:

mkdir /test
mount /dev/testvg/testlv1 /test
df -u

(add to /etc/fstab)
/dev/testvg/testlv1  /test                ext3       rw,noatime            0 0

Another LVM Howto

Leave a Reply

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