На главную страницу хостинга
Next Previous Contents

9. Common Tasks

The following sections outline some common administrative tasks for an LVM system. This is no substitute for reading the man pages.

9.1 Initializing disks or disk partitions

Before you can use a disk or disk partition as a physical volume you will have to initialize it:

For entire disks:

For partitions:

9.2 Creating a volume group

Use the 'vgcreate' program:

# vgcreate my_volume_group /dev/hda1 /dev/hdb1

NOTE: If you are using devfs it is essential to use the full devfs name of the device rather than the symlinked name in /dev. so: the above would be:

# vgcreate my_volume_group /dev/ide/host0/bus0/target0/lun0/part1 \
                           /dev/ide/host0/bus0/target1/lun0/part1

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.

9.3 Activating a volume group

After rebooting the system or running vgchange -an, you will not be able to access your VGs and LVs. To reactivate the volume group, run:

# vgchange -a y my_volume_group

9.4 Removing a volume group

Make sure that no logical volumes are present in the volume group, see later section for how to do this.

Deactivate the volume group:

# vgchange -a n my_volume_group

Now you actually remove the volume group:

# vgremove my_volume_group

9.5 Adding physical volumes to a volume group

Use 'vgextend' to add an initialized physical volume to an existing volume group.

# vgextend my_volume_group /dev/hdc1
                           ^^^^^^^^^ new physical volume

9.6 Removing physical volumes from a volume group

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:

# vgreduce my_volume_group /dev/hda1

9.7 Creating a logical volume

Decide which physical volumes you want the logical volume to be allocated on, use 'vgdisplay' and 'pvdisplay' to help you decide.

# lvcreate -L1500 -ntestlv testvg
Will create a 1500MB linear LV named 'testlv' and its block device special '/dev/testvg/testlv'.

# lvcreate -i2 -I4 -l100 -nanothertestlv testvg

Will create a 100 LE large logical volume with 2 stripes and stripesize 4 KB.

If you want to create an LV that uses the entire VG, use vgdisplay to find the "Total PE" size, then use that when running lvcreate.

# vgdisplay testvg | grep "Total PE"
Total PE              10230
# lvcreate -l 10230 testvg -n mylv
This will create an LV called mylv filling the testvg VG.

9.8 Removing a logical volume

A logical volume must be closed before it can be removed:

# umount /dev/myvg/homevol
# lvremove /dev/myvg/homevol
lvremove -- do you really want to remove "/dev/myvg/homevol"? [y/n]: y
lvremove -- doing automatic backup of volume group "myvg"
lvremove -- logical volume "/dev/myvg/homevol" successfully removed

9.9 Extending a logical 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.

  1. 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
    # e2fsadm -L+1G /dev/myvg/homevol
    
    is equivalent to the two commands:
    # lvextend -L+1G /dev/myvg/homevol
    # resize2fs /dev/myvg/homevol
    
    Note that you still need to unmount the file system first though.
  2. reiserfs Reiserfs file systems can be resized when mounted or unmounted as you prefer: Online:
    # resize_reiserfs -f /dev/myvg/homevol
    
    Offline:
    # umount /dev/myvg/homevol
    # resize_reiserfs /dev/myvg/homevol
    # mount -treiserfs /dev/myvg/homevol /home
    
  3. xfs XFS file systems must be mounted to be resized and the mount-point is specified rather than the device name.
    # xfs_growfs /home
    

9.10 Reducing a logical volume

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.

  1. 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:
    # umount /home
    # resize2fs /dev/myvg/homevol 524288
    # lvreduce -L-1G /dev/myvg/homevol
    # mount /home
    
  2. reiserfs Reiserfs seems to prefer to be unmounted when shrinking
    # umount /home
    # resize_reiserfs -s-1G /dev/myvg/homevol
    # lvreduce -L-1G /dev/myvg/homevol
    # mount -treiserfs /dev/myvg/homevol /home
    
  3. xfs There is no way to shrink XFS file systems.

9.11 Migrating data from one physical volume to another

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.

# pvmove /dev/hdb1 /dev/sdg1


Next Previous Contents
Статистика хостинга IHO.RU на сайте mail.ru
ХостингЧто скажет Rambler про ХОСТИНГ IHO.RU