Resizing ext3/4 on LVM: Difference between revisions
(Created page with " =Check and prepare for resize= First, check the size of the file system to see if it needs expanding [root@Linux01 ~]# pwd /TCPDumpLV [root@Linux01 TCPDumpLV]# df -kh . ...") |
No edit summary |
||
Line 126: | Line 126: | ||
[http://backdrift.org/online-ext3-grow-resize-with-lvm] | [http://backdrift.org/online-ext3-grow-resize-with-lvm] | ||
[http://tharindu.info/2011/05/22/grow-online-xfs-on-lvm] | [http://tharindu.info/2011/05/22/grow-online-xfs-on-lvm] | ||
=Shrinking ext2/3/4= | |||
Shrinking an ext3 volume is fairly straight forward, but it's important you don't mount your drive and start doing stuff, before you verify everything worked correctly. | |||
e2fsck -f /dev/vg/lv1 | |||
resize2fs -p /dev/vg/lv1 ###G | |||
e2fsck /dev/vg/lv1 | |||
lvresize -L ###G /dev/vg/lv1 | |||
e2fsck /dev/vg/lv1 | |||
Step #5 is the most important step; as steps 1-3 will not have any problems unless you have a system failure, a corrupted file system to start with, disk failure, or hardware failure. Step 5 however, could be due to sys-admin error, from shrinking the LVM volume too much. If you receive an error similar to the following, then you probably shrunk the volume too much, and your file system is not completely accessible. | |||
e2fsck 1.41.9 (22-Aug-2009) | |||
The filesystem size (according to the superblock) is 113634135 blocks | |||
The physical size of the device is 112197632 blocks | |||
Either the superblock or the partition table is likely to be corrupt! | |||
Abort<y>? cancelled! | |||
If the error is due to shrinking too far, then this is easy to recover from; simply do another lvresize, with a large size specified, and do another e2fsck afterward. | |||
Generally speaking, you should make the LVM maybe 2% or so larger than the file system was reduced to, so that there's room for file system overhead. | |||
[http://blog.adamsbros.org/2010/01/11/safe-shrinking-of-lvm-volumes/] | |||
[http://www.davidodwyer.com/content/howto-shrink-ext3-partition-lvm-free-available-extents] | |||
[http://www.microhowto.info/howto/reduce_the_size_of_an_ext2_ext3_or_ext4_filesystem.html] |
Revision as of 01:15, 9 February 2015
Check and prepare for resize
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.
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
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.
Resize the logical volume
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]#
Inspect 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. 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
Resizing filesystems
Resize ext3 filesystem
resize2fs /dev/mapper/TCPDumpVolGRP-TCPDumpLV
Resize xfs filesystem
mount /dev/mapper/TCPDumpVolGRP-TCPDumpLV /mnt/target xfs_growfs -d /mnt/target
Shrinking ext2/3/4
Shrinking an ext3 volume is fairly straight forward, but it's important you don't mount your drive and start doing stuff, before you verify everything worked correctly.
e2fsck -f /dev/vg/lv1 resize2fs -p /dev/vg/lv1 ###G e2fsck /dev/vg/lv1 lvresize -L ###G /dev/vg/lv1 e2fsck /dev/vg/lv1
Step #5 is the most important step; as steps 1-3 will not have any problems unless you have a system failure, a corrupted file system to start with, disk failure, or hardware failure. Step 5 however, could be due to sys-admin error, from shrinking the LVM volume too much. If you receive an error similar to the following, then you probably shrunk the volume too much, and your file system is not completely accessible.
e2fsck 1.41.9 (22-Aug-2009) The filesystem size (according to the superblock) is 113634135 blocks The physical size of the device is 112197632 blocks Either the superblock or the partition table is likely to be corrupt! Abort<y>? cancelled!
If the error is due to shrinking too far, then this is easy to recover from; simply do another lvresize, with a large size specified, and do another e2fsck afterward.
Generally speaking, you should make the LVM maybe 2% or so larger than the file system was reduced to, so that there's room for file system overhead.