Friday, 10 February 2012

SHRINK EXT3 filesystem

Ex:

  1. First, check to see how much space is available

    [root@Linux01 ~]# pwd
    /TCPDumpLV
    [root@Linux01 TCPDumpLV]# df -kh .
    FilesystemSizeUsedAvailUse%Mounted on
    /dev/mapper/TCPDumpVolGRP-TCPDumpLV6.1G922M4.9G16%/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 NameTCPDumpVolGRP
    LV UUIDhYQs4t-YtY7-51hl-c4ps-4N6d-2W7h-IidcxF
    LV Write Accessread/write
    LV Statusavailable
    # open0
    LV Size1.50 GB
    Current LE48
    Segments1
    Allocationinherit
    Read ahead sectorsauto
    - currently set to256
    Block device253:5
    1. Remount the file system and verify the new size
    1. [root@Linux01 /]# mount /dev/TCPDumpVolGRP/TCPDumpLV
      [root@Linux01 /]# cd /TCPDumpLV/
      <>
    1. [root@Linux01 TCPDumpLV]# df -kh .
    1. Filesystem
    1. Size
    1. Used
    1. Avail
    1. Use%
    1. Mounted on
    1. /dev/mapper/TCPDumpVolGRP-TCPDumpLV
    1. 1.5G
    1. 920M
    1. 497M
    1. 65%
    1. /TCPDumpLV

  • No comments:

    Post a Comment