UnixServerAdmin

Server Administration & Management

How to Shrink or reduce size of LVM partitons in RHEL/CentOS

1. Check disk partitions size

# df -hT

Filesystem    Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 ext3 34G 6.6G 26G 21% /
/dev/mapper/VolGroup00-LogVol03 ext3 34G 29G 27G 52% /usr
/dev/mapper/VolGroup00-LogVol04 ext3 97G 89G 2.7G 98% /var
/dev/sda1 ext3 99M 27M 67M 29% /boot
tmpfs tmpfs 56G 0 56G 0% /dev/shm
/dev/mapper/VolGroup00-LogVol02 ext3 56G 9.1G   65G 13% /backup

2. Unmount the partitions that want to shrink or reduce

# umount /dev/mapper/VolGroup00-LogVol02

3. Check a Linux ext2/ext3/ext4 file system partition.

# /sbin/e2fsck -f /dev/mapper/VolGroup00-LogVol02

e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
/lost+found not found.  Create<y>? yes
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/VolGroup00-LogVol02: ***** FILE SYSTEM WAS MODIFIED *****
/dev/mapper/VolGroup00-LogVol02: 2887/20971520 files (14.9% non-contiguous), 3019764/20971520 blocks

4. Resize the partition to 30 GB

# /sbin/resize2fs -p /dev/mapper/VolGroup00-LogVol02 30G

resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/mapper/VolGroup00-LogVol02 to 7864320 (4k) blocks.
Begin pass 2 (max = 1690914)
Relocating blocks             XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 640)
Scanning inode table          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 201)
Updating inode references     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/VolGroup00-LogVol02 is now 7864320 blocks long.

5. Reduce the size of a logical volume upto 30 GB

# /usr/sbin/lvreduce -L 30G /dev/mapper/VolGroup00-LogVol02

  WARNING: Reducing active logical volume to 30.00 GB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
  Do you really want to reduce LogVol02? [y/n]: y
  Reducing logical volume LogVol02 to 30.00 GB
  Logical volume LogVol02 successfully resized

6. Recheck  again, Linux ext2/ext3/ext4 file system partition.

# /sbin/e2fsck -f /dev/mapper/VolGroup00-LogVol02

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/VolGroup00-LogVol02: 2887/7864320 files (14.9% non-contiguous), 2606289/7864320 blocks

7. Resize the partition to 30 GB

# /sbin/resize2fs -p /dev/mapper/VolGroup00-LogVol02

resize2fs 1.39 (29-May-2006)
The filesystem is already 7864320 blocks long.  Nothing to do!

8. Now, Mount the partition.

# mount /dev/mapper/VolGroup00-LogVol02  /backup

9. Again, Check disk partitions size

# df -hT

Filesystem    Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00 ext3 34G 6.6G 26G 21% /
/dev/mapper/VolGroup00-LogVol03 ext3 34G 29G 27G 52% /usr
/dev/mapper/VolGroup00-LogVol04 ext3 97G 89G 2.7G 98% /var
/dev/sda1 ext3 99M 27M 67M 29% /boot
tmpfs tmpfs 56G 0 56G 0% /dev/shm
/dev/mapper/VolGroup00-LogVol02 ext3 30G 9.1G   19G 33% /backup

Its Done !!!

Advertisements

October 30, 2013 - Posted by | LVM, Tips & Tricks, Unix/Linux | , , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: