Tuesday 25 June 2013

Shrink root(/) partition - LVM


Objective: Shrink root partition using LVM.

Environment: Redhat 5.0 (32-bit) / CentOS release 6.3 (32-bit).

While I installed my OS long back, I had partitioned more space in the root file system, because of which I was unable to use other file systems due to lack of disk space.

So, incase if few are facing the same issues, here is the tutorial to decrease your space in root partition.

Once your volume group(VG) gets free space, you can extend any where in your logical volumes(LV) which resides in the same volume group(VG)

Change Plan:
1. find the current disk usage in the file system. 
2. Since your root partition(mounted) needs to be re-sized,  need access to unmounted root volume get into the rescue environment.
3. Change to logical volume manager in rescue environment.
4. Shrink the root file system 
5. Reduce root volume.
6. Reboot system and bring it online.
7. Check the root disk after re-sizing.

Technical Implementation:

1. Current disk usage:
tux# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      6.7G  2.0G  4.5G  31% /
/dev/sda1              99M   12M   83M  13% /boot
tmpfs                 379M     0  379M   0% /dev/shm

2. Reboot the system and boot system in rescue environment.

3. In rescue shell, change to LV Manager prompt.
#lvm vgchange -a y

The -a y argument sets the availability to "y" or yes. As there are no specified LVM volume groups, this command will make all LVM volumes found available to the rescue kernel.

Once the kernel is aware of all LVM volumes they will be automatically mapped as devices. These are usually located under /dev/VolGroup.

#ls /dev/VolGroup00/
LogVol00  LogVol01

#e2fsck -f /dev/VolGroup00/LogVol00

4. After the check, resize2fs can be used to shrink the file system on the LVM volume. Here I reduce the root volume to 1GB

#resize2fs -f /dev/VolGroup00/LogVol00 1G

The e2fsck check command could be run again to make sure the, now significantly smaller, root file system is OK.

5. Reduce the root volume.
#lvm lvreduce -L 1G /dev/VolGroup00/LogVol00

The lvreduce command reduces the size of LVM volumes. The -L option allows the new size to be explicitly given. If the option to this argument does not begin with a minus sign, it is taken as the size to reduce the volume.

6. Remove CD/DVD and reboot the system to bring it online.
#reboot

7. Check root partition after reboot.
tux# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      5.9G  2.0G  3.7G  35% /
/dev/sda1              99M   12M   83M  13% /boot
tmpfs                 379M     0  379M   0% /dev/shm

Root partition was shrinked successfully.

Objective successful.

No comments:

Post a Comment