Operating System - Linux
1825792 Members
2621 Online
109687 Solutions
New Discussion

Re: reduce the size of lvm2

 
SOLVED
Go to solution
ramadashsuresh
Frequent Advisor

reduce the size of lvm2

Hai
i am using Redhat EL-4 and configured LVM2
now i want to reduce the logical volume size from 2gb to 1 gb which was mounted on /mnt/lvm and file system is ext3

what are the procedures to reduce the size

4 REPLIES 4
Ivan Ferreira
Honored Contributor
Solution

Re: reduce the size of lvm2

Before reducing the size of a file system, take a full backup of it!!!!

You must reduce in two parts:

- Reduce the ext3 file system
- Reduce the logical volume

You must ensure that when you reduce the logical volume, the logical volume size is not less that the file system size or you can loss the data, so you can reduce the file system size and then reduce the logical volume to a size a little bigger than the file system size, to ensure that you won't break the file system.

Procedure to reduce a 6 GB file system/logical volume to 5 GB, in this case, is /dev/rhel4vg/lvrhel4:

*** Check the current size:

# df -h /mnt/rhel4
S.ficheros Tamaà ±o Usado Disp Uso% Montado en
/dev/mapper/rhel4vg-lvrhel4
6,0G 141M 5,8G 3% /mnt/rhel4

# lvdisplay /dev/rhel4vg/lvrhel4
--- Logical volume ---
LV Name /dev/rhel4vg/lvrhel4
VG Name rhel4vg
LV UUID HcD4Es-Ar4s-0GaI-e3GS-29bI-8uuV-EE9NJH
LV Write Access read/write
LV Status available
# open 1
LV Size 6,00 GB
Current LE 1536
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:2

*** Umount the file system an run fsck:

# umount /mnt/rhel4/

# e2fsck -f /dev/mapper/rhel4vg-lvrhel4
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? yes

Pass 4: Checking reference counts
Pass 5: Checking group summary information

/dev/mapper/rhel4vg-lvrhel4: ***** FILE SYSTEM WAS MODIFIED *****
/dev/mapper/rhel4vg-lvrhel4: 11/786432 files (18.2% non-contiguous), 60567/1572864 blocks

*** Resize the file sytem to 5 GB

# resize2fs /dev/rhel4vg/lvrhel4 5G
resize2fs 1.39 (29-May-2006)
Resizing the filesystem on /dev/rhel4vg/lvrhel4 to 1310720 (4k) blocks.
The filesystem on /dev/rhel4vg/lvrhel4 is now 1310720 blocks long.

*** Resize the logical volume to a value a little bigger than 5 GB (Here you can see in the warning that will be reduced to 5,18 GB)

# lvreduce /dev/rhel4vg/lvrhel4 -L 5300M
/dev/cdrom: open failed: Sistema de ficheros de sà ³lo lectura
Attempt to close device '/dev/cdrom' which is not open.
WARNING: Reducing active logical volume to 5,18 GB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lvrhel4? [y/n]: y
Reducing logical volume lvrhel4 to 5,18 GB
Logical volume lvrhel4 successfully resized

*** Verify the new sizes

# lvdisplay /dev/rhel4vg/lvrhel4
--- Logical volume ---
LV Name /dev/rhel4vg/lvrhel4
VG Name rhel4vg
LV UUID HcD4Es-Ar4s-0GaI-e3GS-29bI-8uuV-EE9NJH
LV Write Access read/write
LV Status available
# open 0
LV Size 5,18 GB
Current LE 1325
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:2

# mount /mnt/rhel4/

# df -h /mnt/rhel4/
S.ficheros Tamaà ±o Usado Disp Uso% Montado en
/dev/mapper/rhel4vg-lvrhel4
5,0G 141M 4,8G 3% /mnt/rhel4


Pretty cool!!, isn't it??
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Steven E. Protter
Exalted Contributor

Re: reduce the size of lvm2

Shalom,

rsize2fs is the primary tool for reducing a filesystem. It must be umounted before you reduce it. The logical volume reduce command you have been provided is excellent and yes, quite cool.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
ramadashsuresh
Frequent Advisor

Re: reduce the size of lvm2

Thanks ivan

the way of explain the concept very clear
now the problem has solved

once again thanking u
have a nice day


ramadashsuresh
Frequent Advisor

Re: reduce the size of lvm2

resize the file system using the following command

resize2fs

reduce the volume size

lvreduce