From LQWiki
Jump to navigation Jump to search

lvreduce is the command that lets you reduce the size of a logical volume. Since lvreduce operates at extent level, a filesystem on the logical volume has to be resized beforehand (using resize2fs), since any data in the part to be reduced will be lost.


 #lvreduce  -l -3 myGroup/myVolume
to reduce logical volume myVolume in volume group myGroup with 3 extents

Reducing ext3 File Systems

Although ext3 file systems can be grown online, in order to reduce them, they must be umounted first. Thus, the root file system cannot be reduced without booting from e.g. a CD (or alternate root partition).

Apart from this, the procedure is similar to growing an ext3 file system. The steps are:

  1. umount the file system. This may involve stopping processes, stopping logins or even switching to single-user mode.
  2. reduce the size of the ext3 file system to the desired size
  3. reduce the size of the logical volume
  4. grow the file system again to occupy the whole logical volume
  5. mount the file system again
  6. restart any stopped processes

For example to reduce /home to 4 Gb (it used to be 5 Gb), the a typical command sequence could be:

myhost:~# cd /
myhost:/# umount /home
myhost:/# e2fsck -f /dev/mapper/myhost-home
e2fsck 1.41.3 (12-Oct-2008)
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/mapper/myhost-home: 11/655360 files (0.0% non-contiguous), 79696/2621440 blocks
myhost:/# resize2fs -p /dev/mapper/myhost-home 3G
resize2fs 1.41.3 (12-Oct-2008)
Resizing the filesystem on /dev/mapper/myhost-home to 786432 (4k) blocks.
Begin pass 2 (max = 32801)
Begin pass 3 (max = 80)
The filesystem on /dev/mapper/myhost-home is now 786432 blocks long.
myhost:/# lvreduce --size 4G /dev/mapper/myhost-home
  WARNING: Reducing active logical volume to 4.00 GB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce home? [y/n]: y
  Reducing logical volume home to 4.00 GB
  Logical volume home successfully resized
myhost:/# resize2fs /dev/mapper/myhost-home
resize2fs 1.41.3 (12-Oct-2008)
Resizing the filesystem on /dev/mapper/myhost-home to 1048576 (4k) blocks.
The filesystem on /dev/mapper/myhost-home is now 1048576 blocks long.
myhost:/# mount /home