HOW TO EXTEND AND REDUCE LVM SIZE IN LINUX .

In this post you will learn how to extend or reduce lvm ( logical volume management). Google drive is one of the example of lvm . It provide space for its users to store data . In google drive minimum space is 15 GB but some users want extra space so they extend lvm . And if you want extra space you have to pay .

 

lvm in linux

  • First create partitions
[root@dhcppc10 ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 65399.
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
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57368-65399, default 57368):
Using default value 57368
Last cylinder or +size or +sizeM or +sizeK (57368-65399, default 65399): +1000M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57491-65399, default 57491):
Using default value 57491
Last cylinder or +size or +sizeM or +sizeK (57491-65399, default 65399): +1500M

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (57674-65399, default 57674):
Using default value 57674
Last cylinder or +size or +sizeM or +sizeK (57674-65399, default 65399): +2000M

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.
  • Mandatory – run partprobe command to save all changes made .
[root@dhcppc10 ~]# partprobe /dev/sda
  • Create physical volumes including these partitions .
[root@dhcppc10 ~]# pvcreate /dev/sda5 /dev/sda6 /dev/sda7
  Physical volume "/dev/sda5" successfully created
  Physical volume "/dev/sda6" successfully created
  Physical volume "/dev/sda7" successfully created
  • Over physical volume create vg ( volume group)
  • Type vgcreate  vgname   physicalvolumes
[root@dhcppc10 ~]# vgcreate vg11 /dev/sda5 /dev/sda6 /dev/sda7
  Volume group "vg11" successfully created
  • Now create lvm (logical volumes )
  • On lv1 i’ll show how to extend and in lv2 i’ll show how to reduce .
[root@dhcppc10 ~]# lvcreate -L +700M -n lv1 vg11
  Logical volume "lv1" created
[root@dhcppc10 ~]# lvcreate -L +1000M -n lv2 vg11
  Logical volume "lv2" created
  • Check by lvs command .
[root@dhcppc10 ~]# lvs
  LV   VG   Attr   LSize    Origin Snap%  Move Log Copy%  Convert
  lv1  vg11 -wi-a-  700.00M
  lv2  vg11 -wi-a- 1000.00M

HOW TO EXTEND LVM IN LINUX

extend lvm in linux

Type lvextend  -L then give size you want to increase after that lvm full name

It will take extra size from vg (volume group ) .

[root@dhcppc10 ~]# lvextend -L +300M /dev/vg11/lv1
  Extending logical volume lv1 to 1000.00 MB
  Logical volume lv1 successfully resized

HOW TO REDUCE LVM IN LINUX

reduce lvm in linux

Type lvreduce  -L  then give size you want to reduce after that lvm full name

It might ask “do you really want to reduce lv2 ? ” Type y and hit Enter .

[root@dhcppc10 ~]# lvreduce -L -300M /dev/vg11/lv2
  WARNING: Reducing active logical volume to 700.00 MB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv2? [y/n]: y
  Reducing logical volume lv2 to 700.00 MB
  Logical volume lv2 successfully resized
  • Check by lvs command
  • Lv1 is now extended its size to 1000MB
  • Lv2 is reduced to 700MB
[root@dhcppc10 ~]# lvs
  LV   VG   Attr   LSize    Origin Snap%  Move Log Copy%  Convert
  lv1  vg11 -wi-a- 1000.00M
  lv2  vg11 -wi-a-  700.00M

 

 

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s