logos

With Andrii Grytsenko


Technical Diary - With Andrii Grytsenko

LVM resizing

How to increase or decrease size of existing lvm partitions step-by-step

!!!Please be very careful with your data. My advice is back your data up before you start

This tutorial describe only ext3 filesystem.

REDUCING

To reduce your lvm partition first of all you have to unmount you partition, re-size filesystem and lvm partition.

Here is our filesystems:

[root@lvm ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
2.2G  1.1G  976M  53% /
/dev/hda1              99M   12M   82M  13% /boot
tmpfs                  94M     0   94M   0% /dev/shm
/dev/mapper/VolGroup00-home
1.5G   35M  1.4G   3% /home 

Let’s reduce our /home partition by 200 MB:

Unmount you partition:

[root@lvm ~]# umount /home 

Double check that it’s really unmounted. Its should not appear at

df

listing :

[root@lvm ~]# df -h   |grep home
1.5G 35M 1.4G 3% /home

Run check fs tool before you start:

[root@lvm ~]# e2fsck -f /dev/VolGroup00/home
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/VolGroup00/home: 11/192768 files (9.1% non-contiguous), 14826/385024 blocks

Now is time for reducing fs:

[root@lvm ~]# resize2fs /dev/VolGroup00/home 200M
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/VolGroup00/home to 327680 (4k) blocks.
The filesystem on /dev/VolGroup00/home is now 327680 blocks long.

Where, last value in command is size. Its should be equal the total size of partition after reducing(Total_space – reduced_space = OUR_SIZE).

Now you are ready to run lvm reduce tool:
!!!Be careful on this step and always make backups before you start.

[root@lvm ~]# lvresize -L -200Mg /dev/VolGroup00/home
/dev/hdc: open failed: No medium found
Rounding up size to full physical extent 192.00 MB
WARNING: Reducing active logical volume to 1.28 GB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce home? [y/n]: y
Reducing logical volume home to 1.28 GB
Logical volume home successfully resized

mount your partition :

[root@lvm ~]# mount /home

and check it:

[root@node2 ~]# [root@lvm ~]# df -h /home
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-home  1.3G   35M  1.2G   3% /home

As you can see now our partition is 1.3G. Its on 200MB less then old one.

INCREASING

Currently we have 200MB of unallocated space. Next we divide it on two pieces. From first we make new one partition and second one add to existing root(/) partition.

First lets try to make new one:

[root@lvm ~]# lvcreate -l 50%FREE --name test VolGroup00
/dev/hdc: open failed: No medium found
Logical volume "test" created

And make fs:

[root@lvm ~]# mkfs -t ext3 /dev/VolGroup00/test
mke2fs 1.39 (29-May-2006)
THE OUTPUT IS SKIPPED.

Mount and check size of new partition:

[root@lvm ~]# mkdir /mnt/test
[root@lvm ~]# mount /dev/VolGroup00/test /mnt/test/
[root@lvm ~]# df -h | grep test
/dev/mapper/VolGroup00-test  93M  5.6M   83M   7% /mnt/test

Ok. This part is done. Back to our tasks. Lets try to add unallocated space to root partition:

[root@lvm ~]# lvextend -l +100%FREE /dev/VolGroup00/LogVol00
/dev/hdc: open failed: No medium found
Extending logical volume LogVol00 to 2.28 GB
Logical volume LogVol00 successfully resized

TO increase file system, do:

[root@lvm ~]# resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 598016 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 598016 blocks long.

And last one steps remount and check:

[root@lvm ~]# mount -o remount /
[root@lvm ~]# df -h /
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00  2.3G  1.1G  1.1G  51% /

As we can see in the begging of the actions our root partition was 2.2G and now it’s 2.3G. This means that it was increased by 100Mb.

1 Comment to LVM resizing

  1. WP Themes's Gravatar WP Themes
    August 14, 2010 at 08:20 | Permalink

    Good fill someone in on and this enter helped me alot in my college assignement. Say thank you you seeking your information.

Leave a Reply

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Categories

Translate