You can also specify the extent size with this command if the default of 4MB
is not suitable for you with the '-s' switch. In addition you can put some
limits on the number of physical or logical volumes the volume can have.
Make sure that the physical volume isn't used by any logical volumes by using
then 'pvdisplay' command:
# pvdisplay /dev/hda1--- Physical volume ---
PV Name /dev/hda1
VG Name myvg
PV Size 1.95 GB / NOT usable 4 MB [LVM: 122 KB]
PV# 1
PV Status available
Allocatable yes (but full)
Cur LV 1
PE Size (KByte) 4096
Total PE 499
Free PE 0
Allocated PE 499
PV UUID Sd44tK-9IRw-SrMC-MOkn-76iP-iftz-OVSen7
If the physical volume is still used you will have to migrate the data to
another physical volume.
Then use 'vgreduce' to remove the physical volume:
To extend a logical volume you simply tell the lvextend command how much you
want to increase the size. You can specify how much to grow the volume, or how
large you want it to grow to:
# lvextend -L12G /dev/myvg/homevol
lvextend -- extending logical volume "/dev/myvg/homevol" to 12 GB
lvextend -- doing automatic backup of volume group "myvg"
lvextend -- logical volume "/dev/myvg/homevol" successfully extended
will extend /dev/myvg/homevol to 12 Gigabytes.
# lvextend -L+1G /dev/myvg/homevol
lvextend -- extending logical volume "/dev/myvg/homevol" to 13 GB
lvextend -- doing automatic backup of volume group "myvg"
lvextend -- logical volume "/dev/myvg/homevol" successfully extended
will add another gigabyte to /dev/myvg/homevol.
After you have extended the logical volume it is necessary to increase the
file system size to match. how you do this depends on the file system you are
using.
By default, most file system resizing tools will increase the size of the
file system to be the size of the underlying logical volume so you don't need to
worry about specifying the same size for each of the two commands.
ext2
Unless you have patched your kernel with the ext2online patch it is
necessary to unmount the file system before resizing it.
# umount /dev/myvg/homevol/dev/myvg/homevol
# resize2fs /dev/myvg/homevol
# mount /dev/myvg/homevol /home
If you don't have e2fsprogs 1.19 or later, you can download the ext2resize
command from ext2resize.sourceforge.net and use that:
# umount /dev/myvg/homevol/dev/myvg/homevol
# resize2fs /dev/myvg/homevol
# mount /dev/myvg/homevol /home
For ext2 there is an easier way. LVM ships with a utility called e2fsadm
which does the lvextend and resize2fs for you (it can also do file system
shrinking, see the next section) so the single command
Logical volumes can be reduced in size as well as increased. However, it is
very important to remember to reduce the size of the file system or
whatever is residing in the volume before shrinking the volume itself, otherwise
you risk losing data.
ext2
If you are using ext2 as the file system then you can use the e2fsadm
command mentioned earlier to take care of both the file system and volume
resizing as follows:
# umount /home
# e2fsadm -L-1G /dev/myvg/homevol
# mount /home
If you prefer to do this manually you must know the new size of the volume
in blocks and use the following commands:
If you want to take a disk out of service it must first have all of its
active physical extents moved to another disk. This disk must be an LVM physical
volume in the same volume group as the disk to be removed and have enough free
space to hold the extents to be copied from the old disk. For further detail see
Removing
an old disk.
The following command moves all the data from the IDE disk partition
/dev/hdb1 onto a SCSI disk partition /dev/sdg1. Be aware that this command can
take a considerable amount of time to complete.
Also, if the extents contain a striped logical volume then the process cannot
be interrupted so it is strongly recommended that you take a backup of your data
before starting pvmove.
In an effort to provide a service of value to the open source community, I've put together this website that containing many of my notes and references.
This website is not authoritative and it is certainly not without errors; it is a work in progress.
In addition to my contributions you will also find the work of others. Where the work is not mine, I have tried to indicate that, and to reference the source of the work: by citing the original author, retaining the authors' name and license wherever present, or by placing the work in a suitably named URL containg /external/ in the path. If you find any work here that should not be publically available, please send me a note and it will be removed.
As for my contributions, you are free to use any of *MY* notes or code from this website unless specifically instructed otherwise.
Brett Lee, Ph.D., President & CEO
Everything Penguin, Inc.