Linux LVM: Reduce Filesystem and Logical Volume
The following example shows how to reduce the size of a filesystem mounted on an LVM logical volume. The instructions below are only for non-root filesystems. No reboot is required, but the filesystem will need to be unmounted. So, if there are any user applications using this filesystem, they will need to be stopped and the users will need to log out.
Example:
Mountpoint: /data
Disk device: /dev/VolGroup01/LogVol00
Filesystem type: ext3
Important: Prior to proceeding with the steps below, create a backup of /data (or whatever is the name of the filesystem you are resizing) using “tar” or “rsync”. Make sure the destination filesystem has sufficient space.
Example:
Using “tar”:
|
1 |
cd / ; tar cvf data.tar /data |
Using “rsync”:
|
1 |
cd / ; mkdir /data_backup ; rsync -avu /data/ /data_backup/ |
- Unmount filesystem:a. Check for any processes using the filesystem:
1lsof | grep /data
b. Terminate these processes (if any):
Using “while” loop and “kill”:
1234lsof | grep /data | awk '{print $2}' | sort | uniq | while read linedokill -9 ${line}doneOr using “fuser”:
1fuser -k /dataUnmount the filesystem:
1umount -f /dataIf that fails with a “busy” error, then try:
1umount -l /data - Scan the logical disk device and fix any inconsistencies:
1e2fsck -f /dev/VolGroup01/LogVol00
Sample output:
1234567e2fsck 1.39 (29-May-2006)Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/VolGroup01/LogVol00: 3880/9830400 files (1.0% non-contiguous), 380181/19658752 blocks - Resize the logical disk device (this example shows resizing down to 19GB):
1resize2fs /dev/VolGroup01/LogVol00 19456M
Sample output:
123resize2fs 1.39 (29-May-2006)Resizing the filesystem on /dev/VolGroup01/LogVol00 to 4980736 (4k) blocks.The filesystem on /dev/VolGroup01/LogVol00 is now 4980736 blocks long. - Resize the logical volume to something slightly bigger than the new filesystem size:
1lvresize -L 20G /dev/VolGroup01/LogVol00
Sample output:
12345WARNING: Reducing active logical volume to 20.00 GBTHIS MAY DESTROY YOUR DATA (filesystem etc.)Do you really want to reduce LogVol00? [y/n]: yReducing logical volume LogVol00 to 20.00 GBLogical volume LogVol00 successfully resized - Verify the new size of the logical volume:
1lvdisplay /dev/VolGroup01/LogVol00
Sample output:
1234567891011121314--- Logical volume ---LV Name /dev/VolGroup01/LogVol00VG Name VolGroup01LV UUID GT3KXD-UUa3-CTJo-cMDo-BKIc-Lrux-t5nVwGLV Write Access read/writeLV Status available# open 0LV Size 20.00 GBCurrent LE 5120Segments 2Allocation inheritRead ahead sectors auto- currently set to 256Block device 253:2 - Remount the filesystem and verify new size:
123456mount /dev/VolGroup01/LogVol00df -h /dataFilesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup01-LogVol0019G 273M 18G 2% /data
-
ericmreitz
-
HASTHEANSWERS
-
Krazy Bob
-
Mike
-
Arminator
-
Denali
-
ouch
