Introduction

The example below shows the commands needed to increase the size of a filesystem called /data/archive which is a logical volume of 10G using space from a volume group call vgArchive. The full path to the device is /dev/vgSAN/lvArchive.

Note: These two methods pre-date ext4 filesystems

Update 2014:  ext4 and later file systems do provide a number of on-line resize tools so this article is old but useful for historic reasons.

Method 1 – ext 2 file system resize

  1. Check if File system is begin used – fuser /data/archive
  2. Unmount the file system – umount /data/archive
  3. Now extend the file system device – lvextend -L+10G /dev/vgSAN/lvArchive
  4. Check the filesystem device – fsck -n /dev/vgSAN/lvArchive
  5. Turn off journalling – tune2fs -O ^has_journal /dev/vgSAN/lvArchive
  6. Check the filesystem device – fsck -f /dev/vgSAN/lvArchive
  7. Now resize the file system – ext2resize /dev/vgSAN/lvArchive
  8. Turn jounalling back on – tune2fs -j /dev/vgSAN/lvArchive
  9. remount fle system – mount /data/archive
  10. Check the new size – df -h /data/archive

Method 2 – ext 3 file system resize

  1. Check if File system is begin used – fuser /data/archive
  2. Unmount the file system – umount /data/archive
  3. Now extend the file system device – lvextend -L+10G /dev/vgSAN/lvArchive
  4. Check the filesystem device – fsck -n /dev/vgSAN/lvArchive
  5. Check the filesystem device – fsck -f /dev/vgSAN/lvArchive
  6. Now resize the file system – resize2fs /dev/vgSAN/lvArchive
  7. remount fle system – mount /data/archive
  8. Check the new size – df -h /data/archive

 

Reducing a file system

The other day I built a CloudLinux server and the default build created a filesystem that used all the remaining space in the volume goup which was 180G. The filesystem is 5G in use and I really only need it to be 20G so I reduced it in a couple of stages.

  1. Check if File system is begin used – fuser /vz
  2. Unmount the file system – umount /vz
  3. check the file system first (if you dont resize2fs will tell you the exact command to run) – e2fsck -f /dev/vg0/lv_vz
  4. Then resize it down to the new size with – resize2fs /dev/vg0/lv_vz 10G
  5. Now reduce the logical volume to the new size – lvreduce -L 20G /dev/vg0/lv_vz 
  6. Check the file system again – e2fsck -f /dev/vg0/lv_vz
  7. Now increase to the fill the available space – resize2fs /dev/vg0/lv_vz
  8. remount the file systems and use df to see its new size – mount -a ; df -h

-oOo- 

Advertisements