#####################Logical Volume Manager##########################
$ LVM [ Logical Volume Manager ] : -
LVM is a tool for
logical volume management which is used to allocating disks, striping,
mirroring and resizing logical volumes. With LVM, a hard drive or set of
hard drives is allocated to one or morephysical volumes .
Lvm is very
useful in various scenario where your
hardisk getting full and you want to increase harddrive size without losing
data or also you can reduce as per the requirement.
$ LVM has
several commands as follows :-
·
Pvcreate
·
Pvdisplay
·
Pvremore
·
Vgcreate
·
Vgextend
·
Vgreduce
·
Vgremove
·
Vgdisplay
·
Lvcreate
·
Lvdispaly
·
Lvreduce
·
Lvremove
$ pvcreate
:- is used to create physical volume on harddrive.
$ pvdisplay
:- is used to display created physical volume on harddisk.
$ pvremove
:- is used to remove physical volume from harddisk.
$ vgcreate
:- is used to create volume group by adding created physical volume in single
group.
$ vgextend
:- we can also extend the already created volume group with help of vgextend
command.
$ vgdisplay
:- is used to display volume groups on harddrives.
$ vgremove
:- we can also remove created volume groups from harddrives with the help of
vgremove command.
$ lvcreate
:- with help of this command we can create logical volume as per the user
required size from the Volume group.
$ lvdisplay
:- is used to display created volumes.
$ lvreduce
:- we can also reduce size of already created logical volumes with help of
lvreduce command without losing data.
$ lvremove
:- we can also remove created logical volumes if we don’t required.
$ lvextend
:- is used to extend the size of already created logical volume.
Now we can
see practical scenario :-
To create
lvm on hardisk first we create 3 partition on harddisk or we can also used
already created partitions.
1. We create 3 partitions on harddisk
with help of fdisk command each of partition size is 500M
2. Now we have to create three physical
volume then from this volume create a group and then we create logical volumes.
$ Create a
physical volume on /dev/sda1, /dev/sda2, /dev/sda3
#
pvcreate /dev/sda1 /dev/sda2 /dev /sda3
$ Physical volumes are created now check with,
#
pvdisplay
$ After successful creation of Physical volume we are going
to add all this physical volume to single Volume Group.
#
vgcreate /dev/mynewvg /dev/sda1
/dev/sda2 /dev/sda3
$ Check created
volume group,
#
vgdisplay
$ Now we are creating 3 Logical volumes from Volume group.
#
lvcreate -L 700M /dev/mynewvg -n
lvol1
#
lvcreate -L 400M
/dev/mynewvg -n lvol2
# lvcreate
-L 400M /dev/mynewvg
-n lvol3
$ to display all this
logical volume used,
# lvdisplay
With help of above
commands we can successfully create lvm on harddisk.
Some other commands which we used as per requirement.
$ if we want to
remove all lvm from hardisk we used below commands ,
# For
removing lvm we need to start from above like first remove logical volume then
volume group and in last physical volumes.
$ Logical Volume
remove
# lvremove
/dev/mynewvg/lvol1
# lvremove
/dev/mynewvg/lvol2
# lvremove
/dev/mynewvg/lvol3
$ Volume Group Remove
#
vgremove /dev/mynewvg
$ Physical Volume
Remove
#
pvremove /dev/sda1 /dev/sda2
/dev/sda3
$ if we want to extend the size of Logical volume,
#
lvextend -L +100M /dev/mynewvg/lvol1
OR
# lvresize -L
+100M /dev/mynewvg/lvol1
#
resize2fs /dev/mynewvg/lvol1 [ To take affect of above command ]
$ if we want to
reduce the size of Logical volume,
#
umount /dev/mynewvg/lvol1
#
e2fsck -f /dev/mynewvg/lvol1
# resize2fs
/dev/mynewvg/lvol1 600M
# lvreduce
-L -100M /dev/mynewvg/lvol1
With this extend and reduce command will help without any
data loss.
$ if want to increase
Volume group used,
# vgextend
/dev/mynewvg /dev/sda4
**************** ********************* ************** ***************************
LVM
LVM
– Logical Volume Management
[root@tushar
~]# df –h -----------------To check HDD partitions
Filesystem Size
Used Avail Use% Mounted on
/dev/sda2 18G
2.8G 14G 17% /
tmpfs 497M
228K 497M 1% /dev/shm
/dev/sda1 291M
34M 242M 13% /boot
-----------------------------------------------------------------------------------------------------------------
LVM
------Partitions
How
add HDD in VMware – right click on setting and add hdd (.vmdk.1 partition
create)
After
adding HDD to run - echo scan
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# fdisk –l -----------to check partition mount
Disk
/dev/sda: 21.5 GB, 21474836480 bytes
255
heads, 63 sectors/track, 2610 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: 0x0005b96e
Device Boot Start End Blocks
Id System
/dev/sda1 *
1 39
307200 83 Linux
Partition
1 does not end on cylinder boundary.
/dev/sda2 39 2354
18598912 83 Linux
/dev/sda3 2354 2611
2064384 82 Linux swap / Solaris
Disk
/dev/sdb: 2147 MB, 2147483648 bytes
------------------ add 2GB HDD
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
-----------------------------------------------------------------------------------------------------------------
RESIZING THE PARTITIONS (EXTEND AND
REDUCE)
We cannot extend
& reduce the partition because it’s not in LVM or regular partitions
LVM -It is
Logical Device driver layer above regular partition
We can create
LVM time of installation = DISKRUIDE LVM
Default
Installation all partitions go under LVM - …./dev/logval/volgroup
-----------------------------------------------------------------------------------------------------------------
TASK
# unmount …….delete …….new
partition………lvm……../home (dir)
Can
we migrate regular partition to lvm
Answer
: yes
(unmount /home, delete /home dir device , remount)
1) Create 500MB Partition
2)
Create LVM
3)
Format
4)
Mount
5)
…./common (Create DIR)
-----------------------------------------------------------------------------------------------------------------
1) Fdisk –l ------2GB ---device drive
2) LVM -----ID-----8e
3) PV ---Physical Volume – 2GB (/dev/sdb1)
4) VG ---Volume Group ---2GB (create volume group name eg. myvol )
5) LV –Logical Volume – (Create name rg .lv1 and partition size)
6) Mkfs.ext3 /dev/myvol/lv1 ----format lvm partition
7) Mount /dev/myvol/lv1 -----partition mount
8) /etc/fstab/
-----------------------------------------------------------------------------------------------------------------
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)
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# partprobe –h (sync hdd partition)
Usage:
partprobe [OPTION] [DEVICE]...
-d, --dry-run do not actually inform the operating system
-s, --summary print a summary of contents
-h, --help display this help and exit
-v, --version output version information and exit
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# fdisk -h
fdisk [options] <disk> change partition table
fdisk [options] -l <disk> list partition
table(s)
fdisk -s <partition> give partition size(s) in blocks
Options:
-b <size> sector size (512, 1024, 2048
or 4096)
-c switch off
DOS-compatible mode
-h print help
-u <size> give sizes in sectors instead
of cylinders
-v print version
-C <number> specify the number of cylinders
-H <number> specify the number of heads
-S <number> specify the number of sectors
per track
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# fdisk –l ------------------To check HDD
Disk
/dev/sda: 21.5 GB, 21474836480 bytes
---------default partition
255
heads, 63 sectors/track, 2610 cylinders
/dev/sda1
* 1 39 307200
83 Linux
Partition
1 does not end on cylinder boundary.
/dev/sda2 39 2354
18598912 83 Linux
/dev/sda3 2354 2611
2064384 82 Linux swap / Solaris
Disk
/dev/sdb: 2147 MB, 2147483648 bytes
------------------free hdd 1 partition
255
heads, 63 sectors/track, 261 cylinders
Disk
/dev/sdc: 2147 MB, 2147483648 bytes
------------------free hdd 2
partition
22
heads, 16 sectors/track, 11915 cylinders
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# mount ------------------------to check mount
point
/dev/sda2
on / type ext4 (rw)
proc
on /proc type proc (rw)
sysfs
on /sys type sysfs (rw)
devpts
on /dev/pts type devpts (rw,gid=5,mode=620)
[root@Tusharjahdav
~]# mount – a ---------- no need to
restart pc
How
To Create LVM Partitions
[root@Tusharjahdav
~]# fdisk -s /dev/sdc -----------------check hdd size
2097152
[root@Tusharjahdav
~]# fdisk -s /dev/sdb
-----------------check hdd size
1048576
[root@Tusharjahdav
~]# fdisk /dev/sdb -------------------free partition hdd
Command
(m for help): n ----------------------------------------
add a new partition
Command
action
e
extended
p
primary partition (1-4)
p ------------------------------------------------------------ Primary
partition
Partition
number (1-4): 1
--------------------------------Give partition number
Partition
1 is already defined. Delete it before
re-adding it.
Command
(m for help): t ------------------------change lvm ID
Selected
partition 1
Hex
code (type L to list codes): 8e
-------------------given 8e (lvm ID) for lvm partition
Command
(m for help): p ---------------check
partition table
Command
(m for help): w -------------------------- write table to
disk and exit
The
partition table has been altered!
Calling
ioctl() to re-read partition table.
[root@Tusharjahdav
~]# sync --------------------------------- Syncing
disks
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]#
portprob –s /dev/sdb1 -----partition done (update hdd partition)
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]#
pvcreate /dev/sdb1 ---------------------create
physical volume 1GB
(pvcreate < device name> )
Physical volume "/dev/sdb1" successfully
created
------------------------------------------------------
-----------------------------------------------------------
[root@Tusharjahdav ~]# vgcreate myvol /dev/sdb1 --
Volume group create 1GB
(vgcreate
< new group name><pv name>
Volume group "myvol" successfully
created
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav ~]# lvcreate -L 500M
-n lv1 myvol ---------------500M
lv1 created
( lvcreate
–L <size> -n < new lv name><vg name>
Logical
volume "lv1" created
-----------------------------------------------------------------------------------------------------------------
1)
pvcreate, 2) vgcreate, 3) lvcreate
After above 3
commands create layer (/dev/mapper/myvol-lv1) and system create information in background
[root@Tusharjahdav
~]# man lvm -------To
check LVM
Commands and flags or HELP
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# ls /dev/mapper/myvol-lv1 ------------------Actual location of LVM
/dev/mapper/myvol-lv1
[root@Tusharjahdav
~]# ls /dev/myvol/lv1 --------------------------LVM links or short
cut path
/dev/myvol/lv1
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# mkfs.ext3 /dev/myvol/lv1 ---------------new lvm volume format
(mk-make, fs- file system,
.ext2,3,4 versions)
[root@Tusharjahdav
~]# mkdir /Dell -----------------Create common DIR
[root@Tusharjahdav
~]# ls
bin boot Dell department dev
etc GHAR home
india lib lib64
lost+found media mnt
opt proc root
sbin selinux srv
sys tmp usr
var wallet
[root@Tusharjahdav
~]# mount /dev/myvol/lv1 /Dell ----------mount
common DIR
-----------------------------------------------------------------------------------------------------------------
pvdisplay }
--------------check
pv information
vgdisplay
}
-------------To
check free space and maintain the LVM
lvdisplay } -------------check
lv information
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# pvdisplay
--- Physical volume ---
PV Name /dev/sdb1
--------------------device driver name
VG Name myvol ------------------------volume group name
PV Size 2.00 GiB / not usable 4.00 MiB --------------PV Size
[root@Tusharjahdav
~]# vgdisplay
--- Volume group ---
VG Name myvol
Format lvm2
VG Size 2.00 GiB --------------------------------------PV
Size
Alloc PE / Size 200 / 800.00 MiB
Free
PE / Size 311 / 500 GiB ---------------------------free size
[root@Tusharjahdav
~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvol/lv1
------------------------logical volume name
LV Name lv1
VG Name myvol
LV Size 500.00 MiB --------------------------------lv1 size
-----------------------------------------------------------------------------------------------------------------
Add mount /Dell entry in …/etc/fstab or …./etc/mtab
[root@Tusharjahdav
~]# vi /etc/fstab
Dell /dev/myvol/lv1 ext3
defaults 0 0 ---- add entry in ftab for permanent mount
root@Tusharjahdav
~]# df –h ----------------to check
Filesystem Size
Used Avail Use% Mounted on
/dev/sda2 18G
2.7G 14G 17% /
tmpfs 497M
72K 497M 1% /dev/shm
/dev/sda1 291M
34M 242M 13% /boot
/dev/mapper/myvol-lv1 485M 11M
449M 3% /Dell ---------------added…. /Dell
How
to extend LVM volume
There
is 2 commands for lvm extend volume
1)…[root@Tusharjahdav
~]# lvextend -L +200m
/dev/myvol/lv1 ----extend 200MB
Extending logical volume lv1 to 1000.00 MiB
Logical volume lv1 successfully resized
[root@Tusharjahdav
~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvol/lv1
LV Name lv1
VG Name myvol
LV Size 1000.00 MiB ---------------------extend
lv1 volume
----------------------------------------------OR---------------------------------------------
1) …[root@Tusharjahdav ~]# lvextend -L 1200m /dev/myvol/lv1 -- give total value u want
Extending logical volume lv1 to 1.17 GiB
Logical volume lv1 successfully resized
[root@Tusharjahdav
~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvol/lv1
LV Name lv1
VG Name myvol
LV Size 1.17 GiB ----extend 200MB
-----------------------------------------------------------------------------------------------------------------
1)..[root@Tusharjahdav
~]# lvextend -l +50%free /dev/myvol/lv1-
extend 50% from free hdd
Extending logical volume lv1 to 1.59 GiB
Logical volume lv1 successfully resized
[root@Tusharjahdav
~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvol/lv1
LV Name lv1
VG Name myvol
LV Size 1.59 GiB ----extend 50% from free
space
[root@Tusharjahdav
~]# vgdisplay /
vgs
Free PE 211 ------------------------free
size
-----------------------------------------------------------------------------------------------------------------2)….
[root@Tusharjahdav ~]# resize2fs
/dev/myvol/lv1 -----extend & reduce
the file system
Filesystem
at /dev/myvol/lv1 is mounted on /common - Resize
or extend (created file system)
[root@Tusharjahdav
~]# df –h -------------check lv1 volume size
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 18G 2.7G
14G 17% /
tmpfs 497M 72K
497M 1% /dev/shm
/dev/sda1 291M 34M
242M 13% /boot
/dev/mapper/myvol-lv1 678M
11M 633M 2% /Dell
-----------------------------------------------------------------------------------------------------------------
1st
HDD -/dev/sdb1 - Free partition
PV -- 1GB
|
|
VG – 1GB
|
|
LV –1GB
|
|
Create 850MB lv1
|
150 MB free
|
mkfs.ext3
/dev/myvol/l dev/myvol/lv1-----format
& mount Dir and add fstab for permanent
(Create the file system)
[root@Tusharjahdav
~]# mount /dev/myvol/lv1 /Dell
------------mount DIR
[root@Tusharjahdav
~]# vi /etc/fstab
Dell /dev/myvol/lv1 ext3
defaults 0 0 ---- add entry in fstab for permanent
mount
-----------------------------------------------------------------------------------------------------------------
Online extending – no need to unmount, reboot & shutdown -
we extend the hdd without unount
-----------------------------------------------------------------------------------------------------------------
VG
is important because of VG contain PV and LV
-----------------------------------------------------------------------------------------------------------------
1st
HDD
/dev/sdb1 - Free partition 2nd HDD -/dev/sdc1
PV -- 1GB
|
PV 2Gb Create
|
|||
VG – 1GB + 2GB = 3GB total value of
VG
VG extend
|
||||
LV –1GB
Create 1GB lv1- 1st HDD
|
Lv1 300 MB extend
2nd
HDD
|
Free 1.7GB
2nd
HDD
|
||
VG can contains multiple PV’s
[root@Tusharjahdav
~]# fdisk -l
Disk
/dev/sda: 21.5 GB, 21474836480 bytes
Disk /dev/sdb:
1073 MB, 1073741824 bytes
Device
Boot Start End Blocks
Id System
/dev/sdb1 1 130
1044193+ 8e Linux LVM
Disk /dev/sdc: 2147
MB, 2147483648 bytes
[root@Tusharjahdav
~]# fdisk /dev/sdc -----------------Create Partition
Command
(m for help): n
Command
action
e
extended
p
primary partition (1-4)
p
Partition
number (1-4): 1
First
cylinder (1-261, default 1):
Using
default value 1
Last
cylinder, +cylinders or +size{K,M,G} (1-261, default 261):
Using
default value 261
Command
(m for help): t
Selected
partition 1
Hex
code (type L to list codes): 8e
Changed
system type of partition 1 to 8e (Linux LVM)
Command
(m for help): w
The
partition table has been altered!
Calling
ioctl() to re-read partition table.
Syncing
disks.
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# sync
[root@Tusharjahdav
~]# partprobe
/dev/sdc1
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# pvcreate /dev/sdc1 ------------------Create physical volume
Physical volume "/dev/sdc1"
successfully created
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# fdisk -s /dev/sdc -----check size
P -------------------------print
partition tabel
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# pvdisplay ------check pv
--- Physical volume ---
PV Name /dev/sdb1 --------------------------------1st created pv
VG Name myvol
PV Size 1019.72 MiB / not usable 3.72
MiB
"/dev/sdc1" is a new physical
volume of "2.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc1 -------------------------------2nd created pv
VG Name
PV Size
2.00 GiB
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# vgdisplay ----vgdisplay before extend value
--- Volume group ---
VG Name myvol
VG Size 1016.00 MiB
Free PE / Size 39 / 156.00 MiB ----------------free size
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav ~]# vgextend myvol /dev/sdc1
-----vg extended hdd size
Volume group "myvol" successfully
extended
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# vgdisplay ----after vg extend out put
--- Volume group ---
VG Size 2.99 GiB
Free PE / Size 550 / 2.15 GiB -------free size add
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
Dell]# lvextend -L +500M /dev/myvol/lv1
Extending logical volume lv1 to 1.76 GiB
[root@Tusharjahdav
Dell]# lvdisplay
LV Size 1.76 GiB
[root@Tusharjahdav
Dell]# vgdisplay
Free
PE / Size 315 / 1.23 GiB
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# resize2fs /dev/myvol/lv1
-------extend partition
[root@Tusharjahdav
Dell]# df –h
/dev/mapper/myvol-lv1 1.3G
11M 1.2G 1% /Dell
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# lvextend -l +100%free /dev/myvol/lv1
-----extend 100%
[root@Tusharjahdav
Dell]# vgdisplay
Free PE / Size 0 / 0
[root@Tusharjahdav
Dell]# lvdisplay
LV Size 2.99 GiB
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# resize2fs /dev/myvol/lv1
-------extend partition
root@Tusharjahdav
Dell]# df –h
/dev/mapper/myvol-lv1 2.9G
12M 2.8G 1% /Dell
1st
HDD
/dev/sdb1 2nd HDD -/dev/sdc1 3rd HDD -/dev/sdd1
PV -- 1GB
|
PV 2Gb Create
|
PV 1Gb Create
|
|||
VG – 1GB + 2GB+1GB = 4GB total value
of VG
VG extend
|
|||||
LV –1GB
Create 1GB lv1
1st
HDD
|
Lv1 2GB
2GB extend
2nd
HDD
|
Lv2 500M
3rd HDD
|
Lv1 500m extend
3rd HDD
|
Add 3 HDD and create 3 PV & extend 3VG and extend lv1 and
create 2nd - lv2
[root@Tusharjahdav ~]# fdisk –l -------3rd hdd installed in wm
1GB
Disk
/dev/sda: 21.5 GB, 21474836480 bytes
-------------default HDD
Disk
/dev/sdb: 1073 MB, 1073741824 bytes
----------------1st HDD add
Disk
/dev/sdc: 2147 MB, 2147483648 bytes
---------------2nd HDD
add
Disk
/dev/sdd: 1073 MB, 1073741824 bytes
----------------3rd
HDD add
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# fdisk /dev/sdd --------3nd hdd
partition
Command
(m for help): n
Command
action
e
extended
p
primary partition (1-4)
p
Partition number
(1-4): 1
First
cylinder (1-130, default 1):
Using
default value 1
Last
cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using
default value 130
Command
(m for help): t
Selected
partition 1
Hex
code (type L to list codes): 8e
Changed system
type of partition 1 to 8e (Linux LVM)
Command (m for
help): p
Disk
/dev/sdd: 1073 MB, 1073741824 bytes
255
heads, 63 sectors/track, 130 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: 0x3ae06673
Device
Boot Start End Blocks
Id System
/dev/sdd1 1 130
1044193+ 8e Linux LVM
[root@Tusharjahdav
~]# sync
[root@Tusharjahdav
~]# partprobe /dev/sdd
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav ~]# pvcreate /dev/sdd1
Physical volume "/dev/sdd1"
successfully created
[root@Tusharjahdav
~]# vgextend myvol /dev/sdd1
Volume group "myvol" successfully
extended
[root@Tusharjahdav
~]# pvdisplay
--- Physical volume ---
PV Name /dev/sdb1
VG Name myvol
PV Size 1019.72 MiB / not usable 3.72
MiB
--- Physical volume ---
PV Name /dev/sdc1
VG Name myvol
PV Size 2.00 GiB / not usable 3.32 MiB
--- Physical volume ---
PV Name /dev/sdd1
VG Name myvol
PV Size 1019.72 MiB / not usable 3.72
MiB
[root@Tusharjahdav
~]# vgdisplay
VG Name myvol
Format lvm2
VG Size 3.98 GiB
Alloc
PE / Size 765 / 2.99 GiB
Free
PE / Size 254 / 1016.00 MiB
[root@Tusharjahdav
~]# lvdisplay
LV Size 2.99 GiB
[root@Tusharjahdav ~]# lvcreate -L 500M -n lv2 myvol
Logical volume "lv2" created
[root@Tusharjahdav
~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvol/lv1
LV Name lv1
VG Name myvol
LV
Size 2.99 GiB
--- Logical volume ---
LV Path /dev/myvol/lv2
LV Name lv2
VG Name myvol
LV Size 500.00 MiB
[root@Tusharjahdav ~]# mkfs.ext3 /dev/myvol/lv2 ------format
lv2 volume
[root@Tusharjahdav ~]# mkdir /icecream ----create
DIR
[root@Tusharjahdav ~]#
mount /dev/myvol/lv2 /icecream/
[root@Tusharjahdav ~]# vi /etc/fstab
/dev/myvol/lv1 /Dell ext3 defaults 0 0
/dev/myvol/lv2 /icecream ext3 deafault 0 0
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav ~]# lvextend -L +300M /dev/myvol/lv1
----lv1 extend from 3rd hdd
[root@Tusharjahdav ~]# lvdisplay
---
Logical volume ---
LV
Path /dev/myvol/lv1
LV
Size 3.28 GiB
---
Logical volume ---
LV
Path /dev/myvol/lv2
LV
Name lv2
VG
Name myvol
LV
Size 500.00 MiB
[root@Tusharjahdav ~]# resize2fs
/dev/myvol/lv1 ----extend hdd size to
display df -h
-----------------------------------------------------------------------------------------------------------------
HOW TO REMOVE LVM PARTITION AND NEW HDD
1) [root@Tusharjahdav
~]# lvs -o +devices ----To check mapping lvm device
2)
root@Tusharjahdav ~]# Take
data backup
3) [root@Tusharjahdav
~]# umount /icecream -------------unmount /common drive
4) [root@Tusharjahdav
~]# vi /etc/fstab ------------------remove mount entry
from fstab
5) [root@Tusharjahdav
~]# lvremove /dev/myvol/lv1 -----remove lv1 partition
6) [root@Tusharjahdav
~]# vgremove myvol /dev/sdb--------remove
volume group
7) [root@Tusharjahdav
~]# pvremove /dev/sdb -------------------remove physical volume
8) [root@Tusharjahdav
~]# fdisk –l ----------------check hdd
9) [root@Tusharjahdav
~]# df –h --------------------check
hdd
10) [root@Tusharjahdav
~]# pvdisplay
11) [root@Tusharjahdav
~]# vgdisplay
12) [root@Tusharjahdav
~]# lvdisplay
13) [root@Tusharjahdav
~]# less /etc/fstab
14) [root@Tusharjahdav
~]# resize2fs /dev/myvol/lv1
15) [root@Tusharjahdav
~]# lvre
lvreduce lvremove
lvrename lvresize
-----------------------------------------------------------------------------------------------------------------
To
stand get the mapping devices ( check mount point)
[root@Tusharjahdav
~]# pvscan
PV /dev/sdb1
VG myvol lvm2 [1016.00 MiB /
0 free]
PV /dev/sdc1
VG myvol lvm2 [2.00 GiB / 0 free]
PV /dev/sdd1
VG myvol lvm2 [1016.00 MiB /
216.00 MiB free]
Total: 3 [3.98 GiB] / in use: 3 [3.98 GiB] /
in no VG: 0 [0 ]
[root@Tusharjahdav
~]# pvs
PV
VG Fmt Attr PSize
PFree
/dev/sdb1
myvol lvm2 a-- 1016.00m 0
/dev/sdc1
myvol lvm2 a-- 2.00g 0
/dev/sdd1
myvol lvm2 a-- 1016.00m 216.00m
[root@Tusharjahdav
~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "myvol" using
metadata type lvm2
[root@Tusharjahdav
~]# vgs
VG
#PV #LV #SN Attr VSize VFree
myvol
3 2 0 wz--n- 3.98g 216.00m
[root@Tusharjahdav
~]# lvscan
ACTIVE '/dev/myvol/lv1' [3.28 GiB] inherit
ACTIVE '/dev/myvol/lv2' [500.00 MiB]
inherit
[root@Tusharjahdav
~]# lvs
LV
VG Attr LSize
Pool Origin Data% Move Log
Cpy%Sync Convert
lv1
myvol -wi-ao---- 3.28g
lv2
myvol -wi-ao---- 500.00m
[root@Tusharjahdav
~]# pvs --segment
PV
VG Fmt Attr PSize
PFree Start SSize
/dev/sdb1
myvol lvm2 a-- 1016.00m 0
0 254
/dev/sdc1
myvol lvm2 a-- 2.00g 0
0 511
/dev/sdd1
myvol lvm2 a-- 1016.00m
216.00m 0 125
/dev/sdd1
myvol lvm2 a-- 1016.00m
216.00m 125 75
/dev/sdd1
myvol lvm2 a-- 1016.00m
216.00m 200 54
[root@Tusharjahdav
~]# lvs -o +devices
LV
VG Attr LSize
Pool Origin Data% Move Log
Cpy%Sync Convert Devices
lv1
myvol -wi-ao---- 3.28g
/dev/sdb1(0)
lv1
myvol -wi-ao---- 3.28g
/dev/sdc1(0)
lv1
myvol -wi-ao---- 3.28g
/dev/sdd1(125)
lv2
myvol -wi-ao---- 500.00m
/dev/sdd1(0)
How
to remove /dev/ssd1 hdd and remove lv2 and lv1
from 3nd hdd
1
pvremove
2
vgremove
3
lvremove
4
pvmove
[root@Tusharjahdav
~]# umount /icecream/
[root@Tusharjahdav
~]# lvdisplay
--- Logical volume ---
LV Path /dev/myvol/lv1
LV Name lv1
VG Name myvol
LV Size 3.28 GiB
--- Logical volume ---
LV Path /dev/myvol/lv2
LV Name lv2
VG Name myvol
LV Size 500.00 MiB
[root@Tusharjahdav
~]# lvremove /dev/myvol/lv2
Do
you really want to remove active logical volume lv2? [y/n]: y
Logical volume "lv2" successfully
removed
[root@Tusharjahdav ~]# lvdisplay --after lv2 remove
--- Logical volume ---
LV Path /dev/myvol/lv1
LV Name lv1
VG Name myvol
LV Size 3.28 GiB
[root@Tusharjahdav
~]# vgdisplay -----before reducing vg
--- Volume group ---
VG Name myvol
VG Size 3.98 GiB
[root@Tusharjahdav
~]# umount /Dell/ ----------------dell unmount for vg reduce
(off line )
[root@Tusharjahdav
~]# e2fsck -yc /dev/myvol/lv1 ------to check hdd
e2fsck
1.41.12 (17-May-2010)
Checking
for bad blocks (read-only test): done
/dev/myvol/lv1:
Updating bad block inode.
Pass
1: Checking inodes, blocks, and sizes
Pass
2: Checking directory structure
Pass
3: Checking directory connectivity
Pass
4: Checking reference counts
Pass
5: Checking group summary information
/dev/myvol/lv1:
***** FILE SYSTEM WAS MODIFIED *****
/dev/myvol/lv1:
15/853440 files (0.0% non-contiguous), 119128/3440640 blocks
[root@Tusharjahdav
~]# resize2fs /dev/myvol/lv1
resize2fs
1.41.12 (17-May-2010)
The
filesystem is already 3440640 blocks long.
Nothing to do!
[root@Tusharjahdav
~]# lvreduce -L 500M /dev/myvol/lv1
WARNING:
Reducing active logical volume to 500.00 MiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do
you really want to reduce lv1? [y/n]: y
Reducing logical volume lv1 to 500.00 MiB
Logical volume lv1 successfully resized
[root@Tusharjahdav
~]# vgreduce myvol /dev/sdd1
Removed "/dev/sdd1" from volume
group "myvol"
[root@Tusharjahdav
~]# pvremove /dev/sdd1
Labels
on physical volume "/dev/sdd1" successfully wiped
[root@Tusharjahdav
~]# mount /Dell/ -----remount dir
[root@Tusharjahdav
~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 18G 2.7G
14G 17% /
tmpfs 497M 72K
497M 1% /dev/shm
/dev/sda1 291M 34M
242M 13% /boot
/dev/mapper/myvol-lv1 3.2G
12M 3.1G 1% /Dell
-----------------------------------------------------------------------------------------------------------------
[root@centoshost
Desktop]# free -m
total used free
shared buffers cached
Mem: 1862 1033 829 3 62 542
-/+
buffers/cache: 428 1434
Swap: 3743 0
3743
-------------------------before extend swap memory size
oot@centoshost
Desktop]# fdisk /dev/sdc
Device Boot Start
End Blocks Id System
/dev/sdc1 1 130
1044193+
82 Linux
swap / Solaris
-----------------------------------------------------------------------------------------------------------------
[root@centoshost Desktop]# parted –l
-----------check hdd and partitions
Model:
VMware, VMware Virtual S (scsi)
Disk
/dev/sda: 53.7GB
Sector
size (logical/physical): 512B/512B
Number Start
End Size Type
File system Flags
1
1049kB 316MB 315MB
primary ext4 boot
2
316MB 4241MB 3926MB
primary linux-swap(v1)
3
4241MB 53.7GB 49.4GB
primary ext4
Model:
VMware, VMware Virtual S (scsi)
Disk
/dev/sdb: 2147MB
Sector
size (logical/physical): 512B/512B
Number Start
End Size Type
File system Flags
1
32.3kB 535MB
535MB primary lvm
2
535MB 1069MB
535MB primary lvm
3
1069MB 2147MB 1078MB
extended
5
1069MB 1604MB 535MB
logical
Model:
VMware, VMware Virtual S (scsi)
Disk
/dev/sdc: 1074MB
Sector
size (logical/physical): 512B/512B
Number Start
End Size Type
File system Flags
1
32.3kB 1069MB 1069MB
primary
-----------------------------------------------------------------------------------------------------------------
[root@centoshost
Desktop]# swapon –s ------check swap
partition maped on drives
Filename Type Size Used Priority
/dev/sda2 partition 3833852 0 -1
---swap access from 1 hdd
/dev/sdc1 partition 1044188 0
-2 ---swap access from 2 hdd
[root@centoshost
Desktop]# swapon –a -----read swap memory
-----------------------------------------------------------------------------------------------------------------
[root@centoshost
Desktop]# vi /etc/fstab -- add swap unique UID
UUID=7a615d1a-6239-4aa0-bb7f-62fc0078c986 swap swap defaults 0 0
-----------------------------------------------------------------------------------------------------------------
[root@centoshost
Desktop]# swapon -v /dev/sdc1 ------to extend swap memory
swapon
on /dev/sdc1
swapon:
/dev/sdc1: found swap signature: version 1, page-size 4, same byte order
swapon:
/dev/sdc1: pagesize=4096, swapsize=1069252608, devsize=1069254144
-----------------------------------------------------------------------------------------------------------------
[root@centoshost
Desktop]# free -m
total used free
shared buffers cached
Mem: 1862 1036 826 3 63 542
-/+
buffers/cache: 429 1433
Swap: 4763 0 4763 -------------------------After
extend swap memory size
-----------------------------------------------------------------------------------------------------------------
root@centoshost
Desktop]# swapoff /dev/sdc1 ----To reduce swap extended partition
root@centoshost
Desktop]# swapon -s
Filename Type Size
Used Priority
/dev/sda2 partition 3833852 0 -1
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
~]# lvmdiskscan -----check lvm partition
/dev/ram0 [
16.00 MiB]
/dev/myvol/lv1 [ 3.80 GiB]
/dev/ram1
[ 16.00 MiB]
/dev/sda1
[ 300.00 MiB]
/dev/myvol/cup [ 100.00 MiB]
/dev/ram2
[ 16.00 MiB]
/dev/sda2
[ 17.74 GiB]
/dev/ram3
[ 16.00 MiB]
/dev/sda3
[ 1.97 GiB]
/dev/ram4
[ 16.00 MiB]
/dev/ram5
[ 16.00 MiB]
/dev/ram6
[ 16.00 MiB]
/dev/ram7
[ 16.00 MiB]
/dev/ram8
[ 16.00 MiB]
/dev/ram9
[ 16.00 MiB]
/dev/ram10
[ 16.00 MiB]
/dev/ram11
[ 16.00 MiB]
/dev/ram12
[ 16.00 MiB]
/dev/ram13
[ 16.00 MiB]
/dev/ram14
[ 16.00 MiB]
/dev/ram15
[ 16.00 MiB]
/dev/sdb1
[ 1019.72 MiB] LVM physical volume
/dev/sdc1
[ 2.00 GiB] LVM physical volume
/dev/sdd1
[ 1019.72 MiB] LVM physical volume
1 disk
20 partitions
0 LVM physical volume whole disks
3 LVM physical volumes
----------------------------------------------------------------------------------------------------------------
Increase Your LVM size up to 6GB
Note: We have exiting value is 2GB, therefore to increases LVM up to
6GB
$ lvextend –L +4000M /dev/myvol/lv1
$ resize2fs /dev/myvol/lv1
-----------------------------------------------------------------------------------------------------------------
Reduce Your LVM size up to 1GB
Note: we have now LVM up to is 6GB, which have to decrease up to 1GB,
therefore
$ umount /home
$ e2fsck –yc /dev/myvol/lv1
$ resize2fs /dev/myvol/lv1 1000M
$ lvreduce –L 1000M /dev/myvol/lv1
$ mount –a
$ df –h
$ mount /dev/myval/lv1
/common.
-----------------------------------------------------------------------------------------------------------------
We can create different mount point
#...”/” ….LVM……Rescan Mode……….unmount
PV is divided into slice its call “pe”
PE default Size --- 4MB
1)….abc---------32MB size of file -----(8 pes
used)
2)….we can increase pe size eg pe size -8MB
3)…abc---------32MB size of file----(4 pes
used)
-----------------------------------------------------------------------------------------------------------------
LVM
STRIPPING
LVM
SNAPSHOTS
LVM
DUMP
LVM
MIRRORING
-----------------------------------------------------------------------------------------------------------------
We
can take this structure backup and restore
[root@Tusharjahdav
~]# vgcfgbackup myvol ------Take backup of VG
Volume group "myvol" successfully
backed up.
[root@Tusharjahdav
~]# ls /etc/lvm/backup/ --------LVM
backup Path
Myvol
-------------------------------------------------------------backup VG
(Myvol)
[root@Tusharjahdav
backup]# cat myvol
-------------------check myvol backup file
[root@Tusharjahdav
backup]# vgcfgrestore myvol
--------Restore LVM backup
Restored volume group myvol
-----------------------------------------------------------------------------------------------------------------
This
is configuration file of LVM
[root@Tusharjahdav
backup]# vi /etc/lvm/lvm.conf ------lvm config file
Filtering
and Exclude –To increase drive
ls /dev/cdrom -------given error
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
backup]# vi /etc/lvm/lvm.conf
#
Exclude the cdrom drive
filter
= [ "r|/dev/cdrom|usb-storage" ]---------uncomment of filter &
system stop scan device
-----------------------------------------------------------------------------------------------------------------
[root@Tusharjahdav
backup]# vgdisplay
--- Volume group ---
VG Name myvol
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 19
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size 3.98 GiB
PE Size 4.00 MiB
-------------------------------pe default value
Total PE 1019 ---------------------------total pe
Alloc PE / Size 998 / 3.90 GiB ------------------------assign pe3
Free
PE / Size 21 / 84.00 MiB
VG UUID
xcxXsZ-G0zf-oJMN-wssg-Ubj7-abAN-13iiat
How
to increase PE Size
What
is the limitation of pe
No comments:
Post a Comment