LVM CLI Steps

** Consider how a LVM disk is created | Prep a simple set up | Advanced LVM CLI | All the LVM CLI commands | Extend an LV and partition **

 
Consider how a LVM disk is created ^
 
Prep a simple set up for an external Drive of 20Gb ^
  1. fdisk /dev/sd<drive letter>
    See other sources for fdisk use - this presumes a working knowledge of fdisk.
    The partition sizes needed for a particular raw device should be carefully considered. There is overhead so calculations must be guesstimated for sizes.
    I found the following values ...
    Make sure you get a good bit of extra to compensate for the loss. I'd add 5GB for each partition that is expected to be added, thus if 5 partitions will be needed in the external drive add 25GB to the total size needed. I'd add an additional 25Gb to that for future growth.
    The disk must be type Linux LVM or 8e
     
  2. The physical volumes (PV) must be created.
    pvcreate /dev/sd<drive letter><partition number>
    pvcreate /dev/sdc1
    # pvcreate /dev/sdc1
    Writing physical volume data to disk "/dev/sdc1"
    Physical volume "/dev/sdc1" successfully created
    pvcreate /dev/sdc2
    # pvcreate /dev/sdc2
    Writing physical volume data to disk "/dev/sdc2"
    Physical volume "/dev/sdc2" successfully created
     
  3. The VG now needs to be created to include the PVs.
    vgcreate <Volume Group Name> /dev/sd<drive letter>1 /dev/sd<drive letter>2 ... /dev/sd<drive letter>N
    vgcreate VolGroup01 /dev/sdc1 /dev/sdc2
    # vgcreate VolGroup01 /dev/sdc1 /dev/sdc2
    Volume group "VolGroup01" successfully created
     
  4. The LVs now need to be created.
    lvcreate -L <size> -n <LVName> <Volume Group Name>
    lvcreate -L 10G -n work01 VolGroup01
    # lvcreate -L 10G -n work01 VolGroup01
    Logical volume "work01" created
    lvcreate -L 10G -n work02 VolGroup01
     
  5. Now the filesystem needs to be created.
    ls -l /dev/mapper
    mkfs -t <fs type> /dev/mapper/<VGName>-<LVName>
    mkfs -t ext4 /dev/mapper/VolGroup01-work01
    # mkfs -t ext4 /dev/mapper/VolGroup01-work01
    mke2fs 1.39 (29-May-2006)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    2621440 inodes, 5242880 blocks
    262144 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=4294967296
    160 block groups
    32768 blocks per group, 32768 fragments per group
    16384 inodes per group
    Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

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

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

    mkfs -t ext4 /dev/mapper/VolGroup01-work01
     
  6. Create mount points for the LV that now have filesystems.
    mkdir /work01 /work02
     
  7. Mount the LV's
    mount /dev/mapper/VolGroup01-work01 /work01
    mount /dev/mapper/VolGroup01-work02 /work02

     
  8. Make enteries in /etc/fstab; Which should look like ...
    /dev/mapper/VolGroup01-work01 /work01 ext4 _netdev,defaults,errors=continue 0 1
So what did we end up with ...
# pvdisplay /dev/sdc1 /dev/sdc2
  --- Physical volume ---
  PV Name               /dev/sdc1
  VG Name               VolGroup01
  PV Size               10.00 GB / not usable 1008.00 KB
  Allocatable           yes 
  PE Size (KByte)       4096
  Total PE              2561
  Free PE               1
  Allocated PE          2560
  PV UUID               c8k6SK-R1Px-GNGi-nxae-MhJb-ABmo-mvZrxo
   
  --- Physical volume ---
  PV Name               /dev/sdc2
  VG Name               VolGroup01
  PV Size               10.00 GB / not usable 1.00 MB
  Allocatable           yes 
  PE Size (KByte)       4096
  Total PE              2561
  Free PE               1
  Allocated PE          2560
  PV UUID               gbu4w0-7Ukx-L20f-OOiP-hZYC-TRP2-2fUhAD
  
# vgdisplay VolGroup01
  --- Volume group ---
  VG Name               VolGroup01
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               20.01 GB
  PE Size               4.00 MB
  Total PE              5122
  Alloc PE / Size       5120 / 20.00 GB
  Free  PE / Size       2 / 8.00 MB
  VG UUID               etxlSN-bDve-fP33-3cBK-A2dC-cT8e-7SPnPs
  
# lvdisplay VolGroup01
  --- Logical volume ---
  LV Name                /dev/VolGroup01/work02
  VG Name                VolGroup01
  LV UUID                sLznKy-1TYc-2Zni-Cj68-A48c-dW9B-D2JYhD
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                10.00 GB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     4096
  Block device           253:2
   
  --- Logical volume ---
  LV Name                /dev/VolGroup01/work01
  VG Name                VolGroup01
  LV UUID                hpYQ3S-qIy8-fcdO-cB3m-zkIz-5xqq-9HcJe2
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                10.00 GB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     4096
  Block device           253:3
# ls -l /dev/mapper/VolGroup01*
total 0
brw-rw---- 1 root disk 253, 3 May 30 11:07VolGroup01-work01
brw-rw---- 1 root disk 253, 2 May 30 11:07VolGroup01-work02

 

Advanced LVM CLI ^

Extend a VG then extend a LV (original size + added size).
In this case a PV /dev/sdd1 that was fdisk'd a primary/1 at 18G from /dev/sdd was prep'd for LVM will be added to LV work01.

    1)Request that a new LUN be created.
       Find the new LUN:  /bin/iscsiadm -m session -R
       That should show a new IQN, Use fdisk -l to identify the new physical volume.
       For this example lets say that is /dev/sdd
    2)lvs /dev/VolGroup01/work01
           LV     VG         Attr   LSize  Origin Snap%  Move Log Copy%  Convert
           work01 VolGroup01 -wi-ao 10.00G               
    3)pvcreate /dev/sdd1
           Writing physical volume data to disk "/dev/sdd1"
           Physical volume "/dev/sdd1" successfully created
    4)vgextend VolGroup01 /dev/sdd1
           Volume group "VolGroup01" successfully extended
    5)lvextend --size  28G /dev/VolGroup01/work01  ## Why 28? LV work01  was 10g + 18G = 28G.
           Extending logical volume work01 to 28.00 GB
           Logical volume work01 successfully resized           
    5)lvs /dev/VolGroup01/work01
           LV     VG         Attr   LSize  Origin Snap%  Move Log Copy%  Convert
           work01 VolGroup01 -wi-ao 28.00G     

Re-create a partition instead of extending it. (similar to above)

    0) Request that a new LUN be created. (fte 100G)).
       'Locate' the new LUN:  /sbin/iscsiadm -m discovery -d 5 -t st -p 10.1.1.1:3260
       That should show a new IQN, Use fdisk -l to identify the new physical volume.
       For this example lets say that is  /dev/sde and that 3 VG exist, 0-2.   
    1) Bring the disk on-line:  /sbin/iscsiadm -m node --interface=eth1 -T <IQ Name> --login      
    2) pvcreate /dev/sde    
    3) pvdisplay /dev/sde    
    4) vgcreate VolGroup03 /dev/sde       
    5) pvdisplay /dev/sde    
    6) lvcreate -L 100G -n l05-new VolGroup03   
    7) ls -l /dev/mapper  
    8) mkfs -t ext4 /dev/mapper/VolGroup03-l05-new   
    9) mkdir /l05-new   
   10) mount /dev/mapper/VolGroup03-l05-new /l05-new  
   11) cd /l05-new  
   12) cp -r -m -v /l05/* .  
   13) umount /l05   
   14) umount /l05-new 
   15) mount /dev/mapper/VolGroup03-l05-new /l05  
   16) In /etc/vfstab change the old entry to reflect the new name.
       Confirm it works umount /l05; df -h;
mount /l05
17) lvrename /dev/VolOracle01/L05 /dev/VolOracle01/L05-old lvrename /dev/VolGroup03/l05-new /dev/VolGroup03/l05 NOTE: This required the more conventional path NOT /dev/mapper. 18) Use system-config-lvm to confirm it has been removed. and ls -l /dev/mapper

Remove space from a LV

      lvreduce --size 1OG /dev/VolGroup01/work01  
           lvreduce --size 10G /dev/VolGroup01/work01
             WARNING: Reducing active and open logical volume to 10.00 GB
             THIS MAY DESTROY YOUR DATA (filesystem etc.)
           Do you really want to reduce work01? [y/n]: Y
             Reducing logical volume work01 to 10.00 GB
             Logical volume work01 successfully resized

Remove a PV from a VG.

      vgreduce VolGroup01 /dev/hdd1
           Removed "/dev/sdd1" from volume group "VolGroup01"

Add to a PV after addition storage has been added to it at the storage array.

      Generally a reboot will be necesary for the system to see the added storage.
            reboot
            Confirm the new space is seen.
            fdisk -l dev/sd<drive letter>
            Use the additional space as need for new partitions.
            Follow the steps at Prep a simple set up for an external Drive of 20Gb to complete the disk preparation.

Move data from on PV to another.

      pvmove -v /dev/sdb /dev/sdz

An example of the commands above.,br> CLI for lvm to remove, reduce and enlarge.

Remove LV l04

     df -h /l04
     umount /l04
     rm -rf /l04
     Remove entry from /etc/fstab
     		/dev/mapper/data-l04 /l04 ext4	_netdev,defaults,errors=continue 
     lvremove  /dev/data/data-l04
     df -h /l04
Reduce LV l03
     df -h /l03
     umount /l03
     e2fsck -f /dev/mapper/data-l03
     resize2fs -p /dev/mapper/data-l03
     lvreduce -L-20G /dev/mapper/data-l03  
     e2fsck -f /dev/mapper/data-l03
     mount /l03
     df -h /l03
Enlarge LV l01
     df -h /l01
     lvextend -L+10G /dev/mapper/VolGroup01-L01
     resize2fs -p /dev/mapper/VolGroup01-L01
     df -h /l01
Enlarge LV l02
     df -h /l02
     lvextend -L+10G  /dev/mapper/VolGroup01-L02
     resize2fs -p /dev/mapper/VolGroup01-L02 
     df -h /l02

All the LVM CLI commands: ^
Extend /l05 on T2DTDB ^
reboot

Must do an umount fir all partitions on iscsi drive
    /etc/init.d/dbora stop
    ps -ef |grep pmon
    ps -ef |grep u0
    kill -9 those processes found running in /u0

umount /l0* /u0*

vgchange -a n

fdisk /dev/sdc
   create a new partition (primary sdc2 )with the the space that was added.
   system-config-lvm could see the 50Gb that was added but could not access it!!

vgchange -a y

vgextend VolGroup01  /dev/sdc2

lvscan
vgdisplay VolGroup01  ## Note the  Free  PE / Size

lvresize -L+40G /dev/mapper/VolGroup01-l05

e2fsck -f /dev/mapper/VolGroup01-l05

resize2fs -p /dev/mapper/VolGroup01-l05
 
vgchange -a y

mount -a
df -h
      confirmed the new space was added to /l05      ;-{D
/etc/init.d/dbora start
     ... wait for a bit
ps -ef |grep pmon

reboot
iscsi-add-remove-disk.html
Add a new SD in and remove the old one

Valid HTML 4.01!