Tuesday, March 31, 2015

logical volume manager in linux with examples.

http://www.linuxserverworldadmin.blogspot.in/2015/03/logical-volume-manager-in-linux.html

Logical Volume Manager 


To view the Hard disk name and partition information 
[root@client24 ~]# fdisk -l 
Disk /dev/hda: 40.0 GB, 40020664320 bytes 
255 heads, 63 sectors/track, 4865 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End
/dev/hda1 * 1 13
/dev/hda2 14 523
/dev/hda3 524 778
/dev/hda4 779 4865
/dev/hda5 779 905
/dev/hda6 906 1032
/dev/hda7 1033 1097 
Solaris
/dev/hda8 1098 2314

Create 3 partitions

[root@client24 ~]# fdisk /dev/hda

Blocks   Id  System 
104391 83  Linux
4096575 83  Linux
2048287+ 83  Linux
32828827+ 5  Extended
1020096 83  Linux
1020096 83  Linux
522081 82  Linux swap / 
9775521 83  Linux 
The number of cylinders for this disk is set to 4865. 
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) 

Command (m for help): n 
First cylinder (2315-4865, default 2315): Using default value 2315 
Last cylinder or +size or +sizeM or +sizeK (2315-4865, default 4865): 
+200M 
Command (m for help): n 
First cylinder (2340-4865, default 2340): Using default value 2340 
Last cylinder or +size or +sizeM or +sizeK (2340-4865, default 4865): 
+200M 
Command (m for help): n 
First cylinder (2365-4865, default 2365): Using default value 2365 
Last cylinder or +size or +sizeM or +sizeK (2365-4865, default 4865): 
+200M 
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. 
[root@client24 ~]# partprobe /dev/hda 
[root@client24 ~]# fdisk -l 
Disk /dev/hda: 40.0 GB, 40020664320 bytes 
255 heads, 63 sectors/track, 4865 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End
/dev/hda1 * 1 13
/dev/hda2 14 523
/dev/hda3 524 778
/dev/hda4 779 4865
/dev/hda5 779 905
/dev/hda6 906 1032
/dev/hda7 1033 1097 
Solaris
/dev/hda8 1098 2314
/dev/hda9 2315 2339
/dev/hda10 2340 2364
/dev/hda11 2365 2389
Create Physical Volumes

Blocks   Id  System 
104391 83  Linux
4096575 83  Linux
2048287+ 83  Linux
32828827+ 5  Extended
1020096 83  Linux
1020096 83  Linux
522081 82  Linux swap /
9775521 83  Linux
200781 83  Linux
200781 83  Linux 
200781 83  Linux 
[root@client24 ~]# pvcreate /dev/hda9 /dev/hda10 /dev/hda11 
Physical volume "/dev/hda9" successfully created 
Physical volume "/dev/hda10" successfully created 
Physical volume "/dev/hda11" successfully created 

To view Physical Volumes 

[root@client24 ~]# pvdisplay 
--- Physical volume ---
PV Name /dev/hda9
VG Name vg1
PV Size 196.08 MB / not usable 4.08 MB
Allocatable yes (but full)
PE Size (KByte) 4096
Total PE 48
Free PE 0
Allocated PE 48
PV UUID 5r8qvn-GF0k-NAfo-Rhqc-I3Qn-ZWws-zLCvks
--- Physical volume ---
PV Name /dev/hda10
VG Name vg1
PV Size 196.08 MB / not usable 4.08 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 48

Free PE 21
Allocated PE 27
PV UUID ys5Wd9-YiQ5-mM7c-sjrt-Mcwb-35oF-8mFyDW
--- Physical volume ---
PV Name /dev/hda11
VG Name vg1
PV Size 196.08 MB / not usable 4.08 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 48
Free PE 48
Allocated PE 0
PV UUID 5U81jh-Uddd-0giT-GYUT-pkvu-3MK3-KNkZJi

To create Volume Group 

[root@client24 ~]# vgcreate vg1 /dev/hda9 /dev/hda10 /dev/hda11 
Volume group "vg1" successfully created 
To display Volume Group Information. 
[root@client24 ~]# vgdisplay 
--- Volume group ---
VG Name vg1
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 3
Act PV 3
VG Size 576.00 MB
PE Size 4.00 MB
Total PE 144
Alloc PE / Size 75 / 300.00 MB
Free  PE / Size 69 / 276.00 MB
VG UUID P1zXt6-yBWW-SoUq-ZeF1-K7pf-Z69D-GVz8Up

To create logical Volume 


[root@client24 ~]# lvcreate vg1 -L +300M -n lv1 
Logical volume "lv1" created 

To view Logical Volume Information. 

[root@client24 ~]# lvdisplay 
--- Logical volume ---
LV Name /dev/vg1/lv1
VG Name vg1
LV UUID ZvsfPh-Ve0c-y4Qa-VUYy-HbdR-lG3G-66703a
LV Write Access read/write
LV Status available
# open 0
LV Size 300.00 MB
Current LE 75
Segments 2
Allocation inherit
Read ahead sectors 0
Block device 253:0
[root@client24 ~]# 

Format the Logical Volume 

[root@client24 ~]# mkfs.ext3 /dev/vg1/lv1 
mke2fs 1.39 (29-May-2006) 
Filesystem label= 
OS type: Linux 
Block size=1024 (log=0) 
Fragment size=1024 (log=0) 
102400 inodes, 409600 blocks 
20480 blocks (5.00%) reserved for the super user First data block=1 
Maximum filesystem blocks=67633152 
50 block groups 
8192 blocks per group, 8192 fragments per group 2048 inodes per group 
Superblock backups stored on blocks: 
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409 
Writing inode tables: done 
Creating journal (8192 blocks): done 
Writing superblocks and filesystem accounting information: done 

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

[root@client24 ~]# mkdir /mylvm 
[root@client24 ~]# mount /dev/vg1/lv1 /mylvm 
[root@client24 ~]# mount 

To resize the Logical Volume 

[root@client24 ~]# lvresize -L +100M /dev/vg1/lv1 

Extending logical volume lv1 to 400.00 MB 
Logical volume lv1 successfully resized 

[root@client24 ~]# lvdisplay 
--- Logical volume ---
LV Name /dev/vg1/lv1
VG Name vg1
LV UUID ZvsfPh-Ve0c-y4Qa-VUYy-HbdR-lG3G-66703a
LV Write Access read/write
LV Status available
# open 0
LV Size 400.00 MB
Current LE 100
Segments 3
Allocation inherit
Read ahead sectors 0
Block device 253:0
[root@client24 ~]# cd /mylvm  
[root@client24 mylvm]# touch file1 file2 file3 
[root@client24 mylvm]# mkdir hyd sec 
[root@client24 mylvm]# ls 
file1  file2  file3  hyd  lost+found  sec 

[root@client24 ~]# cd 
[root@client24 ~]# umount /mylvm 

To remove logical Volume 

[root@client24 ~]# lvremove /dev/vg1/lv1 
Do you really want to remove active logical volume "lv1"? [y/n]: y 
Logical volume "lv1" successfully removed 
[root@client24 ~]# cd 
[root@client24 ~]# umount /mylvm
[root@client24 ~]# lvremove /dev/vg1/lv1 

Do you really want to remove active logical volume "lv1"? [y/n]: y Logical volume "lv1" successfully removed 
[root@client24 ~]# fdisk /dev/hda 
The number of cylinders for this disk is set to 4865. 
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) 
Command (m for help): n 
First cylinder (2390-4865, default 2390): +300M Value out of range. 
First cylinder (2390-4865, default 2390): w First cylinder (2390-4865, default 2390): Using default value 2390 
Last cylinder or +size or +sizeM or +sizeK (2390-4865, default 4865): 
+300M 
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. 
[root@client24 ~]# partprobe /dev/hda 
[root@client24 ~]# fdisk -l 
Disk /dev/hda: 40.0 GB, 40020664320 bytes 
255 heads, 63 sectors/track, 4865 cylinders 
Units = cylinders of 16065 * 512 = 8225280 bytes 

Device Boot Start End Blocks   Id  System
/dev/hda1 * 1 13 104391 83  Linux
/dev/hda2 14 523 4096575 83  Linux
/dev/hda3 524 778 2048287+ 83  Linux
/dev/hda4 779 4865 32828827+ 5  Extended
/dev/hda5 779 905 1020096 83  Linux
/dev/hda6 906 1032 1020096 83  Linux
/dev/hda7 1033 1097 522081 82  Linux swap /
Solaris
/dev/hda8 1098 2314 9775521 83  Linux
/dev/hda9 2315 2339 200781 83  Linux
/dev/hda10 2340 2364 200781 83  Linux
/dev/hda11 2365 2389 200781 83  Linux
/dev/hda12 2390 2426 297171 83  Linux

[root@client24 ~]# pvcreate /dev/hda12 
Physical volume "/dev/hda12" successfully created 

To extend the volume group. 

[root@client24 ~]# vgextend vg1 /dev/hda12 
Volume group "vg1" successfully extended 

[root@client24 ~]# vgdisplay 
--- Volume group ---
VG Name vg1
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 4
Act PV 4
VG Size 864.00 MB
PE Size 4.00 MB
Total PE 216
Alloc PE / Size 0 / 0
Free  PE / Size 216 / 864.00 MB
VG UUID P1zXt6-yBWW-SoUq-ZeF1-K7pf-Z69D-GVz8Up



No comments:

Post a Comment