Pick a Free OS

User login

Navigation

LVM: The logical way to manage space

Well, this is cited as the most important reason for using LVM— -- the fact that you can just add space to your volume group and also dynamically resize your logical volumes.

Adding more space to your volume group is a simple affair. Let’s say you have /dev/hda9 of type Linux LVM and you would like to add that to the volume group freeos. The tool to use is vgextend.

# vgextend freeos /dev/hda9

vgextend— -- INFO: maximum logical volume size is 255.99 Gigabyte

vgextend -- —doing automatic backup of volume group “freeos”

vgextend -- —volume group “freeos” successfully extended

Ok, so now you have added more space to your volume group. Let’s use some of the space to extend our lv1 logical volume.

# lvextend -L+1G /dev/freeos/lv1

lvextend— -- extending logical volume “/dev/freeos/lv1” to 2 GB

lvextend— -- doing automatic backup of volume group “freeos”

lvextend— -- logical volume “/dev/freeos/lv1” successfully extended

Lvextend takes a variety of parameters for size. You use the plus “+” to say that that partition size should be extended by 1 GB. You can, alternatively, use a “-“ here to reduce the partition size by 1 GB. You can give an absolute value too.

Now check the free space on your partition.

# df -h

/dev/freeos/lv1 1.0G 32M 992M 3% /mnt/test

You still need to resize the filesystem to take over the new space.

# resize_reiserfs -s+1024M -f /dev/freeos/lv1

# df -h

/dev/freeos/lv1 2.0G 32M 2.0G 2% /mnt/test

Although you can do the resize while the partition is online, we recommend that you first unmount the partition and then do such operations on the filesystem. When resizing downwards, it is definitely a must that you unmount the filesystem.

To reduce the filesystem size, first reduce the size of your logical volume.

# resize_reiserfs -s-1024M -f /dev/freeos/lv1

You are running ALPHA version of reiserfs shrinker.

This version is only for testing or very careful use. Backup of your data is essential.

Do you want to continue? [y/N]:y

Processing the tree: 0%....20%....40%....60%....80%....100%

nodes processed (moved):

int 0 (0),

leaves 1 (0),

unfm 0 (0),

total 1 (0).

ReiserFS report:

blocksize 4096

block count 262144 (524288)

free blocks 253925 (516061)

bitmap block count 8 (16)

Syncing..done

Now reduce the size of the logical volume.

# lvreduce -L-1G /dev/freeos/lv1