Tuesday, September 25, 2012

step by step configuration of lvm in linux









step by step configuration of lvm in linux ::--




Logical Volume Manager

2. Create Partitions

For this Linux lvm example you need an unpartitioned hard disk /dev/sdb. First you need to create physical volumes. To do this you need partitions or a whole disk. It is possible to run pvcreate command on /dev/sdb, but I prefer to use partitions and from partitions I later create physical volumes.
Logical Volume Manager List Partitions with fdisk
Use your preferred partitioning tool to create partitions. In this example I have used cfdisk.
Create partitions with cfdiskLogical Volume Manager List Partitions with fdisk

Partitions are ready to use.

3. Create physical volumes

Use the pvcreate command to create physical volumes.
# pvcreate /dev/sdb1
# pvcreate /dev/sdb2 
The pvdisplay command displays all physical volumes on your system.
# pvdisplay 
Alternatively the following command should be used:
# pvdisplay /dev/sdb1 
Create physical volumes with pvcreate

4. Create Virtual Group

At this stage you need to create a virtual group which will serve as a container for your physical volumes. To create a virtual group with the name "mynew_vg" which will include /dev/sdb1 partition, you can issue the following command:
# vgcreate mynew_vg /dev/sdb1 
To include both partitions at once you can use this command:
# vgcreate mynew_vg /dev/sdb1 /dev/sdb2 
Create Virtual Group
Feel free to add new physical volumes to a virtual group by using the vgextend command.
# vgextend mynew_vg /dev/sdb2 
virtual group extend

5. Create Logical Volumes

From your big cake (virtual group) you can cut pieces (logical volumes) which will be treated as a partitions for your linux system. To create a logical volume, named "vol01", with a size of 400 MB from the virtual group "mynew_vg" use the following command:
  • create a logical volume of size 400 MB -L 400
  • create a logical volume of size 4 GB -L 4G
# lvcreate -L 400 -n vol01 mynew_vg
lvm lvcreate
With a following example you will create a logical volume with a size of 1GB and with the name vol02:
# lvcreate -L 1000 -n vol02 mynew_vg

lvcreate
Note the free size in virtual group.
lvcrete free space

6. Create File system on logical volumes

The logical volume is almost ready to use. All you need to do is to create a filesystem.:
# mkfs.ext3 -m 0 /dev/mynew_vg/vol01 
the -m option specifies the percentage reserved for the super-user, set this to 0 if you wish not to waste any space, the default is 5%. create file system on the logical volumes

7. Edit /etc/fstab

Add an entry for your newly created logical volume into /etc/fstab
edit /etc/fstab to include logical volumes

7.1. Mount logical volumes

Before you mount do not forget to create a mount point.
# mkdir /home/foobar 
mount logical volumes

8. Extend logical volume

The biggest advantage of logical volume manager is that you can extend your logical volumes any time you are running out of the space. To increase the size of a logical volume by another 800 MB you can run this command:
# lvextend -L +800 /dev/mynew_vg/vol01 
Extend logical volume
The command above does not actually increase the physical size of volume, to do that you need to:
# resize2fs  /dev/mynew_vg/vol01 
Look at the figure below to see what problems you may encounter when extending a volume:
Problem with extending a logical volume

9. Remove logical volume

The command lvremove can be used to remove logical volumes. Make sure that before you attempt to remove logical volumes your logical volume does not have any valuable data stored on it, moreover, make sure the volume is unmounted.
# lvdisplay 
display volume group
# lvremove /dev/mynew_vg/vol02 
remove logical volume===================================================



Setup Ubuntu Logical Volume Manager (LVM) Step By Step

In my last post I explained about the concepts of the Logical Volume Manager (LVM). If you need some background on Logical Volume Manager (LVM) or you are new to LINUX you can read the post Understanding The Concept Of Logical Volume Manager – LVM. Now hope you have a fair background with linux and the LVM lets try to setup it on a Ubuntu Linux Machine, you can use any LINUX distribution to set Setup Logical Volume Manager (LVM). The commands are almost same.

The setup of my machine is :-
1.) Primary Disk 20 Gb (dev/sda).
2.) Secondary Disk 10 GB (dev/sdb) [Will be used for LVM].
3.) Third Disk 6GB (dev/sdc) [Will be used for LVM].
Now to find the partitions or drives in your machine you can use the following command.
sudo fdisk -l
1 How To Setup Logical Volume Manager LVM Step By Step How To Setup Logical Volume Manager (LVM) Step By Step
Now as per my previous post I want to use the same partition size for secondary disk as 10Gb but 3 Gb for Third disk because I also want to show how to extend the LVM partition. So we start by formatting the drives.
STEP1.) Partitioning the 10 Gb drive
sudo fdisk /dev/sdb
Note:- The hard drive name can be different in your system.
Now press n to create a new partition .
Now press p to make it a primary partition.
Now it will ask you to specify the starting cylinder as it is a raw disk and we need to use it the full capacity simply press enter.
Now enter the last cylinder. Just simply press enter as we need to use the whole disk. The drive has been initialized and read to be formatted.
You can check the partition information by pressing the p. All the steps are explained in the following image.
3 How To Setup Logical Volume Manager LVM Step By Step1 How To Setup Logical Volume Manager (LVM) Step By Step
Now after finishing the above step we see that the above partition type is LINUX (Code 83) so we need to make it type LVM.
Now press t
Select the partition ( In this case we have only single partition on the disk so one will be automatically selected)
Now we need to enter the HEX code for the partition type . To find the Codes we can use l.
Now from the list we know the code is 8e. So type8e. The partition type is now LVM. Now to write the changes press w.
Now to make the kernel aware of the changes use partprobe command.
sudo partprobe /dev/sdb
4 How To Setup Logical Volume Manager LVM Step By Step How To Setup Logical Volume Manager (LVM) Step By Step
Now we need to have our third hard-drive ready for the LVM we repeat the same step again but not taking the default start and finish cylinder number instead we specify the size as according to our need. I am using 4 GB ( the previous post explaining mentioned 6GB but to show how to extend LVM I am using 4GB.
So lets start again with the new drive :-
sudo fdisk /dev/sdc
Type n for new partition.
Now type p for making it a primary partition.
Now press enter as we are starting from a raw disk
Now on the finishing cylinder type +4G as we need the size 4GB.
Press t and type 8e (LINUX LVM partition code)
Press w to write changes. You can also issue the command
sudo partprobe /dev/sdc
your basic work is done. The drives are ready to be used to setup LVM.
All the steps can be verified from the following image.
5 How To Setup Logical Volume Manager LVM Step By Step How To Setup Logical Volume Manager (LVM) Step By Step
STEP2.) Create the Physical Volumes
sudo pvcreate /dev/sdb1 /dev/sdc1
Now Create the Volume Group the name of the volume group is routemybrain
sudo vgcreate routemybrain /dev/sdb1 /dev/sdc1
You can verify the LOGICAL GROUP using the command vgdisplay
7 How To Setup Logical Volume Manager LVM Step By Step How To Setup Logical Volume Manager (LVM) Step By Step
Creating the Logical volume
sudo lvcreate routemybrain -L +14G -n akash
routemybrain -> The name of the volume group
-L -> To specify the size of the partition in our case 14GB
-n -> To specify the name of the Logical volume in our case akash.
we can see the logical volume with the help of lvdisplay.
8 How To Setup Logical Volume Manager LVM Step By Step How To Setup Logical Volume Manager (LVM) Step By Step
The LVM setup is done and finally we have created a LVM parition of 14gb now the final step just to mount it.
STEP3.) Make a directory for mounting the share
sudo mkdir /home/newtrojan/Lvm-Mount
now format the LVM partition.
sudo mkfs.ext3 /dev/routemybrain/akash
Now mount the partition
sudo mount /dev/routemybrain/akash /home/newtrojan/Lvm_Mount
9 How To Setup Logical Volume Manager LVM Step By Step How To Setup Logical Volume Manager (LVM) Step By Step
you can verify the mount by issuing df -h command
10 How To Setup Logical Volume Manager LVM Step By Step How To Setup Logical Volume Manager (LVM) Step By Step
That was really a long post. In the next post I will be explaining how to extend, resize or delete a Logical Volume Manager (LVM) partition



 +++++++=====++++++++==========++++++++++++++++===


LVM Configuration PDF Print E-mail
LVM Configuration
Physical Volume Creation
Volume Group Creation
Logical Volume Creation
Formatting a File System
Mounting a File System
All Pages

LVM Overview


LVM or Logical Volume Management is a tool used by Unix/Linux administrators to manage disk resources.  LVM provides a layer of abstraction between the underlying physical disk/volume and the host operating system (Unix administrators often refer to disks as volumes.)  LVM partitions can span across physical hard drives and can be re-sized (unlike traditional ext3 "raw" partitions.)  LVM partitions offers features such as resizing, snapshots and mirroring of volumes all of which can be very useful in a variety of situations for management of disk in the enterprise.
In this KB article, we'll show you how to configure LVM on a Linux system.  You can find additional articles in the Linux KB to guide you through other LVM administrative tasks such as renaming, removing, resizing, snapshots and mirroring.
Note: LVM is only supported in the Linux kernel 2.4 and above.  If you don't have support for LVM, you may have to recompile your kernel from source.
LVM Creation can be broken down into 7 steps:
  1. Partitioning
  2. Physical volume(s) creation
  3. Volume group(s) creation
  4. Logical volume(s) creation
  5. Formatting of the file system
  6. Mounting of file system
  7. Updating fstab for automatic volume mounting

Partitioning


LVM partitions must be of type 8e (Linux LVM.)  We are going to use fdisk to define three (3) new partitions on available disks installed in our server.
  1. Lets begin by taking a look at our current disks and their associated partitions (you must be root)

    [root@Linux01 ~]# 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          13      104391   83  Linux
    /dev/sda2              14        1305    10377990   8e  Linux LVM

    Disk /dev/sdb: 4294 MB, 4294967296 bytes
    255 heads, 63 sectors/track, 522 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Disk /dev/sdb doesn't contain a valid partition table

    Disk /dev/sdc: 4294 MB, 4294967296 bytes
    255 heads, 63 sectors/track, 522 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Disk /dev/sdc doesn't contain a valid partition table

    Disk /dev/sdd: 4294 MB, 4294967296 bytes
    255 heads, 63 sectors/track, 522 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Disk /dev/sdd doesn't contain a valid partition table
    [root@Linux01 ~]#

    As you can see, we have one disk (/dev/sda) which already has a couple of partitions (for the running OS.)  We have highlighted the three available disks which we will use for our LVM file system (/dev/sdb, /dev/sdc/ and /dev/sdd).
  2. Define a new partition of type 8e (Linux LVM) on /dev/sdb using fdisk

    [root@Linux01 ~]# fdisk /dev/sdbDevice contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
    Building a new DOS disklabel. Changes will remain in memory only,
    until you decide to write them. After that, of course, the previous
    content won't be recoverable.

    Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

    Command (m for help): n
    Command action
    e   extended
    p   primary partition (1-4)
    p

    Partition number (1-4): 1
    First cylinder (1-522, default 1): 1
    Last cylinder or +size or +sizeM or +sizeK (1-522, default 522): 522
  3. Change the type of the file system to 8e (Linux LVM)

    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/sdb: 4294 MB, 4294967296 bytes
    255 heads, 63 sectors/track, 522 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1               1         522     4192933+  8e  Linux LVM
  4. Write the changes to the partition table

    Command (m for help): w
    The partition table has been altered!

    Calling ioctl() to re-read partition table.
    Syncing disks.
    [root@Linux01 ~]#
  5. Repeat steps 2 - 4 until all the drives have partitions of type 8e created on them 

Physical Volume Creation


Physical volumes are the disk resources used to create the LVM.  The volumes are usually simple disk partitions (i.e. /dev/sda1, /dev/sda2 etc) or they can be Linux software RAID volumes (i.e. /dev/md0, /dev/md1 etc.)  It is important to note that LVM does not provide data protection or redundancy such as RAID, so additional measures should be taken to ensure fault tolerance is built into the LVM volumes.
We will use pvcreate to initialize the newly created partitions.
  1. Check to see what (if any) physical volumes (PV's) already exist on the system

    [root@Linux01 ~]# pvdisplay
    --- Physical volume ---
    PV Name
    VG Name
    PV Size
    Allocatable
    PE Size (KByte)
    Total PE
    Free PE
    Allocated PE
    PV UUID

    [root@Linux01 ~]#


    /dev/sda2
    VolGroup00
    9.90 GB / not usable 22.76 MB
    yes (but full)
    32768
    316
    0
    316
    3NzAOq-mdpQ-3XDA-eqAE-F0jf-Y22F-s1lTQ4


    We already have one PV created on our system (this is in use by our OS) which is a member of Volume Group VolGroup00
  2. Create 3 new physical volumes (PV's) from /dev/sdb1, /dev/sdc1 and /dev/sdd1

    [root@Linux01 ~]# pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd1
    Physical volume "/dev/sdb1" successfully created
    Physical volume "/dev/sdc1" successfully created
    Physical volume "/dev/sdd1" successfully created
    [root@Linux01 ~]#
  3. Verify the creation of the new volumes with pvdisplay

    [root@Linux01 ~]# pvdisplay
    --- Physical volume ---
    PV Name /dev/sda2
    VG Name VolGroup00
    PV Size 9.90 GB / not usable 22.76 MB
    Allocatable yes (but full)
    PE Size (KByte) 32768
    Total PE 316
    Free PE 0
    Allocated PE 316
    PV UUID 3NzAOq-mdpQ-3XDA-eqAE-F0jf-Y22F-s1lTQ4

    "/dev/sdb1" is a new physical volume of "4.00 GB"
    --- NEW Physical volume ---
    PV Name /dev/sdb1
    VG Name
    PV Size 4.00 GB
    Allocatable NO
    PE Size (KByte) 0
    Total PE 0
    Free PE 0
    Allocated PE 0
    PV UUID Co3JxS-qx30-clUX-wP3t-1xmV-tjBK-QmoyBr

    "/dev/sdc1" is a new physical volume of "4.00 GB"
    --- NEW Physical volume ---
    PV Name /dev/sdc1
    VG Name
    PV Size 4.00 GB
    Allocatable NO
    PE Size (KByte) 0
    Total PE 0
    Free PE 0
    Allocated PE 0
    PV UUID jcNBJ9-Mqh6-dsFD-Z14x-jpoo-Rhh2-z1hGIf

    "/dev/sdd1" is a new physical volume of "4.00 GB"
    --- NEW Physical volume ---
    PV Name /dev/sdd1
    VG Name
    PV Size 4.00 GB
    Allocatable NO
    PE Size (KByte) 0
    Total PE 0
    Free PE 0
    Allocated PE 0
    PV UUID UQVaeK-sRTe-iKJw-IEVd-38fn-3kiK-qqWhEt



Volume Group Creation


We are now ready to create a Volume Group (VG).  A Volume group acts as a container of resources for Physical Volumes.  So in other words, the total space available to a LV is created from VG's which have partitions or physical volumes (PV's) associated to them.
When a volume group is created, equally sized chucks or extents are defined.  By default, a physical extent size of 4MB is used however this can be altered with a "-s PhysicalExtentSize [kKmMgGtT]" command line switch (more on that in a minute.)
We can increase or decrease the size of a LV by the addition or removal of physical extents to/from the LV.  This is important as there exists some limitations on 2.4 based kernels.  2.4 based kernels have a maximum LV size is 2TB (32-bit CPUs on 2.6 kernels have a maximum LV size of 16TB and 8EB for 64-bit CPUs.)  2.4 based kernels can also only have at most 65534 extents (2.6 kernels do not have this limitation.)  So the only way to reach a full 2TB LV size on a 2.4 based kernel would be with an extent size of 32MB (32 x 65534 = 2097088MB / 1024MB = 2,047GB or 2TB.)
We are now going to create a new Volume Group using a 32MB physical extent size.
  1. Lets begin by taking a look at the Volume Groups the are already present on the system

    [root@Linux01 ~]# vgdisplay
    --- Volume group ---
    VG Name VolGroup00
    System ID
    Format lvm2
    Metadata Areas 1
    Metadata Sequence No 6
    VG Access read/write
    VG Status resizable
    MAX LV 0
    Cur LV 5
    Open LV 5
    Max PV 0
    Cur PV 1
    Act PV 1
    VG Size 9.88 GB
    PE Size 32.00 MB
    Total PE 316
    Alloc PE / Size 316 / 9.88 GB
    Free PE / Size 0 / 0
    VG UUID zz6pnX-TR24-jPcE-zHrv-loz5-TPd2-eERHtq
  2. Create a new Volume Group with the name TCPDumpVolGRP using /dev/sdb1, /dev/sdc1 and /dev/sdd1 with a physical extent size of 32 MB

    [root@Linux01 ~]# vgcreate TCPDumpVolGRP /dev/sdb1 /dev/sdc1 /dev/sdd1 -s 32M
    Volume group "TCPDumpVolGRP" successfully created
    [root@Linux01 ~]#
  3. Verfiy the Volume Group was created successfully

    [root@Linu01 ~]# vgdisplay
    --- Volume group ---
    VG Name TCPDumpVolGRP
    System ID
    Format lvm2
    Metadata Areas 3
    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 3
    Act PV 3
    VG Size 11.91 GB
    PE Size 32.00 MB
    Total PE 381
    Alloc PE / Size 0 / 0
    Free PE / Size 381 / 11.91 GB
    VG UUID 9fWFIS-vDlg-xOW6-Xmb8-Tkrg-GPZw-ZnUZwh

    --- Volume group ---
    VG Name VolGroup00
    System ID
    Format lvm2
    Metadata Areas 1
    Metadata Sequence No 6
    VG Access read/write
    VG Status resizable
    MAX LV 0
    Cur LV 5
    Open LV 5
    Max PV 0
    Cur PV 1
    Act PV 1
    VG Size 9.88 GB
    PE Size 32.00 MB
    Total PE 316
    Alloc PE / Size 316 / 9.88 GB
    Free PE / Size 0 / 0
    VG UUID zz6pnX-TR24-jPcE-zHrv-loz5-TPd2-eERHtq



Logical Volume Creation


Now that we have a Volume Group created that has free physical extents, we are now ready to create our new Logical Volume (LV).  LV's can be created using a number of extents (with the -l command line switch) or by total size (with the -L command line switch followed by KB, MB, GB or TB.)
In our first example, we will create a LV by specifying the number of extents.  Lets begin:
  1. Define a new LV with 100 extents

    [root@Linux01 ~]# lvcreate -l 100 -n TCPDumpLV TCPDumpVolGRP
    Logical volume "TCPDumpLV" created
    [root@Linux01 ~]#
  2. Verify the LV was created successfully

    [root@Linux01 ~]# lvdisplay
    --- Logical volume ---
    LV Name /dev/TCPDumpVolGRP/TCPDumpLV
    VG Name TCPDumpVolGRP
    LV UUID hYQs4t-YtY7-51hl-c4ps-4N6d-2W7h-IidcxF
    LV Write Access read/write
    LV Status available
    # open 0
    LV Size 3.12 GB
    Current LE 100
    Segments 1
    Allocation inherit
    Read ahead sectors auto
    - currently set to 256
    Block device 253:5
    Note: As you can see, there are 100 logical extents in the TCPDumpLV.  Since we know the extent size is 32MB, the total size of the LV is 3.12 GB (100 x 32 = 3200MB / 1024MB = 3.12 GB)
We will now create another LV, but this time specifying the total size of the LV.  Lets begin:
  1. Define a new LV that is 4GB in size

    [root@Linux01 ~]# lvcreate -L 4GB -n 4GLV TCPDumpVolGRP
    Logical volume "4GLV" created
    [root@Linux01 ~]#
  2. Verify the LV was created successfully

    [root@Linux01 ~]# lvdisplay
    --- Logical volume ---
    LV Name /dev/TCPDumpVolGRP/4GLV
    VG Name TCPDumpVolGRP
    LV UUID 2y9Ro0-N0xD-9Ys5-Nb5y-svc8-QgNE-tFr8mH
    LV Write Access read/write
    LV Status available
    # open 0
    LV Size 4.00 GB
    Current LE 128
    Segments 2
    Allocation inherit
    Read ahead sectors auto
    - currently set to 256
    Block device 253:6
    Note: Since we know the extent size is 32 MB and the LV size to be 4 GB, we can calculate the number of extents with (4000GB / 32MB = 125 extents)


Lets take one last look at our TCPDumpVolGRP Volume Group before we move on.  You'll notice in the following output that our physical extents allocation has increased and the number of free extents has decreased.  These numbers will correlate with the LV's that we created above: 128 extents + 100 extents = 228 total extents in use
[root@Linux01 ~]# vgdisplay
--- Volume group ---
VG Name TCPDumpVolGRP
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 0
Max PV 0
Cur PV 3
Act PV 3
VG Size 11.91 GB
PE Size 32.00 MB
Total PE 381
Alloc PE / Size 228 / 7.12 GB
Free PE / Size 153 / 4.78 GB
VG UUID 9fWFIS-vDlg-xOW6-Xmb8-Tkrg-GPZw-ZnUZwh


Formatting a File System


We are now ready to format the file system.  Linux offers many different file systems, some distributions of Linux/Unix will tend to recommend EXT3 while others might recommend XFS or ReiserFS.  There is really no wrong or right answer here, different file systems will have features and advantages/disadvantages.  The concept to understand here is that you must format the logical volume.
We are going to format our new LV's of type EXT3 with journaling enabled
  1. Format LV TCPDumpLV

    [root@Linux01 ~]# mke2fs -j /dev/TCPDumpVolGRP/TCPDumpLV
    mke2fs 1.39 (29-May-2006)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    409600 inodes, 819200 blocks
    40960 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=838860800
    25 block groups
    32768 blocks per group, 32768 fragments per group
    16384 inodes per group
    Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912

    Writing inode tables: done                           
    Creating journal (16384 blocks): done
    Writing superblocks and filesystem accounting information: done

    This filesystem will be automatically checked every 22 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    [root@Linux01 ~]#
  2. Format LV 4GLV

    [root@Linux01 ~]# mke2fs -j /dev/TCPDumpVolGRP/4GLV
    mke2fs 1.39 (29-May-2006)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    524288 inodes, 1048576 blocks
    52428 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=1073741824
    32 block groups
    32768 blocks per group, 32768 fragments per group
    16384 inodes per group
    Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736

    Writing inode tables: done                           
    Creating journal (32768 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@Linux01 ~]#


Mounting a File System


We are now ready to mount our new logical volumes.  This is no different than with any other Linux/Unix file system.
  1. Mount LV 4GLV on the mount point of /4GLV

    [root@Linux01 ~]# mkdir /4GLV
    [root@Linux01 ~]# mount /dev/TCPDumpVolGRP/4GLV /4GLV
  2. Mount LV TCPDumpLV on the mount point of /TCPDumpLV

    [root@Linux01 ~]# mkdir /TCPDumpLV
    [root@Linux01 ~]# mount /dev/TCPDumpVolGRP/TCPDumpLV /TCPDumpLV
  3. Verify the mounts points using df

    [root@Linux01 ~]# df -kh
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/VolGroup00-LogVol04 3.9G 2.2G 1.6G 59% /
    /dev/sda1 99M 12M 82M 13% /boot
    tmpfs 1006M 0 1006M 0% /dev/shm
    /dev/mapper/VolGroup00-LogVol00 992M 41M 901M 5% /home
    /dev/mapper/VolGroup00-LogVol02 992M 69M 872M 8% /tmp
    /dev/mapper/VolGroup00-LogVol03 2.0G 150M 1.7G 8% /var
    /dev/mapper/TCPDumpVolGRP-4GLV 4.0G 137M 3.7G 4% /4GLV
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV 3.1G 69M 2.9G 3% /TCPDumpLV

Updating fstab


Nice work, you are now ready to use your new LV.  However, before we finish up, we need to add the new LV to our fstab so that it will auto mount on reboot.
  1. Using your favorite editor, add the following to your /etc/fstab file

    /dev/mapper/TCPDumpVolGRP-4GLV /4GLV ext3 defaults 0 0
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV /TCPDumpLV ext3 defaults 0 0
  2. Verfy you syntax allowing mount to read from the fstab file

    [root@Linux01 ~]# umount /4GLV
    [root@Linux01 ~]# umount /TCPDumpLV
    [root@Linux01 ~]# mount -a
    [root@Linux01 ~]# df -kh
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/VolGroup00-LogVol04 3.9G 2.2G 1.6G 59% /
    /dev/sda1 99M 12M 82M 13% /boot
    tmpfs 1006M 0 1006M 0% /dev/shm
    /dev/mapper/VolGroup00-LogVol00 992M 41M 901M 5% /home
    /dev/mapper/VolGroup00-LogVol02 992M 69M 872M 8% /tmp
    /dev/mapper/VolGroup00-LogVol03 2.0G 150M 1.7G 8% /var
    /dev/mapper/TCPDumpVolGRP-4GLV 4.0G 137M 3.7G 4% /4GLV
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV 3.1G 69M 2.9G 3% /TCPDumpLV
Nice work!  You should now be well on your way to logical volume managemet.  Good luck!





LVM Mirroring Overview


Continuing with our LVM how to series, in this KB, we will build on the knowledge from our LVM Configuration KB, and explore two sided logical volume (LV) mirroring.  In this KB, we will guide you through the creation of a two sided mirror from a new LV and the steps necessary to add mirroring to an existing LV.
Note: Mirroring is usually thought of as two way (in which two physical copies of the volume exist.)  However, when creating LVM mirrors, you can define as many mirrors of a LV as you wish limited only by the number of physical volumes (PVs) available in the Volume Group (VG).  Each side of the mirror requires one or more PVs.
LVM mirroring is most commonly used for data protection and high availability of mission critical data.  Similar to RAID 1, LVM mirroring ensures fault tolerance without any associated downtime should either leg of the mirror experience a hardware failure.  In the event of a failure, LVM converts the mirrored volume into a linear volume and continues to operate as before, but without the mirrored redundancy.
LVM mirroring at a minimum requires three physical volumes:
  1. A volume for one side of the mirror
  2. A volume for other side of the mirror
  3. A volume for the log
Note: We recommend for recoverability purposes that the PV's be three separate physical disks.  Although not recommended, the PV's could also be a combination of partitions from one more physical disks but understand that a hardware failure could render the data on the LVM mirror useless - which somewhat defeats the purpose of LVM mirroring.



Creating New Mirror Volumes


For our first example, we will show you how to create a new mirrored logical volume (LV) from free space on our volume group (VG).  We are going to create a new 3GB mirrored LV called DumpMirror on the volume group TCPDumpVolGRP Let's begin:
  1. Let's first check our TCPDumpVolGRP volume group to see if it has enough free space to support a 3GB mirrored LV

    [root@Linux01 ~]# vgs
    VG #PV #LV #SN Attr VSize VFree
    TCPDumpVolGRP 3 1 0 wz--n- 11.91G 9.91G
    VolGroup00 1 5 0 wz--n- 9.88G 0
    [root@Linux01 ~]#
    Note: Since our 3GB mirrored LV will require ~6GB (3GB x 2 legs = 6GB + Log Volume), the 9.91GB free should suffice.
  2. Let's also check to ensure the TCPDumpVolGRP volume group has enough free physical volumes (PV) available

    [root@Linux01 ~]# pvs
    PV VG Fmt Attr PSize PFree
    /dev/sda2
    VolGroup00 lvm2 a- 9.88G 0
    /dev/sdb1 TCPDumpVolGRP lvm2 a- 3.97G 3.97G
    /dev/sdc1 TCPDumpVolGRP lvm2 a- 3.97G 1.97G
    /dev/sdd1 TCPDumpVolGRP lvm2 a- 3.97G 3.97G
    [root@Linux01 ~]#
    Note: Two sided mirrors require three physical volumes which we appear to have with free space available on them
  3. We will now create the mirrored LV.  Creating a mirrored LV is much the same as the creation of a non-mirrored LV with the exception of the '-m 1' command line switch.  The '-m 1' tells LVM you wish to create a two sided mirror

    [root@Linux01 ~]# lvcreate -L 3G -n DumpMirror -m 1 TCPDumpVolGRP
    Logical volume "DumpMirror" created
    [root@Linux01 ~]#

  4. Creating the mirrored LV can take sometime.  Monitor the sync process until it reaches 100%

    [root@Linux01 ~]# lvs
    LV VG Attr LSize Origin Snap% Move Log Copy% Convert
    4GLV TCPDumpVolGRP -wi-ao 2.00G





    DumpMirror TCPDumpVolGRP mwi-ao 3.00G


    DumpMirror_mlog 5.21
    LogVol00 VolGroup00 -wi-ao 1.00G





    LogVol01 VolGroup00 -wi-ao 1.94G





    LogVol02 VolGroup00 -wi-ao 1.00G





    LogVol03 VolGroup00 -wi-ao 2.00G





    LogVol04 VolGroup00 -wi-ao 3.94G





    [root@Linux01 ~]#
    Note: The sync process is only ~5% complete, this could take a while
    [root@Linux01 ~]# lvs
    LV VG Attr LSize Origin Snap% Move Log Copy% Convert
    4GLV TCPDumpVolGRP -wi-ao 2.00G





    DumpMirror TCPDumpVolGRP mwi-ao 3.00G


    DumpMirror_mlog 100.00
    LogVol00 VolGroup00 -wi-ao 1.00G





    LogVol01 VolGroup00 -wi-ao 1.94G





    LogVol02 VolGroup00 -wi-ao 1.00G





    LogVol03 VolGroup00 -wi-ao 2.00G





    LogVol04 VolGroup00 -wi-ao 3.94G





    [root@Linux01 ~]#
    Note: The LV is now synced and ready for use

  5. Inspect the LV to confirm the devices that are in use by the mirror
    [root@Linux01 ~]# lvs -a -o +devices
    LV VG Attr LSize Log Copy% Devices
    4GLV TCPDumpVolGRP -wi-ao 2.00G

    /dev/sdc1(0)
    DumpMirror TCPDumpVolGRP mwi-a- 3.00G DumpMirror_mlog 100.00 DumpMirror_mimage_0(0),
    DumpMirror_mimage_1(0)
    [DumpMirror_mimage_0] TCPDumpVolGRP iwi-ao 3.00G

    /dev/sdb1(0)
    [DumpMirror_mimage_1] TCPDumpVolGRP iwi-ao 3.00G

    /dev/sdd1(0)
    [DumpMirror_mlog] TCPDumpVolGRP lwi-ao 32.00M

    /dev/sdc1(64)
    LogVol00 VolGroup00 -wi-ao 1.00G

    /dev/sda2(126)
    LogVol01 VolGroup00 -wi-ao 1.94G

    /dev/sda2(254)
    LogVol02 VolGroup00 -wi-ao 1.00G

    /dev/sda2(158)
    LogVol03 VolGroup00 -wi-ao 2.00G

    /dev/sda2(190)
    LogVol04 VolGroup00 -wi-ao 3.94G

    /dev/sda2(0)
    [root@Linux01 ~]#
    Note: Some columns were removed from the above output.  You will notice DumpMirror uses /dev/sdb1 and /dev/sdd1.  You will also notice the logs for DumpMirror are held on /dev/sdc1
  6. Format DumpMirror

    [root@Linux01 ~]# mke2fs -j /dev/TCPDumpVolGRP/DumpMirrormke2fs 1.39 (29-May-2006)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    393216 inodes, 786432 blocks
    39321 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=805306368
    24 block groups
    32768 blocks per group, 32768 fragments per group
    16384 inodes per group
    Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912

    Writing inode tables: done                           
    Creating journal (16384 blocks): done
    Writing superblocks and filesystem accounting information: done

    This filesystem will be automatically checked every 21 mounts or
    180 days, whichever comes first.  Use tune2fs -c or -i to override.
    [root@Linux01 ~]#
  7. Mount DumpMirror on the mount point of /mirror

    [root@Linux01 ~]# mkdir /mirror
    [root@Linux01 ~]# mount /dev/TCPDumpVolGRP/DumpMirror /mirror
  8. Add DumpMirror to the /etc/fstab file

    /dev/TCPDumpVolGRP/DumpMirror /mirror ext3 defaults 0 0
Nice work.  You know have a fault tolerant logical volume! We are now going to continue with the KB and show you how to add mirroring to an existing logical volume.



Mirror From Existing Volume


We are now going to look at how to create a mirror from an existing logical volume (LV.)  For this portion of the KB, we will assume you have an LV in use on your system and would like it mirrored.
Note: If you do not have any LV's on your system and need help creating your first LV, see our LVM Configuration KB.
In the following example, we will convert the logical volume DataLV from a linear to mirrored LV.  Lets begin!
  1. Review the output of pvs, vgs and lvs so we know the layout of DataLV and confirm the requirements for the mirror

    [root@Linux01 ~]# lvs -a -o +devices
    LV VG Attr LSize Origin Snap% Move Log Copy% Convert Devices
    DataLV TCPDumpVolGRP -wi-ao 2.5G





    /dev/sdb1(0)
    LogVol00 VolGroup00 -wi-ao 1.00G





    /dev/sda2(126)
    LogVol01 VolGroup00 -wi-ao 1.94G





    /dev/sda2(254)
    LogVol02 VolGroup00 -wi-ao 1.00G





    /dev/sda2(158)
    LogVol03 VolGroup00 -wi-ao 2.00G





    /dev/sda2(190)
    LogVol04 VolGroup00 -wi-ao 3.94G





    /dev/sda2(0)
    [root@Linux01 ~]#
    Note: You will notice that DataLV is 2.5GB in size and resides on /dev/sdb1.

    [root@Linux01 ~]# pvs
    PV VG Fmt Attr PSize PFree
    /dev/sda2
    VolGroup00 lvm2 a- 9.88G 0
    /dev/sdb1 TCPDumpVolGRP lvm2 a- 3.97G 1.47G
    /dev/sdc1 TCPDumpVolGRP lvm2 a- 3.97G 3.97G
    /dev/sdd1 TCPDumpVolGRP lvm2 a- 3.97G 3.97G
    [root@Linux01 ~]#
    Note: pvs confirms our assumptions showing that some of sdb1 is consumed by DataLV.  We are also able to confirm we have the three required PV's necessary for the mirror.

    [root@Linux01 ~]# vgs
    VG #PV #LV #SN Attr VSize VFree
    TCPDumpVolGRP 3 1 0 wz--n- 11.91G 9.41G
    VolGroup00 1 5 0 wz--n- 9.88G 0
    [root@Linux01 ~]#
    Note: A free space check on our volume group shows we have enough free space for the 2.5GB mirror required for DataLV
  2. Convert the logical volume to a mirror

    [root@Linux01 Data]# lvconvert -m1 TCPDumpVolGRP/DataLV
    TCPDumpVolGRP/DataLV: Converted: 12.5%
    TCPDumpVolGRP/DataLV: Converted: 26.2%
    TCPDumpVolGRP/DataLV: Converted: 40.0%
    TCPDumpVolGRP/DataLV: Converted: 53.8%
    TCPDumpVolGRP/DataLV: Converted: 68.8%
    TCPDumpVolGRP/DataLV: Converted: 82.5%
    TCPDumpVolGRP/DataLV: Converted: 96.2%
    TCPDumpVolGRP/DataLV: Converted: 100.0%
    Logical volume DataLV converted.
    [root@Linux01 Data]#
    Note: The lvconvert command can take a considerable amount of time depending on how big a mirror is to be created.  Go grab a beer or read some more articles on TCPDump while you wait, but do not break out of the process.
  3. Confirm the mirror has been created
    [root@Linux01 ~]# lvs -a -o +devices
    LV VG Attr LSize Log Copy% Devices
    DataLV TCPDumpVolGRP mwi-a- 2.50G DataLV_mlog 100.00 DataLV_mimage_0(0),
    DataLV_mimage_1(0)
    [DataLV_mimage_0] TCPDumpVolGRP iwi-ao 2.50G

    /dev/sdb1(0)
    [DataLV_mimage_1] TCPDumpVolGRP iwi-ao 2.50G

    /dev/sdc1(0)
    [DataLV_mlog] TCPDumpVolGRP lwi-ao 32.00M

    /dev/sdd1(0)
    LogVol00 VolGroup00 -wi-ao 1.00G

    /dev/sda2(126)
    LogVol01 VolGroup00 -wi-ao 1.94G

    /dev/sda2(254)
    LogVol02 VolGroup00 -wi-ao 1.00G

    /dev/sda2(158)
    LogVol03 VolGroup00 -wi-ao 2.00G

    /dev/sda2(190)
    LogVol04 VolGroup00 -wi-ao 3.94G

    /dev/sda2(0)
    [root@Linux01 ~]#
    Note: Some columns were removed from the above output.  You will notice DataLV uses /dev/sdb1 and /dev/sdc1.  You will also notice the mirror logs for DumpMirror are held on /dev/sdd1
Note: For additional details on the Attr column (LVM display attributes) of the lvs, vgs, and pvs commands, please see our LVM Attributes KB.
Nice work, your logical volume is now fault tolerant!


Logical Volume Removal


In this KB, we will show you how to remove a logical volume.  We will assume you already have a logical volume (LV) created on your system.  If you do not already have a LV, and you need help creating your first LV, please see our LVM Configuration KB for details.
Removing a logical volume is a three step process:
  1. Unmount the LV
  2. Remove the LV
  3. Update /etc/fstab
Note: Make sure you unmount the file system before removing the LV.  Forcing the removal of a LV before it is unmounted could have unknown consequences on your system.
In the following example, we will remove the logical volume TCPDumpLV.  Lets get started!
  1. Begin by listing all the logical volumes on the system

    [root@Linux01 ~]# lvs
    LV VG Attr LSize Origin Snap% Move Log Copy% Convert
    TCPDumpLV TCPDumpVolGRP -wi-ao 2.00G





    LogVol00 VolGroup00 -wi-ao 1.00G





    LogVol01 VolGroup00 -wi-ao 1.94G





    LogVol02 VolGroup00 -wi-ao 1.00G





    LogVol03 VolGroup00 -wi-ao 2.00G





    LogVol04 VolGroup00 -wi-ao 3.94G





    [root@Linux01 ~]#

  2. Let's find out where TCPDumpLV is mounted

    [root@Linux01 ~]# df -kh
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/VolGroup00-LogVol04 3.9G 2.2G 1.6G 59% /
    /dev/sda1 99M 12M 82M 13% /boot
    tmpfs 1006M 0 1006M 0% /dev/shm
    /dev/mapper/VolGroup00-LogVol00 992M 41M 901M 5% /home
    /dev/mapper/VolGroup00-LogVol02 992M 69M 872M 8% /tmp
    /dev/mapper/VolGroup00-LogVol03 2.0G 150M 1.7G 8% /var
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV 2.0G 568M 1.4G 30% /Data
    Note: TCPDumpLV is mounted on /Data

  3. Unmount TCDDumpLV

    [root@Linux01 /]# umount /Data
    [root@Linux01 /]#
  4. Remove the logical volume

    [root@Linux01 /]# lvremove /dev/TCPDumpVolGRP/TCPDumpLV
    Do you really want to remove active logical volume "TCPDumpLV"? [y/n]: y
    Logical volume "TCPDumpLV" successfully removed
    [root@Linux01 /]#
  5. Verify the logical volume has been removed

    [root@Linux01 ~]# lvs
    LV VG Attr LSize Origin Snap% Move Log Copy% Convert
    LogVol00 VolGroup00 -wi-ao 1.00G





    LogVol01 VolGroup00 -wi-ao 1.94G





    LogVol02 VolGroup00 -wi-ao 1.00G





    LogVol03 VolGroup00 -wi-ao 2.00G





    LogVol04 VolGroup00 -wi-ao 3.94G





    [root@Linux01 ~]#
  6. Update /etc/fstab to reflect the removal of the file system

    /dev/mapper/TCPDumpVolGRP-TCPDumpLV /Data ext3 defaults 0 0

Nice work, you now know how to remove a logical volume!


Logical Volume Renaming


In this KB, we will show you how to rename a logical volume.  We will assume you already have a logical volume (LV) created on your system.  If you do not already have a LV, and you need help creating your first LV, please see our LVM Configuration KB for details.
Renaming a logical volume is a three step process:
  1. Rename the LV
  2. Remount the file system
  3. Update /etc/fstab
Remounting the file system is necessary in order for the user space to see the name change.
Note: The output of the df command will not display the new name of the file system until it has been remounted.
In the following example, we will rename the logical volume DataLV to TCPDumpLV.  Lets get started!
  1. Begin by listing all the logical volumes on the system

    [root@Linux01 ~]# lvs
    LV VG Attr LSize Origin Snap% Move Log Copy% Convert
    DataLV TCPDumpVolGRP -wi-ao 2.00G





    LogVol00 VolGroup00 -wi-ao 1.00G





    LogVol01 VolGroup00 -wi-ao 1.94G





    LogVol02 VolGroup00 -wi-ao 1.00G





    LogVol03 VolGroup00 -wi-ao 2.00G





    LogVol04 VolGroup00 -wi-ao 3.94G





    [root@Linux01 ~]#

  2. Let's find out where DataLV is mounted

    [root@Linux01 ~]# df -kh
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/VolGroup00-LogVol04 3.9G 2.2G 1.6G 59% /
    /dev/sda1 99M 12M 82M 13% /boot
    tmpfs 1006M 0 1006M 0% /dev/shm
    /dev/mapper/VolGroup00-LogVol00 992M 41M 901M 5% /home
    /dev/mapper/VolGroup00-LogVol02 992M 69M 872M 8% /tmp
    /dev/mapper/VolGroup00-LogVol03 2.0G 150M 1.7G 8% /var
    /dev/mapper/TCPDumpVolGRP-DataLV 2.0G 568M 1.4G 30% /Data
    Note: The DataLV is mounted on /Data

  3. Rename DataLV to TCPDumpLV

    [root@Linux01 /]# lvrename TCPDumpVolGRP DataLV TCPDumpLV
    Renamed "DataLV" to "TCPDumpLV" in volume group "TCPDumpVolGRP"
    [root@Linux01 /]#
  4. Verify the logical volume has been renamed

    [root@Linux01 ~]# lvs
    LV VG Attr LSize Origin Snap% Move Log Copy% Convert
    TCPDumpLV TCPDumpVolGRP -wi-ao 2.00G





    LogVol00 VolGroup00 -wi-ao 1.00G





    LogVol01 VolGroup00 -wi-ao 1.94G





    LogVol02 VolGroup00 -wi-ao 1.00G





    LogVol03 VolGroup00 -wi-ao 2.00G





    LogVol04 VolGroup00 -wi-ao 3.94G





    [root@Linux01 ~]#
  5. Notice the user space has yet to be updated, this is because the file system must be remounted

    [root@Linux01 ~]# df -kh
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/VolGroup00-LogVol04 3.9G 2.2G 1.6G 59% /
    /dev/sda1 99M 12M 82M 13% /boot
    tmpfs 1006M 0 1006M 0% /dev/shm
    /dev/mapper/VolGroup00-LogVol00 992M 41M 901M 5% /home
    /dev/mapper/VolGroup00-LogVol02 992M 69M 872M 8% /tmp
    /dev/mapper/VolGroup00-LogVol03 2.0G 150M 1.7G 8% /var
    /dev/mapper/TCPDumpVolGRP-DataLV 2.0G 568M 1.4G 30% /Data

  6. Remount the file system to update the user space

    [root@Linux01 /]# umount /dev/mapper/TCPDumpVolGRP-DataLV
    [root@Linux01 /]# mount /dev/TCPDumpVolGRP/TCPDumpLV /Data/
    [root@Linux01 /]#
  7. Verify the file system has been mounted

    [root@Linux01 ~]# df -kh
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/VolGroup00-LogVol04 3.9G 2.2G 1.6G 59% /
    /dev/sda1 99M 12M 82M 13% /boot
    tmpfs 1006M 0 1006M 0% /dev/shm
    /dev/mapper/VolGroup00-LogVol00 992M 41M 901M 5% /home
    /dev/mapper/VolGroup00-LogVol02 992M 69M 872M 8% /tmp
    /dev/mapper/VolGroup00-LogVol03 2.0G 150M 1.7G 8% /var
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV 2.0G 568M 1.4G 30% /Data
  8. Update /etc/fstab to reflect the new name of the file system

    /dev/mapper/TCPDumpVolGRP-DataLV /Data ext3 defaults 0 0
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV /Data ext3 defaults 0 0

Nice work, you now know how to rename a logical volume!

===

LVM Resizing Overview


In our LVM Configuration KB, we showed how to create a linear mapped logical volume (LV).  In this KB, we are going to build on our LVM knowledge and show you how to resize an existing ext3 file system and it's associate LV.
Note: Procedures for resizing XFS, ResierFS and other volumes may differ.  You should check your documentation for non ext3 volumes before proceeding.  Resizing a file system can also be destructive if not done properly.  You should always make sure you have a backup of your data before attempting a resize!
Logical Volumes can be increased or decreased in size depending on your needs.  However, resizing the LV does not eliminate the need to resize the file system contained within the LV.  This is an important concept to understand since resizing the LV without resizing the file system can cause corruption of your data.
In the following pages, we will guide you through expanding and contracing LV's and their associated file systems.  Let's get to it!



Grow File System


Increasing the size of a file system managed with LVM can be done online (with the file system mounted.)  In order to grow the LV and file system:
  • Check to see if free space exists on the LV that contains the file system
  • Expand the LV if it does not contain enough free space (which could require expanding the volume group if it is out of free space)
  • Grow the file system to utilize all available space on the LV
Lets get started!
  1. First, check the size of the file system to see if it needs expanding

    [root@Linux01 ~]# pwd
    /TCPDumpLV
    [root@Linux01 TCPDumpLV]# df -kh .
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV 3.1G 2.9G 69M 98% /TCPDumpLV
    Note: The disk free command shows that we have 65MB available on our file system and that its 98% use.  If we don't take action soon, we risk filling the file system.
  2. Let's find out which Volume Group contains the Logical Volume that holds /dev/mapper/TCPDumpVolGRP-TCPDumpLV

    [root@Linux01 ~]# lvdisplay /dev/TCPDumpVolGRP/TCPDumpLV
    --- Logical volume ---
    LV Name /dev/TCPDumpVolGRP/TCPDumpLV
    VG Name TCPDumpVolGRP
    LV UUID hYQs4t-YtY7-51hl-c4ps-4N6d-2W7h-IidcxF
    LV Write Access read/write
    LV Status available
    # open 1
    LV Size 3.12 GB
    Current LE 100
    Segments 1
    Allocation inherit
    Read ahead sectors auto
    - currently set to 256
    Block device 253:5
    Note: You can see the volume group for this file system is TCPDumpVolGRP
  3. Let's find out if the volume group TCPDumpVolGRP has available free space to allocate to the logical volume

    [root@Linux01 ~]# vgdisplay TCPDumpVolGRP
    --- Volume group ---
    VG Name TCPDumpVolGRP
    System ID
    Format lvm2
    Metadata Areas 3
    Metadata Sequence No 5
    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 11.91 GB
    PE Size 32.00 MB
    Total PE 381
    Alloc PE / Size 228 / 7.12 GB
    Free PE / Size 153 / 4.78 GB
    VG UUID 9fWFIS-vDlg-xOW6-Xmb8-Tkrg-GPZw-ZnUZwh
    Note: This volume group has plenty of free space.  If we were out of physical extents, we would have to add additional physical volumes to this volume group before continuing on.
  4. We will now resize the logical volume TCPDumpLV by adding 3GB

    [root@Linux01 TCPDumpLV]# lvresize -L +3GB /dev/TCPDumpVolGRP/TCPDumpLV
    Extending logical volume TCPDumpLV to 6.12 GB
    Logical volume TCPDumpLV successfully resized
    [root@Linux01 TCPDumpLV]#
  5. Confirm the new size of the logical volume

    [root@Linux01 ~]# lvdisplay /dev/TCPDumpVolGRP/TCPDumpLV
    --- Logical volume ---
    LV Name /dev/TCPDumpVolGRP/TCPDumpLV
    VG Name TCPDumpVolGRP
    LV UUID hYQs4t-YtY7-51hl-c4ps-4N6d-2W7h-IidcxF
    LV Write Access read/write
    LV Status available
    # open 1
    LV Size 6.12 GB
    Current LE 196
    Segments 2
    Allocation inherit
    Read ahead sectors auto
    - currently set to 256
    Block device 253:5

    [root@Linux01 ~]# pwd
    /TCPDumpLV
    [root@Linux01 TCPDumpLV]# df -kh .
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV 3.1G 2.9G 69M 98% /TCPDumpLV
    Note: You will notice that although we have increased the size of the logical volume, the size of the file system has been unaffected.
  6. We now need to resize the ext3 file system to utilize the remaining available space within the logical volume

    [root@Linux01 TCPDumpLV]# resize2fs -p /dev/mapper/TCPDumpVolGRP-TCPDumpLV
    resize2fs 1.39 (29-May-2006)
    Filesystem at /dev/mapper/TCPDumpVolGRP-TCPDumpLV is mounted on /TCPDumpLV; on-line resizing required
    Performing an on-line resize of /dev/mapper/TCPDumpVolGRP-TCPDumpLV to 1605632 (4k) blocks.
    The filesystem on /dev/mapper/TCPDumpVolGRP-TCPDumpLV is now 1605632 blocks long.

    [root@Linux01 TCPDumpLV]# df -kh .
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV 6.1G 2.9G 2.9G 50% /TCPDumpLV
Nice work, you just resized your file system while it was online!  Now lets take a look at reducing the size of a file system.


Shrink File System


Decreasing the size of a file system managed with LVM must be done off-line (unmounted.)  To shrink the file system and LV:
  • Unmount the file system
  • Run a file system check to ensure the integrity of the volume
  • Shrink the file system
  • Shrink the logical volume
Note: You cannot shrink the file system beyond the amount of free space that is available on it.  So if the file system you want to shrink has 1GB of free space, you will only be able to shrink the volume by 1GB.  However, logical volumes are not as forgiving.  If you are not careful, you can shrink the LV to a size less than what is required by the file system.  If the LV is resized smaller than what the file system has been resized to, things will go very badly for you.  Did we mention you should backup your data before hand?
Let's get started!
  1. First, check to see how much space is available

    [root@Linux01 ~]# pwd
    /TCPDumpLV
    [root@Linux01 TCPDumpLV]# df -kh .
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV 6.1G 922M 4.9G 16% /TCPDumpLV
    Note: The disk free command shows that we are using 922MB and have 4.9G available on our file system.  Therefore, we can safely shrink the volume to 1.5G (leaving a little bit for overhead) without any issue.
  2. Unmount the file system

    [root@Linux01 TCPDumpLV]# cd /
    [root@Linux01 /]# umount /TCPDumpLV
  3. Check the file system for errors

    [root@Linux01 /]# e2fsck -f /dev/mapper/TCPDumpVolGRP-TCPDumpLV
    e2fsck 1.39 (29-May-2006)
    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/mapper/TCPDumpVolGRP-TCPDumpLV: 13/802816 files (7.7% non-contiguous), 261017/1605632 blocks
    [root@Linux01 /]#

  4. Shrink the file system to 1.5GB

    [root@Linux01 /]# resize2fs /dev/mapper/TCPDumpVolGRP-TCPDumpLV 1500M
    resize2fs 1.39 (29-May-2006)
    Resizing the filesystem on /dev/mapper/TCPDumpVolGRP-TCPDumpLV to 384000 (4k) blocks.
    The filesystem on /dev/mapper/TCPDumpVolGRP-TCPDumpLV is now 384000 blocks long.

    [root@Linux01 /]#
  5. Shrink the logical file system to 1.5GB

    [root@Linux01 /]# lvresize -L 1.5G /dev/TCPDumpVolGRP/TCPDumpLV
    WARNING: Reducing active logical volume to 1.50 GB
    THIS MAY DESTROY YOUR DATA (filesystem etc.)
    Do you really want to reduce TCPDumpLV? [y/n]: y
    Reducing logical volume TCPDumpLV to 1.50 GB
    Logical volume TCPDumpLV successfully resized
    [root@Linux01 /]#
    Note: Special precaution should be taken with this step.  It's possible to reduce the logical volume size by more than the size of the file system.  If you do reduce the LV size by more than what you resized the file system to (from step #4), this will almost certainly end very badly for you.  Ensure the LV is large enough for the file system and that you make a backup before hand!
  6. Verify the new size of the logical volume

    [root@Linux01 ~]# lvdisplay /dev/TCPDumpVolGRP/TCPDumpLV
    --- Logical volume ---
    LV Name /dev/TCPDumpVolGRP/TCPDumpLV
    VG Name TCPDumpVolGRP
    LV UUID hYQs4t-YtY7-51hl-c4ps-4N6d-2W7h-IidcxF
    LV Write Access read/write
    LV Status available
    # open 0
    LV Size 1.50 GB
    Current LE 48
    Segments 1
    Allocation inherit
    Read ahead sectors auto
    - currently set to 256
    Block device 253:5
  7. Remount the file system and verify the new size

    [root@Linux01 /]# mount /dev/TCPDumpVolGRP/TCPDumpLV
    [root@Linux01 /]# cd /TCPDumpLV/
    [root@Linux01 TCPDumpLV]# df -kh .
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV 1.5G 920M 497M 65% /TCPDumpLV

Nice work, you've just resized your LV and it's file systems!  Next up, LVM snapshots!




Snapshot Creation


Creating a logical volume (LV) snapshot is much the same process as creating a LV (see our LVM Configuration KB for details on how to create a LV.)  However, when creating a LV snapshot you must use a -s command line switch in conjunction with the LV you wish to snapshot.  The syntax is as follows:
  • lvcreate -L <SIZE_OF_SNAPSHOT> -s -n <NAME_OF_SNAPSHOT> <LV_TO_SNAPSHOT>
In the following example, we will create a 500MB snapshot LV of an existing LV, lets being:
  1. Use lvdisplay to find the name of the logical volume you wish to snapshot

    [root@Linux01 ~]# lvdisplay
    --- Logical volume ---
    LV Name /dev/TCPDumpVolGRP/TCPDumpLV
    VG Name TCPDumpVolGRP
    LV UUID hYQs4t-YtY7-51hl-c4ps-4N6d-2W7h-IidcxF
    LV Write Access read/write
    LV Status available
    # open 1
    LV Size 1.50 GB
    Current LE 48
    Segments 1
    Allocation inherit
    Read ahead sectors auto
    - currently set to 256
    Block device 253:5

    ... OUTPUT TRUNCATED
  2. Create a new 500MB snapshot from the source LV /dev/TCPDumpVolGRP/TCPDumpLV

    [root@Linux01 /]# lvcreate -L 500M -s -n BackupLV /dev/TCPDumpVolGRP/TCPDumpLV
    Rounding up size to full physical extent 512.00 MB
    Logical volume "BackupLV" created
    [root@Linux01 ~]#
    Note: Our snapshot LV (500MB) is about 1/3 the size of the source LV (1.5 GB).  As we have already said, the snapshot LV does not need to be the same size of the source.  Because the snapshot LV will only contain the changes made to the source LV while its snapshot, and we know there is not a high rate of change on the source LV, we are fine using 1/3 the size (and would have probably been safe making it far less.)
  3. Verify the snapshot has been created

    [root@Linux01 ~]# lvdisplay
    --- Logical volume ---
    LV Name /dev/TCPDumpVolGRP/TCPDumpLV
    VG Name TCPDumpVolGRP
    LV UUID hYQs4t-YtY7-51hl-c4ps-4N6d-2W7h-IidcxF
    LV Write Access read/write
    LV Status available
    # open 1
    LV Size 1.50 GB
    Current LE 48
    Segments 1
    Allocation inherit
    Read ahead sectors auto
    - currently set to 256
    Block device 253:5

    --- Logical volume ---
    LV Name /dev/TCPDumpVolGRP/BackupLV
    VG Name TCPDumpVolGRP
    LV UUID mSWMF0-5JtO-GkAd-plBb-YIf8-1HOg-JRfV34
    LV Write Access read/write
    LV snapshot status active destination for /dev/TCPDumpVolGRP/TCPDumpLV
    LV Status available
    # open 0
    LV Size 1.50 GB
    Current LE 48
    COW-table size 512.00 MB
    COW-table LE 16
    Allocated to snapshot 0.00%
    Snapshot chunk size 4.00 KB
    Segments 1
    Allocation inherit
    Read ahead sectors auto
    - currently set to 256
    Block device 253:7

    ... OUTPUT TRUNCATED
    Note: You will notice on the BackupLV that although the LV size says that it's 1.5GB, the copy-on-write (COW) table informs us that it's actually only 512MB (the source LV is 1.5GB.)  Also, the percentage allocated to the snapshot is currently at 0%.  As updates are made to the source LV, you'll notice this percentage will increase.
  4. We can now mount the snapshot so that it may be backed-up

    [root@Linux01 /]# mkdir -p /mnt/backup
    [root@Linux01 /]# mount /dev/TCPDumpVolGRP/BackupLV /mnt/backup/
    [root@Linux01 /]# df -kh
    Filesystem Size Used Avail Use% Mounted on
    /dev/mapper/VolGroup00-LogVol04 3.9G 2.2G 1.6G 59% /
    /dev/sda1 99M 12M 82M 13% /boot
    tmpfs 1006M 0 1006M 0% /dev/shm
    /dev/mapper/VolGroup00-LogVol00 992M 41M 901M 5% /home
    /dev/mapper/VolGroup00-LogVol02 992M 69M 872M 8% /tmp
    /dev/mapper/VolGroup00-LogVol03 2.0G 150M 1.7G 8% /var
    /dev/mapper/TCPDumpVolGRP-4GLV 4.0G 137M 3.7G 4% /4GLV
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV 1.5G 920M 497M 65% /TCPDumpLV
    /dev/mapper/TCPDumpVolGRP-BackupLV 1.5G 920M 497M 65% /mnt/backup
  5. Once the snapshot has been backed-up, unmount the LV and remove it

    [root@Linux01 /]# umount /mnt/backup/
    [root@Linux01 /]# lvremove /dev/mapper/TCPDumpVolGRP-BackupLV
    Do you really want to remove active logical volume "BackupLV"? [y/n]: y
    Logical volume "BackupLV" successfully removed
    [root@Linux01 /]#
Nice work, you now know how-to snapshot a LV.  Good luck!

 ++++========+++++++========+++++==========+++++++


















































            

1 comment:

Unknown said...

This article is very much helpful and i hope this will be an useful information for the needed one. Keep on updating these kinds of informative things...

Android App Development Company
iOS App Development Company

Post a Comment