Showing posts with label LVM. Show all posts
Showing posts with label LVM. Show all posts

Snapshot of Logical Volume and Restore in LVM on Rhel 7/Centos 7/Oracle 7 Linux



LVM Snapshots of Logical Volume  on Rhel 7/Centos 7/Oracle 7 Linux  are space productive pointing time duplicates of lvm volumes. 

It works just with lvm and expend the space just when changes are made to the source intelligent volume to depiction volume. 

If source volume has a huge changes made to sum of 500MB the same changes will be made to the snapshot volume.
Incase the preview comes up short on capacity, we can utilize lvextend to develop.

On the off chance that we have incidentally erased any record in the wake of making a Snapshot we don't need to stress in light of the fact that the preview have the first document which we have erased.

To remove the snapshot we can use lvremove command.


Step 1: Create LVM Snapshot


First, check for free space in volume group to create a new snapshot.For that we are using using following vgs command.

# vgs

 VG       #PV #LV #SN Attr   VSize VFree
  VolGroup   1   2   0 wz--n- 7.51g    0
  testvg     2   1   0 wz--n- 3.99g 1.99g

# lvs
LV      VG       Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root VolGroup -wi-ao----   6.71g
  lv_swap VolGroup -wi-ao---- 816.00m
  testlv  testvg   -wi-ao----   2.00g

You see, there is 1.99GB of free space left in above vgs output. So, let’s create a snapshot for one of my volume named testlv.
For an example we are going to create only 1GB snapshot volume using following commands.


# lvcreate -L 1GB -s -n testlv_snap /dev/testvg/testlv
  Logical volume "testlv_snap" created

Where

1GB= Size of snapshot Iam creating here.
-s= Creates snapshot.
-n= Creates name for the snapshot.
testlv_snap= New snapshots name.
/dev/testvg/testlv= Volume which we are going to create a snapshot.


Snapshot of Logical Volume and Restore in LVM
create snapshot
We can use the below command to list new created snapshot. 

# lvs
  LV          VG       Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root     VolGroup -wi-ao----   6.71g
  lv_swap     VolGroup -wi-ao---- 816.00m
  testlv      testvg   owi-aos---   2.00g
  testlv_snap testvg   swi-a-s---   1.00g      testlv   0.00



Snapshot of Logical Volume and Restore in LVM
List snapshot


You see above, a snapshot was created successfully. 

# df -Th /dev/mapper/testvg-testlv
Filesystem                Type  Size  Used Avail Use% Mounted on
/dev/mapper/testvg-testlv ext4  2.0G   67M  1.9G   4% /testlvm


Let’s add some new files into testlv. 

Now check the volume using the follwing command.

#lvs

 LV          VG       Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root     VolGroup -wi-ao----   6.71g
  lv_swap     VolGroup -wi-ao---- 816.00m
  testlv      testvg   owi-aos---   2.00g
  testlv_snap testvg   swi-a-s---   1.00g      testlv   0.13

You see, 0.13% of snapshot volume was used now.

If we copy more than 1GB of files in testlV you will get error message appear On the screen  Input/output error, it means out of space in snapshot.



Step 2: Extend Snapshot in LVM




First we check available PE using vgdisplay command

# vgdisplay
  --- Volume group ---
  VG Name                    testvg
  System ID
  Format                        lvm2
  Metadata Areas          2
  Metadata Sequence No  4
  VG Access               read/write
  VG Status                resizable
  MAX LV                  0
  Cur LV                    2
  Open LV                 1
  Max PV                   0
  Cur PV                    2
  Act PV                    2
  VG Size                 3.99 GiB
  PE Size                 4.00 MiB
  Total PE                1022
  Alloc PE / Size       768 / 3.00 GiB
  Free  PE / Size       254 / 1016.00 MiB
  VG UUID               mz7AN3-jsR0-rnsQ-XpvM-2W0N-M8q8-pki2kB

# lvextend -l +254 /dev/testvg/testlv_snap
 Extending logical volume testlv_snap to 1.99 GiB
  Logical volume testlv_snap successfully resized

Now verify the size using the below command. 

# lvdisplay /dev/testvg/testlv_snap

 --- Logical volume ---
  LV Path                /dev/testvg/testlv_snap
  LV Name                testlv_snap
  VG Name                testvg
  LV UUID                eVvo1m-OZhv-PfP2-caja-r67k-W2o6-PD9Fcm
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2018-06-16 08:17:05 +0530
  LV snapshot status     active destination for testlv
  LV Status              available
  # open                 0
  LV Size                2.00 GiB
  Current LE             512
  COW-table size         1.99 GiB
  COW-table LE           510
  Allocated to snapshot  0.07%
  Snapshot chunk size    4.00 KiB
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:3


# lvs

 LV          VG       Attr       LSize   Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root     VolGroup -wi-ao----   6.71g
  lv_swap     VolGroup -wi-ao---- 816.00m
  testlv      testvg   owi-aos---   2.00g
  testlv_snap testvg   swi-a-s---   1.99g      testlv   0.07


Step 3: Restoring Snapshot or Merging



To restore the snapshot, we need to un-mount the file system first.

# unmount /testlvm

Just check for the mount point whether its unmounted or not.

# df -h

Here our mount has been unmounted, so we can continue to restore the snapshot. To restore the snap using command lvconvert.

# lvconvert --merge /dev/testvg/testlv_snap
 Merging of volume testlv_snap started.
  testlv: Merged: 100.0%
  Merge of snapshot into logical volume testlv has finished.
  Logical volume "testlv_snap" successfully removed


After the merge is finished, snapshot  volume will be expelled naturally. Now we can check partition space using the below command.

# df -Th

If this article is helpful to know about LVM Snapshots on Rhel 7/Centos 7/Oracle 7 Linux and restore the snapshot please share and subscribe this article.



How to Extend Logical Volume in rhel 7/Centos 7/Oracle 7 Linux LVM



Extend Logical Volume In rhel 7/CentOS 7/ Oracle 7 |In creating Logical Volume section we create testlv with 5GB

We want to increase the size of  the LV from 5GB to 10GB

we can do it two different ways

1. Extend LV Size with new hardDisk 

2. Extend LV Size from extra space of existing VG 

Extend LV Size  with new hardDisk 


We add new disk /dev/sde to LVM using  ‘fdisk ’ command

To do this activity we need to execute the below command. 

# fdisk /dev/sde

  • Type ‘n’ to create new partition

  • Afer that type ‘p’ to create the primary partition 

  • After that we need to enter first and last cylinder value.

  • Then type ‘t’ and we will enter the partition id to create LVM . Now we need to enter 8e and press w to save change.

Now our disk is prepared to add our existing LV. We have to follow the below steps.

 Create Physical volume
Now we create a Physical volume by executing the following command

# pvcreate /dev/sde

To Check PV we use ‘pvdisplay’ command,

Extend Volume group ‘testvg’ to add /dev/sde
# vgextend testvg /dev/sde

To Verify new VG Size we execute  ‘vgdisplay’ command

Extend Logical volume ‘testlv’ we need to follow below command.

# lvextend –L +5G /dev/testvg/testlv



Extend logical volume
Extend logical volume


Here, ‘-L +5G’ means that the size of LV’testlv’ will  increased by 5GB, we can verify the new size by executing ‘lvdisplay’ command.

But the LV Size is not affected.After execute the resize command the new LV Size will be affected.

To resize the filesystem we need to execute the below command.
# resize2fs /dev/testvg/testlv

To verify new LV Size we execute lvdisplay command.


Extend LV Size from  extra space of testvg


Lets take an example  we have 2 GB extra space in our existing Volume Group ‘testvg’ . we add that extra space  to our lv to inctease the size by following  the below process.


Extend Logical volume ‘testlv’ execute the below command.
# lvextend –L +2G /dev/testvg/testlv

To resize the filesystem we need to execute the below command.
# resize2fs /dev/testvg/testlv

To verify new LV Size we execute lvdisplay command.

If this article is helpful to know about Extend Logical Volume In rhel 7/CentOS 7/ Oracle 7 please share and subscribe this article. 



How to Configure Linux LVM2 (logical volume manager) on centos7/rhel7/oracle7 step by step tutorial guide



How To Configure Linux LVM on Oracle 7 / rhel 7/Centos 7 |Three major steps we have to follow to Setup a Logical Volume Manager (LVM). The Steps are :

Physical Volume : Arrange the Physical Harddisk’s some way so that Linux LVM can recognise  the Device and can be used to configure Volume Group and Logical Volumes is called as Physical Volume.
To create Physical volume you can use the command pvcreate.
You can execute  pvdisplay command to show all available Physical Volume’s in the system.
To know about  the Physical Volume details Summary use the command pvs.
Physical Volume is partitioned in to little bits of size is called as Physical Extent.


Volume Group : Addition of Multiple Physical  Volume is made Volume Group. 
To create Volume Group you can use the command vgcreate.
To check the details of VGs we can execute the vgdisplay command.
To know the Volume Group Summary use the command vgs.

Logical Volume : We can create Partitions out of Volume Group to store data is called as Logical Volume.
To create Logical Volume  you can use the command lvcreate.
To check the details of Logical Volume  you can use the command lvdisplay.
To know the  Logical Volume  Summary use the command lvs.

To configure Linux LVM we need at least a Physical Harddisk . Here I have 3 Harddisk’s i.e : /dev/sdb, /dev/sdc, /dev/sdd with size 2 GB each.



You can check harddisk and partition using the below command

# fdisk -l  

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdc: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/sdd: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000



Create Physical Volume


To create Physical volume you can use the command pvcreate.

Syntax:       pvcreate[disk]

Now we are creating Physical Volume by the given three physical harddisk

# pvcreate /dev/sdb   
  Physical volume "/dev/sdb" successfully created
  
# pvcreate /dev/sdc
  Physical volume "/dev/sdc" successfully created
  
# pvcreate /dev/sdd
  Physical volume "/dev/sdd" successfully created



  
create physical volume
create physical volume

You can use  pvdisplay command to show all available Physical Volume’s in the system.
  
  
  
  
  # pvdisplay /dev/sdc   
    "/dev/sdc" is a new physical volume of "2.00 GiB"
  --- NEW Physical volume ---
  PV Name              /dev/sdc
  VG Name               
  PV Size                 2.00 GiB
  Allocatable            NO
  PE Size                0  
  Total PE                0
  Free PE                0
  Allocated PE         0
  PV UUID              Joqlch-yWSj-kuEn-IdwM-01S9-XO8M-mcpsVe


PV Name : Physical disk Name
VG Name : Volume Group Name
PV Size : Physical Volume Size
Allocatable : The amount of Space we can allocate
PE Size : PE stands for Physical Extent.
Total PE : Total available Physical Extents.
Free PE : Remaining Physical Extents.

You can  use pvs command to check the quick short summary of all available Physical Volumes.

# pvs   
  PV         VG   Fmt  Attr PSize PFree
  /dev/sdb        lvm2 a--  2.00g 2.00g
  /dev/sdc        lvm2 a--  2.00g 2.00g
  /dev/sdd        lvm2 a--  2.00g 2.00g



Create Volume Group


To create volume Group you can use the command vgcreate.

Syntax:  vgcreate [Name of Volume Group] [Physical Volumes]

# vgcreate testvg /dev/sdb /dev/sdc /dev/sdd   
  Volume group "testvg" successfully created


create volume group
create volume group

  
  We use vgdisplay command to check the details of Volume Group. 

# vgdisplay   
  --- Volume group ---
  VG Name                  testvg
  System ID             
  Format                      lvm2
  Metadata Areas        3
  Metadata Sequence No  1
  VG Access               read/write
  VG Status                resizable
  MAX LV                  0
  Cur LV                    0
  Open LV                 0
  Max PV                   0
  Cur PV                    3
  Act PV                    3
  VG Size                  5.99 GiB
  PE Size                  4.00 MiB
  Total PE                 1533
  Alloc PE / Size       0 / 0   
  Free  PE / Size       1533 / 5.99 GiB

To know the Volume Group Summary use the command vgs.
# vgs   
  VG        #PV #LV #SN Attr   VSize VFree
  testvg   3   0   0 wz--n- 5.99g 5.99g

Create Logical  Volume


We can create Partitions out of Volume Group to store data is called as Logical Volume.
To create Logical Volume  you can use the command lvcreate.
To check the details of Logical Volume  you can use the command lvdisplay.
To know the  Logical Volume  Summary use the command lvs.

syntax:lvcreate -L [Size] -n [Name of the LV] VG

 We are creating Logical Volume with name testlv
 # lvcreate -L 5G -n testlv testvg
  Logical volume "testlv" created


logical volume create
logical volume create

  
To check the details of Logical Volume  you can use the command lvdisplay. 
To know the  Logical Volume  Summary use the command lvs.

# lvdisplay


Display logical volume
Display logical volume




Now we are ready  to store data on logical volumes. we need to create file system in Logical Volume by formatting it .
# mkfs.ext4 /dev/testvg/testlv

Now we needownload to create a directory to mount Logical Volume. 

# mkdir /testlvm

we can mount it manually by using this below command

# mount /dev/testvg/testlv /testlvm/

For automatic mount you must need entry in fstab

After successfully enter in fstab do the following command
#mount -a

Finally check it by the below command

#df -h

If this article is helpful to know about How To Configure Linux LVM on Oracle 7 / rhel 7/Centos 7 please share and subscribe this article.