Showing posts with label Lvm. Show all posts
Showing posts with label Lvm. Show all posts

Thursday, February 2, 2012

Resizing Online Multipath Disk in Linux

Here is the steps to Resize an Online Multipath Disk which is using Linux native device mapper as multipath solution.


1. Resize your physical disk in SAN. SAN Admins will do this. 
2. Use the following command to find the paths to the LUN:
# multipath -l
3. Now, Resize your paths. For SCSI devices, use the following command:
# echo 1 > /sys/block//device/rescan
4. Resize your multipath device by running the multipathd resize command:
# multipathd -k'resize map mpath0'
5. Resize the  File System (Assuming LVM is NOT used)
# resize2fs /dev/mapper/mpath0
If LVM is used, you need to do the following:
#pvscan
Check your Disk Changes detected under LVM:
#pvs or pvdisplay 
#vgscan
To check the VG Size is Increased:
#vgs or vgdisplay
Now Extend the LV: 
#lvextend -L +G
Finally Extend the File System
#resize2fs

Thursday, January 26, 2012

How To Create LVM Using vgcreate, lvcreate, and lvextend lvm2 Commands


LVM stands for Logical Volume Manager.
With LVM, we can create logical partitions that can span across one or more physical hard drives. First, the hard drives are divided into physical volumes, then those physical volumes are combined together to create the volume group and finally the logical volumes are created from volume group.
The LVM commands listed in this article are used under Ubuntu Distribution. But, it is the same for other Linux distributions.

Before we start, install the lvm2 package as shown below.
$ sudo apt-get intall lvm2
To create a LVM, we need to run through the following steps.
  • Select the physical storage devices for LVM
  • Create the Volume Group from Physical Volumes
  • Create Logical Volumes from Volume Group

Select the Physical Storage Devices for LVM – Use pvcreate, pvscan, pvdisplay Commands

In this step, we need to choose the physical volumes that will be used to create the LVM. We can create the physical volumes using pvcreate command as shown below.
$ sudo pvcreate /dev/sda6 /dev/sda7
Physical volume "/dev/sda6" successfully created
Physical volume "/dev/sda7" successfully created
As shown above two physical volumes are created – /dev/sda6 and /dev/sda7.
If the physical volumes are already created, you can view them using the pvscan command as shown below.
$ sudo pvscan
  PV /dev/sda6                      lvm2 [1.86 GB]
  PV /dev/sda7                      lvm2 [1.86 GB]
  Total: 2 [3.72 GB] / in use: 0 [0   ] / in no VG: 2 [3.72 GB]
You can view the list of physical volumes with attributes like size, physical extent size, total physical extent size, the free space, etc., using pvdisplay command as shown below.
$ sudo pvdisplay
--- Physical volume ---
  PV Name             /dev/sda6
  VG Name
  PV Size               1.86 GB / not usable 2.12 MB
  Allocatable           yes
  PE Size (KByte)    4096
  Total PE              476
  Free PE               456
  Allocated PE          20
  PV UUID               m67TXf-EY6w-6LuX-NNB6-kU4L-wnk8-NjjZfv 

  --- Physical volume ---
  PV Name             /dev/sda7
  VG Name
  PV Size               1.86 GB / not usable 2.12 MB
  Allocatable           yes
  PE Size (KByte)    4096
  Total PE              476
  Free PE               476
  Allocated PE          0
  PV UUID               b031x0-6rej-BcBu-bE2C-eCXG-jObu-0Boo0x
Note : PE – Physical Extents are nothing but equal-sized chunks. The default size of extent is 4MB.

Create the Volume Group – Use vgcreate, vgdisplay Commands

Volume groups are nothing but a pool of storage that consists of one or more physical volumes. Once you create the physical volume, you can create the volume group (VG) from these physical volumes (PV).
In this example, the volume group vol_grp1 is created from the two physical volumes as shown below.
$ sudo vgcreate vol_grp1 /dev/sda6 /dev/sda7
  Volume  group "vol_grp1" successfully created
LVM processes the storage in terms of extents. We can also change the extent size (from the default size 4MB) using -s flag.
vgdisplay command lists the created volume groups.
$ sudo vgdisplay
  --- Volume group ---
  VG Name                     vol_grp1
  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                      3.72 GB
  PE Size                      4.00 MB
  Total PE                     952
  Alloc PE / Size             0 / 0
  Free  PE / Size            952 / 3.72 GB
  VG UUID                     Kk1ufB-rT15-bSWe-5270-KDfZ-shUX-FUYBvR

LVM Create: Create Logical Volumes – Use lvcreate, lvdisplay command

Now, everything is ready to create the logical volumes from the volume groups. lvcreate command creates the logical volume with the size of 80MB.
$ sudo lvcreate -l 20 -n logical_vol1 vol_grp1
  Logical volume "logical_vol1" created
Use lvdisplay command as shown below, to view the available logical volumes with its attributes.
$ sudo lvdisplay
  --- Logical volume ---
  LV Name                /dev/vol_grp1/logical_vol1
  VG Name                vol_grp1
  LV UUID                 ap8sZ2-WqE1-6401-Kupm-DbnO-2P7g-x1HwtQ
  LV Write Access      read/write
  LV Status              available
  # open                  0
  LV Size                  80.00 MB
  Current LE              20
  Segments               1
  Allocation               inherit
  Read ahead sectors  auto
  - currently set to     256
  Block device            252:0
 
After creating the appropriate filesystem on the logical volumes, it becomes ready to use for the storage purpose.
$ sudo  mkfs.ext3 /dev/vol_grp1/logical_vol1

LVM resize: Change the size of the logical volumes – Use lvextend Command

We can extend the size of the logical volumes after creating it by using lvextend utility as shown below. The changes the size of the logical volume from 80MB to 100MB.
$ sudo lvextend -L100 /dev/vol_grp1/logical_vol1
  Extending logical volume logical_vol1 to 100.00 MB
  Logical volume logical_vol1 successfully resized
We can also add additional size to a specific logical volume as shown below.
$ sudo lvextend -L+100 /dev/vol_grp1/logical_vol1
  Extending logical volume logical_vol1 to 200.00 MB
  Logical volume logical_vol1 successfully resized

Tuesday, August 30, 2011

How to make LiveCD detect and mount LVM partition?


Reestablish Volume Group

To tap into the volume group you wish to work with, make sure /etc/lvm/lvm.conf filters are able to see the /dev/md? devices, and execute the following:
[tempsrv] # vgscan
Reading all physical volumes. This may take a while...
Found volume group "rootvg" using metadata type lvm2


which should display the volume group (here it is “rootvg”)associated with an md device you enabled. Then, to make the logical volumes (LVs) available for mounting, execute the following:
[tempsrv] # vgchange -ay rootvg

Now Mount the Logical Volumes:

Now all you need do is mount the reestablished LVs. I find this an excellent time to make use of Bash:
[tempsrv] # for i in `ls /dev/rootvg`; do mount /dev/rootvg/$i /mnt/$i; done;
Of course, you need to create the destination mount point before running the script.

Monday, August 29, 2011

How to mount a Logical Volume on a different Linux Server


I have finally converted to logical volumes which leaves me learning a whole new world. I was moving some data (500GB's) between machines using a USB drive and found that the logical volume on the drive would not quickly mount via traditional mount /dev/sd… command. So here is the process to mount a LVM.
1. Scan for the new volume (Assuming you added it after boot)
vgscan
2. Activate the volume
vgchange -a y VolumeName
3. Display the volume and confirm it's active
lvdisplay
4. Mount the volume via it's volume name
mount /dev/mapper/VolumeName /destination_mount_point

LVM Snapshot theory


LVM snapshots are meant to capture the filesystem in a frozen state. They are not meant to be a backup in and of themselves. They are, however, useful for obtaining backup images that are consistent because the frozen image cannot and will not change during the backup process. So while you won't use them directly to make long-term backups, they will be of great value in any backup process that you decide to use.
When LVM implements a snapshot, there are several things that happen, all very quickly. The first is that a new logical volume has to be allocated. The true purpose of this volume is to provide an area where deltas (changes) to the filesystem are recorded. This allows the original volume to continue on without disrupting any existing read/write access. The downside to this is that the snapshot area is of a finite size, which means on a system with busy writes, it can fill up rather quickly. For volumes that have significant write activity, you will want to increase the size of your snapshot to allow enough space for all changes to be recorded. If your snapshot overflows (fills up) both the original volume and the logical volume grind to a screeching halt. This is done to prevent filesystem corruption, although it has the effect of unceremoniously dropping any I/O (and therefore any programs) that were using the original volume. Should this happen, you will want to release your snapshot as soon as possible so you can get the original volume back online. Once the release is complete, you'll be able to remount the volume as read/write and make the filesystem on it available.
The second thing that happens is that LVM now "swaps" the true purposes of the volumes in question. You would think that the newly allocated snapshot would be the place to look for any changes to the filesystem, after all, it's where all the writes are going to, right? No, it's the other way around. Filesystems are mounted to LVM volumenames, so swapping out the name from underneath the rest of the system would be a no-no (because the snapshot uses a different name). So the solution here is simple: When you access the original volume name, it will continue to refer to the live(read/write) version of the volume you did the snapshot of. The snapshot volume you create will refer to the frozen (read-only) version of the volume you intend to back up. A little confusing at first, but it will make sense.
All of this happens in less than 2 seconds. The rest of the system doesn't even notice. Unless, of course, you don't release the snapshot before it overflows...
When you go to release a snapshot, it then takes all of the recorded changes and "replays" them back into the original volume. This takes a bit longer - depending on how much data was recorded - but won't significantly impact what you're doing. Once the release is complete, the snapshot volume is destroyed and the original remains. This is also why it is important to not "hold onto" snapshots - the data needs to be re-integrated back into the original "live" volume at some point.
There is a third, older version of a snapshot from the LVM version 1 days, that is read-only. This form of snapshot does not record changes to the filesystem. I do not recommend pursuing this as a long-term backup strategy. You are still hosting data on the same physical drive that can fail, and recovery of your filesystem from a drive that has failed is no backup at all.
So, in a nutshell:
Snapshots are good for assisting backups
Snapshots are not, in and of themselves, a form of backup
Snapshots do not last forever
A full snapshot is a BAD thing
Snapshots need to "go home" at some point (data needs to be re-integrated)
LVM is your friend, if you use it wisely.

Friday, August 19, 2011

lvm vs RAID1

So, what is the better approach? Using LVM mirroring capabilities or putting the LVM on a mdadm RAID 1.


lvm require extra log partition for mirroring. Altough that log partition doesn't require much space but still a extra pain.

LVM on mdadm RAID1 is more stable than LVM's own mirroring at the moment.

You don't need to partition the disk and create a new PV just for theLVM mirror log. You can use "--alloc anywhere" while creating the mirrorvolume and LVM will gladly allocate mirror log on one of your mirror legs.

What Is A Snapshot in lvm?

A snapshot is an operation in which we "freeze" the data on a logical volume, while still enabling writing new data.


This, of-course, is an oxymoron.

It is solved by splitting the data to old (written before taking the snapshot) and new (written after taking the snapshot).

The old data resides on the original logical volume.

The new data is written to a different disk.

When an application reads from the device, the underlying kernel code finds where lies the fresh copy of the data, and returns that to the application.

Meanwhile, we may mount the original (frozen) content on a different directory, and access it in read-only mode.

E.g. to backup the data.

Accidentally removed an lvm can i restore it?

Following command can be helpful in this scenario

vgcfgrestore

Also look at your /etc/lvm/archive/ for all archived metadata.

You should be able to use '--list' option.

Move LVM Volume Group to another computer

To move a volume group form one system to another, perform the following steps:


Make sure that no users are accessing files on the active volumes in the volume group, then unmount the logical volumes.

Use the -a n argument of the vgchange command to mark the volume group as inactive, which prevents any further activity on the volume group.

Use the vgexport command to export the volume group. This prevents it from being accessed by the system from which you are removing it.

After you export the volume group, the physical volume will show up as being in an exported volume group when you execute the pvscan command.

When the disks are plugged into the new system, use the vgimport command to import the volume group, making it accessible to the new system.

Activate the volume group with the -a y argument of the vgchange command.

Mount the file system to make it available for use.

Wednesday, August 17, 2011

Recover LVM from Corrupted physical volume

I had Volume Group /dev/vg1 that consist two physical volumes /dev/sdb1 and /dev/sdc1 . One of physical volume /dev/sdc1, corrupted due to disk problem , now the challenge was to recover LVM. I decided to use pvremove command, in following way


root#pvremove /dev/sdc1

Above command displayed error couldn't find device uuid 'xxxxxxx'

Then issue tried forcefully

root#pvremove -ff /dev/sdc1

After some warning, it removed that physical volume.

Then i issued pvdisplay command

root#pvdisplay

This display message ' Couldn't find device with uuid xxxxxx'

Now what you need to do is to create a physical volume with new disk with missing uuid .

For that following command can be used

root# pvcreate --uuid=xxxxxx /dev/sdd1 --restorefile=/etc/lvm/archive/vg0_0.vg

Where /dev/sdd1 is new hard disk in replace of /dev/sdc1

Then restore the vg metadata with following command

root# vgcfgrestore -f /etc/lvm/archive/vg0_0.vg tvg0

Note: check archive of vg in /etc/lvm/archive

LVM Snapshots

First of all some of important facts about LVM Snapshots


A snapshot volume does not have to be as large as the source volume

LVM snapshots use a copy on write (CoW) technology

The snapshot volume only needs to be large enough to accommodate the maximum number of changes that might occur to the source volume during the life of the snapshot.

Snapshot is really just a copy of the inode tree at the point in time you created it

Let us understand this with an example. Suppose you have a 20GB Logical Volume where you storing your data. Now suppose in normal circumstance approx 500MB of data get some changes daily. In this case you need to create 500MB LVM snapshot for your 20GB LVM. The modified data of LVM stored on snapshot instead of LVM. So when it is time to read from the snapshot , any changed blocks are read from the snapshot area. But any blocks that haven't changed since the snapshot are read from the original.

LVM snapshots can be used for taking data backup of live system. You can keep snapshot for a given period of time after that you can take backup of snapshot for its further uses. It you need to recover data from snapshot you need to mount it separately and get data from it.

Command to create snapshot:

root#lvcreate -L 500M -s -n databackup /dev/vg1/lv1

Here databackup is name of snapshot and its size will be 500MB. This is snapshot of Logical Volume lv1.

To recover data from snapshot, you need to mount it as following and then perform recovery

root#mount -t ext3 /dev/vg1/databackup /mnt

To take backup of LVM snapshot for further references, you may use following command

root#tar -cf /mybackup/lv1backup /mnt

After taking it is advisable to remove snapshot, for that you can use following command

root#umount /mnt

root#lvremove /dev/vg1/databackup

Sunday, June 19, 2011

An introduction to Logical Volume Management (LVM)


harddisk
Logical Volume Management (LVM) is a method of allocating space on mass storage devices that is more flexible than conventional partitioning schemes. To understand how LVM works we will first take a look at some terminology:
  • PV: Physical Volume. This can be an entire harddisk, a partition on a harddisk, a RAID device (software or hardware), a LUN, etc.
  • VG: Volume Group. This is an aggregation of one or more PVs, summing small storage spaces into a bigger consolidated one.
  • LV: Logical Volume. This is a part of a VG that can be used to put a filesystem on.
As an example of how these terms work together, have a look at the following picture:
lvm
Breaking things up into these parts means that we can do fun stuff with LVM. First of all, we can have a filesystem that is bigger than the biggest harddisk we have in the system. We can also grow and shrink the space that is given to a filesystem and even do this while the filesystem is being used. Finally, we can create snapshots, read-only ones for backup purposes and read-write ones that allow us to have multiple versions of a filesystem.
Creating
We start by creating the physical volumes (PVs). If you are using a full harddisk as a physical volume it is best to create 1 partition on it that fills the whole disk. The type of the partition can best be set to “8E”, which is the type for “Linux LVM”. You can do this by running fdisk (“n” for new partition, “t” to change the type and “w” to write changes). Afterwards run partprobe to detect the new partitions:
fdisk /dev/sdb
partprobe
Create the physical volume on the partitions. Let’s assume we have three volumes: /dev/sdb1, /dev/sdb2 and /dev/sdb3:
pvcreate /dev/sdb{1,2,3}
pvdisplay /dev/sdb{1,2,3}
Create the volume group “vg0″ that will group these physical volumes together:
vgcreate /dev/vg0 /dev/sdb{1,2,3}
vgdisplay /dev/vg0
Create a logical volume named “lv0″ from the volume group “vg0″ with a size of 100MiB:
lvcreate -L 100M -n lv0 /dev/vg0
lvdisplay /dev/vg0/lv0
Create a filesystem on top of the logical volume “lv0″ and mount it:
mke2fs -j /dev/vg0/lv0
mount /dev/vg0/lv0 /mnt
Growing
We will now grow the filesystem. This can be done when the filesystem is offline, but ext3 also supports online growing. We start by growing the space that is available to the filesystem in the logical volume “lv0″:
lvextend -L 120M /dev/vg0/lv0
Now we can ask the filesystem to occupy the extra space it has been given:
resize2fs /dev/vg0/lv0
Shrinking
Shrinking a filesystem is a bit more difficult. First we need to unmount the filesystem:
umount /mnt
Run a filesystem check and resize it:
e2fsck -f /dev/vg0/lv0
resize2fs /dev/vg0/lv0 80M
Mount the filesystem again:
mount /dev/vg0/lv0 /mnt
At this time, the filesystem is smaller than its logical volume, so we can shrink it:
lvreduce -L 80M /dev/vg0/lv0

Tuesday, May 17, 2011

Logical Volume Management (LVM)


Features:
1. Ability to create volume sets and stripe sets
2. LVM masks the underlying physical technology (ATA,ATAPI,IDE,SCSI,SATA,PATA,etc.)
3. LVM represents storage using a hierarchy:
a. Volume groups
a1. Physical volumes (/dev/sda2, /dev/sdb2, etc.)
b. Logical Volumes
b1. File systems
3. LVM physical volumes can be of various sizes
4. Ability to resize volumes on the fly

Note: Volume groups join: physical volumes (PVs) and Logical Volumes (LVs)


6 Steps to setup LVM:
1. Create LVM partitions via fdisk or parted
a. fdisk /dev/sda, /dev/sdb, /dev/sdc
b. n
c. p
d. +10G
e. t - change to type '8e' (LVM)
f. w
g. partprobe /dev/sda

2. Create Physical Volumes using 'pvcreate'
a. pvcreate /dev/sda3 /dev/sdb3 /dev/sdc3

3. Create Volume Groups using 'vgcreate'
a. vgcreate volgroup001 /dev/sda3 /dev/sdb3 /dev/sdc3
Note: Volume groups can be segmented into multiple logical volumes

4. Create one or more Logical Volumes
a. lvcreate -L 10GB -n logvolvar1 volgroup001
b. lvcreate -L 10GB -n logvolusr1 volgroup001

5. Create File system on logical volume(s)
a. mke2fs -j /dev/volgroup001/logvolvar1
b. mke2fs -j /dev/volgroup001/logvolusr1

6. Mount logical volume
a. mkdir /var1
b. mount /dev/volgroup001/logvolvar1 /var1
c. mkdir /usr1
d. mount /dev/volgroup001/logvolusr1 /usr1


Note: Be certain to update: /etc/fstab so that volumes are mounted when the system reboots

3-tiers of LVM display commands include:
a. pvdisplay - physical volumes - represent raw LVM partitions
b. vgdisplay - volume groups - aggregate physical volumes
c. lvdisplay - logical volumes - file systems - mount here


Rename of Logical Volume:
1. lvrename volume_group_name old new - used to rename volumes

Task: Rename 'logvolvar1' to 'logvolopt1'
a. lvrename volgroup001 logvolvar1 logvolopt1
Note: LVM is updated immediately, even while volume is mounted
However, you must remount the logical volume to see the changes
b. umount /var1 && mount /dev/mapper/volgroup001-logvolopt1 /opt1
c. Update /etc/fstab


Remove Logical Volume:
Task: Remove 'logvolusr1' from the logical volume pool
a. umount /usr1
b. lvremove /dev/mapper/volgroup001-logvolusr1
c. use 'lvdisplay' to confirm removal


Resize Logical Volume:
Task: Grow (resize) 'logvolopt1' to 20GB
a. lvresize -L 20GB /dev/volgroup001/logvolopt1
b. lvdisplay - to confirm new size of logical volume
c. df -h - will still reveal the current size
d. Resize the file system to update the INODE table on the logical volume to account for the new storage in 'logvolopt1'
'resize2fs -f -p /dev/volgroup001/logvolopt1'

Note: You may resize file systems online if the following are met:
1. 2.6x kernel series
2. MUST be formatted with ext3

Task: Shrink (resize) 'logvolopt1' to 15GB
a. lvresize -L 15GB /dev/volgroup001/logvolopt1
b. lvdisplay
c. df -h
d. resize2fs -f -p /dev/volgroup001/logvolopt1
Note: online shrinking is not supported
e. df -h

Note: Check disk utilization prior to shrinking to reduce the risk of losing data

LVM GUI Utility:
system-config-lvm

Tuesday, August 24, 2010

LVM

1. Logical Volume Manager is the esier way to manage hard disk by resizing

logical volumes.

2. The LVM2 packge is used for kernel 2.6.

3. In LVM structure there are three levels of organisation :-

physical volume - volume group - logical volume

4. Linux LVM partition has 8e code.

5. The physical partitions i.e. physical volumes turns into volume groups

that then turns into logical volumes.

This logical volumes are assigned mount points and file system types

like ext2, ext3.

When "partitions" reach their full capacity, free space from the volume

group can be added to the logical volume to increase the size of the

partition. When a new hard drive is added to the system, it can be added

to the volume group,and partitions that are logical volumes can be

increased in size.



#############################################



STEPS TO CONFIGURE LVM :



# Creating Physical Volumes

# Creating Volume Groups

# Creating Logical Volumes and assigning mount points.

# Resizing VG and LVs.

# Removing PV, VG and LVs.

# Monitoring PV, VG and LVS.





######## LOGICAL VOLUME MANAGER CONFIGURETION #######



1)To create the partition.

#fdisk /dev/sda

#partprobe /dev/sda



2)To create the PV (physical volume)

# pvcreate /dev/sda9 /dev/sda10 /dev/sda11

Physical volume "/dev/sda9" successfully created

Physical volume "/dev/sda10" successfully created

Physical volume "/dev/sda11" successfully created



3)To check PV

#pvdisplay



4)To create the VG (volume group)

#vgcreate india /dev/sda9 /dev/sda10 /dev/sda11

Volume group "india" successfully created



5)To check VG

#vgdisplay



6)To create the LV (logical volume).

#lvcreate -L 20m india -n mumbai

#lvcreate -L 20m india -n chennai

#lvcreate -L 20m india -n dehli



7)To check LV.

#lvdisplay



8)To extend the VG.

#fdisk -l

#fdisk /dev/sda

#partprobe /dev/sda

#pvcreate /dev/sda12

Physical volume "/dev/sda12" successfully created

#vgextend india /dev/sda12

Volume group "india" successfully extended



9)To resize the LV.

#lvresize -L +50m /dev/india/mumbai

Rounding up size to full physical extent 52.00 MB

Extending logical volume mumbai to 72.00 MB

Logical volume mumbai successfully resized



10)To check the LV by mounting.



1)To create mount point.

#mkdir /mumbai

#mkdir /chennai

#mkdir /delhi



2)To format the LV.

#mkfs.ext3 /dev/india/mumbai

#mkfs.ext3 /dev/india/chennai

#mkfs.ext3 /dev/india/delhi



3)To mount on mount point.

#mount /dev/india/mumbai /mumbai

#mount /dev/india/mumbai /chennai

#mount /dev/india/mumbai /delhi



4)To check.

#mount

/dev/mapper/india-mumbai on /mumbai type ext3 (rw)

#umount



11)LV Remove.

#lvremove /dev/india/mumbai

Do you really want to remove active logical volume "mumbai"? [y/n]: y

Logical volume "mumbai" successfully removed

#lvremove /dev/india/chennai

#lvremove /dev/india/delhi



12)VG Remove.

#vgremove india

Volume group "india" successfully removed



13)PV Remove.

#pvremove /dev/sda9 /dev/sda10 /dev/sda11 /dev/sda12

Labels on physical volume "/dev/sda9" successfully wiped

Labels on physical volume "/dev/sda10" successfully wiped

Labels on physical volume "/dev/sda11" successfully wiped

Labels on physical volume "/dev/sda12" successfully wiped



14)To update the logical volume with kernel.

#resize2fs /dev/share/mkt

Saturday, August 14, 2010

Resize Logical Volume (LV) in Linux


Here is the quick steps to Resize Logical Volume in Linux..

If you want grow (resize) 'logvolopt1' to 20GB

 1. lvresize -L 20GB /dev/volgroup001/logvolopt1
 2. lvdisplay - to confirm new size of logical volume
 3. df -h - will still reveal the current size
 4. Resize the file system to update the INODE table on the logical volume to account for the new storage in 'logvolopt1'
  'resize2fs -f -p /dev/volgroup001/logvolopt1'

Note: You may resize file systems online if the following are met:

  a. 2.6x kernel series
  b. MUST be formatted with ext3

If you want to shrink (resize) 'logvolopt1' to 15GB

 1. lvresize -L 15GB /dev/volgroup001/logvolopt1
 2. lvdisplay 
 3. df -h 
 4. resize2fs -f -p /dev/volgroup001/logvolopt1

 Note: online shrinking is not supported

 5. df -h

Note: Check disk utilization prior to shrinking to reduce the risk of losing data.. 

Hope these Quick HOWTO will help administrators for quick reference.
cheers :-)