You are not logged in or registered. Please login or register to use the full functionality of this board...



Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to resize LVM partitions
01-14-2013, 10:28 AM (This post was last modified: 11-06-2013 08:58 PM by knifebunny.)
Post: #1
How to resize LVM partitions
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!
First, check the size of the file system to see if it needs expanding

Code:
[[email protected] ~]# pwd
/TCPDumpLV
[[email protected] 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.

Let's find out which Volume Group contains the Logical Volume that holds /dev/mapper/TCPDumpVolGRP-TCPDumpLV

Code:
[[email protected] ~]# 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

Let's find out if the volume group TCPDumpVolGRP has available free space to allocate to the logical volume

Code:
[[email protected] ~]# 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.

We will now resize the logical volume TCPDumpLV by adding 3GB

Code:
[[email protected] TCPDumpLV]# lvresize -L +3GB /dev/TCPDumpVolGRP/TCPDumpLV
Extending logical volume TCPDumpLV to 6.12 GB
Logical volume TCPDumpLV successfully resized
[[email protected] TCPDumpLV]#

Confirm the new size of the logical volume

Code:
[[email protected] ~]# 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

[[email protected] ~]# pwd
/TCPDumpLV
[[email protected] 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.

We now need to resize the ext3 file system to utilize the remaining available space within the logical volume

Code:
[[email protected] 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.

Code:
[[email protected] 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!

First, check to see how much space is available

Code:
[[email protected] ~]# pwd
/TCPDumpLV
[[email protected] 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.

Unmount the file system

Code:
[[email protected] TCPDumpLV]# cd /
[[email protected] /]# umount /TCPDumpLV
Check the file system for errors

Code:
[[email protected] /]# 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
[[email protected] /]#

Shrink the file system to 1.5GB

Code:
[[email protected] /]# 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.

[[email protected] /]#

Shrink the logical file system to 1.5GB

Code:
[[email protected] /]# 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
[[email protected] /]#

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!

Verify the new size of the logical volume

Code:
[[email protected] ~]# 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
Remount the file system and verify the new size

Code:
[[email protected] /]# mount /dev/TCPDumpVolGRP/TCPDumpLV
[[email protected] /]# cd /TCPDumpLV/
[[email protected] 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!
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)