How to resize a logical volume and a reiserfs or ext3 filesystem
Type df -h to list the filesystem we would like to increase.
Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup00-LVROOT 4.0G 3.4G 480M 90% /
We would like to increase the root filesystem by 500M so we need to determine if the volume group (VolGroup00) listed above has enough free space.
To do this type vgdisplay
--- Volume group --- VG Name VolGroup00 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 7 VG Access read/write VG Status resizable MAX LV 0 Cur LV 5 Open LV 5 Max PV 0 Cur PV 1 Act PV 1 VG Size 136.42 GB PE Size 4.00 MB Total PE 34924 Alloc PE / Size 5760 / 22.50 GB Free PE / Size 29164 / 113.92 GB VG UUID efvr7g-grgf5g-V0SP-45gdf-Xber-VKzj-fg5hf
The "Free PE / Size 29164 / 113.92 GB" line shows that we have 113.92 GB free in this volume group.
Type lvdisplay to show additional information about the logical volumes on the server.
--- Logical volume --- LV Name /dev/VolGroup00/LVROOT VG Name VolGroup00 LV UUID fdsff5-Ma8z-8rr3-5ytgb-fht7-N37h-465yhh LV Write Access read/write LV Status available # open 1 LV Size 4.00 GB Current LE 1152 Segments 2 Allocation inherit Read ahead sectors 0 Block device 253:0
Increase logical volume size
In this case we have identified /dev/VolGroup00/LVROOT as being the logical volume to be modified
The current size of the /dev/VolGroup00/LVROOT logical volume is 4G and we need to increase the size to 4.5G
The first step is to increase the logical volume and the second step to increase the filesystem
To increase the logical volume size use the lvextend command as follows
lvextend -L 4.5G /dev/VolGroup00/LVROOT
Increase the filesystem size
Then to increase the size of the filesystem to equal the new size of the LV, do one of the following depending on whether you have an reiserfs or ext3 filesystem.
To check what filesystems you are using type mount
/dev/mapper/VolGroup00-LVROOT on / type ext3 (rw)
We can see in this case we are using the ext3 filesystem
ext2online -d -v /dev/VolGroup00/LVROOT
resize2fs -p /dev/VolGroup00/LVROOT
Type df -k and lvdisplay to check that all is as expected
Decrease the filesystem size
We would like to decrease the size of the /home filesystem by 2GB.
First check the current size.
[root@linux1 /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_linux1-lv_root 50G 4.8G 42G 11% / tmpfs 1002M 88K 1002M 1% /dev/shm /dev/sda1 485M 29M 431M 7% /boot /dev/mapper/vg_linux1-lv_home 20G 217M 19G 2% /home
Then resize the filesystem before resizing the LV to prevent data loss, however it is still important to backup the fileystem first.
Then try to reduce the size of the /home filesystem as follows.
[root@linux1 /]# resize2fs -p /dev/vg_linux1/lv_home 18G resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/vg_linux1/lv_home is mounted on /home; on-line resizing required On-line shrinking from 5267456 to 4718592 not supported.
This shows that the filesystem needs to be unmounted first.
[root@linux1 /]# umount /home
Ok lets try again.
[root@linux1 /]# resize2fs -p /dev/vg_linux1/lv_home 18G resize2fs 1.41.12 (17-May-2010) Please run 'e2fsck -f /dev/vg_linux1/lv_home' first.
We are still unable to shrink the filesystem until we run the filesystem checker e2fsck
[root@linux1 /]# e2fsck -f /dev/vg_linux1/lv_home e2fsck 1.41.12 (17-May-2010) 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/vg_linux1/lv_home: 212/1318912 files (2.8% non-contiguous), 138179/5267456 blocks
Ok lets have another go.
[root@linux1 /]# resize2fs -p /dev/vg_linux1/lv_home 18G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/vg_linux1/lv_home to 4718592 (4k) blocks. Begin pass 3 (max = 161) Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX The filesystem on /dev/vg_linux1/lv_home is now 4718592 blocks long.
Lets take a look.
[root@linux1 /]# mount /home [root@linux1 /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_linux1-lv_root 50G 4.8G 42G 11% / tmpfs 1002M 88K 1002M 1% /dev/shm /dev/sda1 485M 29M 431M 7% /boot /dev/mapper/vg_linux1-lv_home 18G 217M 17G 2% /home
The following procedure will shrink the reiserfs filesystem mounted on /logs from 20G to 10G
[root@linux1 /]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/system-logs 20G 33M 20G 1% /logs
[root@linux1 /]# mount /dev/mapper/system-logs on /logs type reiserfs (rw,acl,user_xattr) [root@linux1 /]# umount /logs [root@linux1 /]# resize_reiserfs -s -10G /dev/system/logs [root@linux1 /]# mount /dev/system/logs /logs
Decrease the LV size
Ok we just need to reduce the size of the LV now.
[root@linux1 /]# lvreduce -L 18G /dev/vg_linux1/lv_home WARNING: Reducing active logical volume to 18.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv_home? [y/n]: y Reducing logical volume lv_home to 18.00 GiB Logical volume lv_home successfully resized