How To Configure LVM on Linux / CentOS / Redhat

0

 

Page index:
Overview
Setup Physical Volumes
Setup Volume Groups
Setup Logical Volume Group
Extending Volume Group
Extending Logical Volume
Reducing Logical Volume

Page 7 of 7

Reducing Logical Volume:

There is one last problem I have very less user data in the LV (data), unwantedly there is so much of free space which I want to use that for another LV(some other). I need to reduce the size of the LV (data) from 49 GB to 20 GB. Let we do it by using the following steps.

Run the file system check.

[root@SRV01 ~]# e2fsck -f /dev/smbserver/data

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/smbserver/data: 12/5898240 files (8.3% non-contiguous), 487424/11796480 blocks

Resize the file system to 20 GB using the following command.

[root@SRV01 ~]# resize2fs /dev/smbserver/data 20G

resize2fs 1.39 (29-May-2006)

Resizing the filesystem on /dev/smbserver/data to 5242880 (4k) blocks.

The filesystem on /dev/smbserver/data is now 5242880 blocks long.

Then reduce the LV (data) to 20 GB using the following command.

[root@SRV01 ~]# lvreduce -L 20G /dev/smbserver/data

WARNING: Reducing active logical volume to 20.00 GB

THIS MAY DESTROY YOUR DATA (filesystem etc.)

Do you really want to reduce data? [y/n]: y

Reducing logical volume data to 20.00 GB

Logical volume data successfully resized

Check it by using following command.

[root@SRV01 ~]# mount /dev/smbserver/data /smbserver/data/

 

[root@SRV01 ~]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda3 965M 467M 449M 51% /

/dev/sda8 5.5G 144M 5.1G 3% /tmp

/dev/sdb5 9.2G 276M 8.5G 4% /opt

/dev/sda7 4.8G 398M 4.1G 9% /home

/dev/sda6 6.2G 1.4G 4.5G 24% /var

/dev/sda5 9.5G 3.3G 5.7G 37% /usr

/dev/sda1 487M 30M 432M 7% /boot

tmpfs 217M 0 217M 0% /dev/shm

/dev/sdb6 11G 155M 9.9G 2% /vm

none 217M 104K 217M 1% /var/lib/xenstored

/dev/hdc 3.7G 3.7G 0 100% /media/CentOS_5.3_Final

/dev/mapper/smbserver-backup

9.9G 1.2G 8.3G 13% /smbserver/backup

/dev/mapper/smbserver-videos

20G 173M 19G 1% /smbserver/videos

/dev/mapper/smbserver-data

20G 1.2G 18G 7% /smbserver/data

The following output will be final after extending and reducing LV.

[root@SRV01 ~]# lvdisplay

— Logical volume —

LV Name /dev/smbserver/data

VG Name smbserver

LV UUID y3MGj1-E0qP-cL1I-MN6R-yzMO-bnRQ-vXef0N

LV Write Access read/write

LV Status available

# open 1

LV Size 20.00 GB

Current LE 5120

Segments 2

Allocation inherit

Read ahead sectors auto

– currently set to 256

Block device 253:0

— Logical volume —

LV Name /dev/smbserver/backup

VG Name smbserver

LV UUID dlk3oC-pB1U-vbMG-BHcB-ZCMg-L0ye-w4MXsc

LV Write Access read/write

LV Status available

# open 1

LV Size 10.00 GB

Current LE 2560

Segments 1

Allocation inherit

Read ahead sectors auto

– currently set to 256

Block device 253:1

— Logical volume —

LV Name /dev/smbserver/videos

VG Name smbserver

LV UUID Gj1Yjy-yWir-rSt6-S2e7-nUvF-XzxF-Y2iNI6

LV Write Access read/write

LV Status available

# open 1

LV Size 20.00 GB

Current LE 5120

Segments 2

Allocation inherit

Read ahead sectors auto

– currently set to 256

Block device 253:2

 

[root@SRV01 ~]# lvscan

ACTIVE ‘/dev/smbserver/data’ [20.00 GB] inherit

ACTIVE ‘/dev/smbserver/backup’ [10.00 GB] inherit

ACTIVE ‘/dev/smbserver/videos’ [20.00 GB] inherit

Reverting Back:

The following commands will remove all the steps we done above.

[root@SRV01 ~]# umount /dev/smbserver/videos /dev/smbserver/data /dev/smbserver/backup

[root@SRV01 ~]# lvremove /dev/smbserver/videos

[root@SRV01 ~]# lvremove /dev/smbserver/data

[root@SRV01 ~]# lvremove /dev/smbserver/backup

[root@SRV01 ~]# vgremove /dev/smbserver

[root@SRV01 ~]# pvremove /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1

That’s it, the above will give you the basic guide lines to setup LVM on Linux.

 

Main Page

You might also like