Subscribe For Free Updates!

We'll not spam mate! We promise.

Sunday, 5 October 2014

Everything about LVM (LOGICAL VOLUME MANAGEMENT)




Hello Friend's, In this session i am going to tell all about LVM (LOGICAL VOLUME MANAGEMENT) ,

========================================================================
I) How to create a Volume Group (VG).
II) How to create a Logical Volume (LV) and mount the file system.

III) How to add a disk to a Volume Group
IV) How to increase the size of a logical volume without OnlineJFS
V) How to remove a Logical Volume
VI) How to reduce the size of a logical volume without OnlineJFS (advanced JFS)
VII) How to remove a disk from a volume group
VIII) How to remove a volume group
IX) How to increase the primary swap
X) How to create a secondary boot disk LVM Mirroring
XI) How to mirror a logical volume
XII) How to unmirror a logical volume
XIII) How to create a mirrored boot disk
XIV) How to mirror a logical volume on a specific physical volume Physical Volume Group
XV) How to create a Physical Volume Group (PVG)
XVI) How to use PVG to mirror logical volumes on specific physical volumes
========================================================================



How to create LVM


Step:1 To check the device (hda , sda) by using fdisk.check the new partition

[root@trash3can /]# fdisk -l
[root@trash3can ~]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1020     8193118+  83  Linux
/dev/sda2            1021        1275     2048287+  83  Linux

Step:2 Create the partation

[root@trash3can ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 1305.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
>> m command for help
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
>> n command for add a new partition
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p  >>press p for primary partition
Partition number (1-4): 3
First cylinder (1276-1305, default 1276):
Using default value 1276
Last cylinder or +size or +sizeM or +sizeK (1276-1305, default 1305): +100M
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Selected partition 4
First cylinder (1289-1305, default 1289):
Using default value 1289
Last cylinder or +size or +sizeM or +sizeK (1289-1305, default 1305): +100M
>> p for print the partition table
Command (m for help): p
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1020     8193118+  83  Linux
/dev/sda2            1021        1275     2048287+  83  Linux
/dev/sda3            1276        1288      104422+  83  Linux
/dev/sda4            1289        1301      104422+  83  Linux
>>w   write table to disk and exit
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
>> to change the partation id by pressing the t command
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): L
 0  Empty           1e  Hidden W95 FAT1 80  Old Minix       bf  Solaris
 1  FAT12           24  NEC DOS         81  Minix / old Lin c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          82  Linux swap / So c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  83  Linux           c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     84  OS/2 hidden C:  c7  Syrinx
 5  Extended        41  PPC PReP Boot   85  Linux extended  da  Non-FS data
 6  FAT16           42  SFS             86  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS       4d  QNX4.x          87  NTFS volume set de  Dell Utility
 8  AIX             4e  QNX4.x 2nd part 88  Linux plaintext df  BootIt
 9  AIX bootable    4f  QNX4.x 3rd part 8e  Linux LVM       e1  DOS access
 a  OS/2 Boot Manag 50  OnTrack DM      93  Amoeba          e3  DOS R/O
 b  W95 FAT32       51  OnTrack DM6 Aux 94  Amoeba BBT      e4  SpeedStor
 c  W95 FAT32 (LBA) 52  CP/M            9f  BSD/OS          eb  BeOS fs
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a0  IBM Thinkpad hi ee  EFI GPT
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a5  FreeBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a6  OpenBSD         f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a7  NeXTSTEP        f1  SpeedStor
12  Compaq diagnost 5c  Priam Edisk     a8  Darwin UFS      f4  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       a9  NetBSD          f2  DOS secondary
16  Hidden FAT16    63  GNU HURD or Sys ab  Darwin boot     fb  VMware VMFS
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT
>> 8e  Linux LVM
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)
Command (m for help): t
Partition number (1-4): 4
Hex code (type L to list codes): 8e
Changed system type of partition 4 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1020     8193118+  83  Linux
/dev/sda2            1021        1275     2048287+  83  Linux
/dev/sda3            1276        1288      104422+  8e  Linux LVM
/dev/sda4            1289        1301      104422+  8e  Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.



Step:3 Check the partation y using fdisk -l command

[root@trash3can ~]# fdisk -l
Disk /dev/sda: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1        1020     8193118+  83  Linux
/dev/sda2            1021        1275     2048287+  83  Linux
/dev/sda3            1276        1288      104422+  8e  Linux LVM
/dev/sda4            1289        1301      104422+  8e  Linux LVM


[root@node1 ~]# cat /proc/partitions
major minor  #blocks  name
   8     0   10485760 sda
   8     1    8193118 sda1
   8     2    2048287 sda2
   8    16    1048576 sdb
   8    17     409626 sdb1
   8    18     409657 sdb2
   8    19     224910 sdb3



********************************phycial volumes************************************

Step:4  Now we are creating the phycial volume (/dev/sda3,/dev/sda4).one or more phycial volume creates the volume group.

[root@trash3can ~]# pvcreate /dev/sda3 /dev/sda4
  Physical volume "/dev/sda3" successfully created
  Physical volume "/dev/sda4" successfully created
[root@trash3can ~]#

Step:5 To check and verify the phycial volume by using the pvdisplay.

[root@trash3can ~]# pvscan
[root@trash3can ~]# pvdisplay
  "/dev/sda3" is a new physical volume of "101.98 MB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name
  PV Size               101.98 MB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               nvle6H-L3cv-EFl3-2F70-EXRM-05bs-8iPQ7h
  "/dev/sda4" is a new physical volume of "101.98 MB"
  --- NEW Physical volume ---
  PV Name               /dev/sda4
  VG Name
  PV Size               101.98 MB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               Vbt35c-iOr3-5lIA-0U7q-O0Qb-uC2n-zdKTcz

Note : Now you can see , We created the two PV ("/dev/sda3" , "/dev/sda4") Successfully

"/dev/sda3" is a new physical volume of "101.98 MB"
 PV Name               /dev/sda3
PV Size               101.98 MB

 "/dev/sda4" is a new physical volume of "101.98 MB"
PV Name               /dev/sda4
PV Size               101.98 MB


[root@trash3can ~]# pvs
  PV         VG   Fmt  Attr PSize  PFree
  /dev/sda2       lvm2 --    1.95G  1.95G
  /dev/sda3       lvm2 --   54.91M 54.91M
[root@trash3can ~]#
[root@trash3can ~]#
[root@trash3can ~]# pvscan
  PV /dev/sda2                      lvm2 [1.95 GB]
  PV /dev/sda3                      lvm2 [54.91 MB]
  Total: 2 [2.01 GB] / in use: 0 [0   ] / in no VG: 2 [2.01 GB]


********************************Volume group *************************************

Step:6  Now we are creating the volume group by using two phycial volume ("/dev/sda3" , "/dev/sda4")and we need to give the volume group name(vg).

[root@trash3can ~]# vgcreate vg /dev/sda3 /dev/sda4
  Volume group "vg" successfully created

Here volume name is vg


Step:7 To check and verify the volume group by using the vgdisplay.

[root@trash3can ~]# vgs
  VG              #PV #LV #SN Attr   VSize VFree
  my_volume_group   2   0   0 wz--n- 2.00G 2.00G
[root@trash3can ~]# vgscan
  Reading all physical volumes.  This may take a while...
  Found volume group "my_volume_group" using metadata type lvm2
[root@trash3can ~]# vgdisplay
  --- Volume group ---
  VG Name               vg
  System ID
  Format                lvm2
  Metadata Areas        2
  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                2
  Act PV                2
  VG Size               200.00 MB
  PE Size               4.00 MB
  Total PE              50
  Alloc PE / Size       0 / 0
  Free  PE / Size       50 / 200.00 MB
  VG UUID               nMofQi-kjDL-B8uS-zG0s-90Gk-s2Fe-mqjCv2
Note :
VG Name               vg
VG Access             read/write
VG Status             resizable
VG Size               200.00 MB(+100 M + 100M)
PE Size               4.00 MB



*******************************Logical volume *************************************

Step:8 Now we will create the logical volume.Here logical volume name is lv and size is +50M

[root@trash3can ~]# lvcreate -L +50M -n lv /dev/vg
  Rounding up size to full physical extent 52.00 MB
  Logical volume "lv" created

L- length of the LV
n- used to define the name of the lv

Step:9 to check and verify wheather lv created or not.

[root@trash3can ~]# lvs
  LV                VG              Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  my_logical_volume my_volume_group -wi-a- 500.00M                            
[root@trash3can ~]# lvscan
  ACTIVE            '/dev/my_volume_group/my_logical_volume' [500.00 MB] inherit
[root@trash3can ~]#

[root@trash3can ~]# lvdisplay
  --- Logical volume ---
  LV Name                /dev/vg/lv
  VG Name                vg
  LV UUID                I33kZN-j74r-yu6w-xx0R-23Sc-pTRg-n5uG4I
  LV Write Access        read/write
  LV Status              available
  # open                 0
  LV Size                52.00 MB
  Current LE             13
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

Note :
LV Name                /dev/vg/lv
LV Size                52.00 MB
Block device           253:0(100+100+50)



******************************Create the file system *********************************
Step:10 Create the file system by using the mkfs command.

[root@trash3can ~]# mkfs.ext3 /dev/vg/lv
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
13328 inodes, 53248 blocks
2662 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=54525952
7 block groups
8192 blocks per group, 8192 fragments per group
1904 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


Step:11  Create the directory to mount the File system .


[root@trash3can ~]# mkdir LVM

Step:12

[root@trash3can ~]# mount /dev/vg/lv LVM/

Step:13 Check and verify

[root@trash3can ~]# df -HTP
Filesystem    Type     Size   Used  Avail Use% Mounted on
/dev/sda1     ext3     8.2G   5.8G   2.0G  75% /
/dev/sda2     ext3     2.1G    37M   1.9G   2% /swap
tmpfs        tmpfs     531M      0   531M   0% /dev/shm
/dev/mapper/vg-lv ext3    53M   5.1M    45M  11% /root/LVM



*****************************LVM mounting****************************************

Step:14 We need to add  the entries in /etc/fstab to make the parmanent entries


[root@trash3can ~]# vim /etc/fstab
/dev/mapper/vg-lv       /root/LVM              ext3    defaults         0 0

[root@trash3can ~]# mount -a
[root@node1 ~]# mount |grep lv
/dev/mapper/vg-lv on /root/LVM type ext3 (rw)
[root@trash3can ~]# cp /etc/passwd LVM/
[root@trash3can ~]# ll LVM/
total 14
drwx------ 2 root root 12288 Dec 28 08:22 lost+found
-rw-r--r-- 1 root root  1791 Dec 28 09:20 passwd

Step:15  Reboot the system to verify that the file system is automatically mounted after boot with df-HTP command


 [root@trash3can ~]# df -HTP
Filesystem    Type     Size   Used  Avail Use% Mounted on
/dev/sda1     ext3     8.2G   5.8G   2.0G  75% /
/dev/sda2     ext3     2.1G    37M   1.9G   2% /swap
tmpfs        tmpfs     531M      0   531M   0% /dev/shm
/dev/mapper/vg-lv ext3    53M   5.1M    45M  11% /root/LVM

***********************************LV extend**************************************

LVM Management (LV extend)
grom volumes
Growing volumes
a) lvextend can grow the logical volumes.
b)resize2fs can grow ext3 File system online and offline


>>>Extend <<<
Step:16  Extend the lv with 100 M size

[root@trash3can ~]# lvextend -L +100M /dev/vg/lv
Extending logical volume lv to 152.00 MB
Logical volume lv successfully resized
[root@trash3can ~]# lvdisplay
--- Logical volume ---
LV Name /dev/vg/lv
VG Name vg
LV UUID I33kZN-j74r-yu6w-xx0R-23Sc-pTRg-n5uG4I
LV Write Access read/write
LV Status available
# open 0
LV Size 152.00 MB >>>
Current LE 38
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
Step:17 Still size is 53M

[root@trash3can ~]# df -HTP
Filesystem    Type     Size   Used  Avail Use% Mounted on
/dev/mapper/vg-lv ext3    53M   5.1M    45M  11% /root/LVM

Step:18 We need to run the commad to make the changes onine

[root@trash3can ~]# resize2fs -p /dev/vg/lv
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/vg/lv is mounted on /root/LVM; on-line resizing required
Performing an on-line resize of /dev/vg/lv to 155648 (1k) blocks.
The filesystem on /dev/vg/lv is now 155648 blocks long.
[root@trash3can ~]# df -h LVM/
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg-lv     148M  5.3M  135M   4% /root/LVM
Now size has been changed (148M)

*********************************************************************************
EXTRA Info

Step:19  Shrinking volume must be done offline umount
[root@trash3can ~]# umount LVM/
Requires a file ssytem check e2fsck
[root@trash3can ~]# e2fsck -F /dev/vg/lv
e2fsck 1.39 (29-May-2006)
/dev/vg/lv: clean, 12/36176 files, 9945/155648 blocks



*********************************************************************************
Now I am adding one more disk in FS(/dev/sd5)


[root@trash3can ~]# pvcreate /dev/sda5
  Physical volume "/dev/sda5" successfully created
[root@trash3can ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               vg
  PV Size               1.95 GB / not usable 287.50 KB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              500
  Free PE               462
  Allocated PE          38
  PV UUID               vDEBXN-PSdT-Xqfv-T0fL-856Z-jB4d-aM7xks
  --- Physical volume ---
  PV Name               /dev/sda3
  VG Name               vg
  PV Size               101.98 MB / not usable 1.98 MB
  Allocatable           yes
  PE Size (KByte)       4096
  Total PE              25
  Free PE               25
  Allocated PE          0
  PV UUID               8EogKA-i6H6-VrbB-YwLb-N0D1-ARlN-Wry1gI
  "/dev/sda5" is a new physical volume of "54.88 MB"
  --- NEW Physical volume ---
  PV Name               /dev/sda5
  VG Name
  PV Size               54.88 MB
  Allocatable           NO
  PE Size (KByte)       0
  Total PE              0
  Free PE               0
  Allocated PE          0







Socializer Widget By trash3can
SOCIALIZE IT →
SHARE IT →

0 comments:

Post a Comment