Everything Penguin, Inc.

Helping to support the open source community.
Search this Site:

Local Sources
  • /pub

  • Linux OS
  • /pub/OS/Linux

  • Networking
  • /pub/Networking

  • Network Services
  • /pub/NetworkServices

  • Clustering
  • HA
  • DRM

  • Encryption
  • Keytool/OpenSSL
  • Java Samples

  • Development
  • Design
  • C/C++
  • Java
  • Perl
  • Shell
  • Web / J2EE

  • Storage
  • Filesystems
  • HPC
  • /pub/Storage

  • Not Linux ?
  • BSD
  • HP-UX
  • Solaris
  • VM
  • Windows
  • /pub/OS

  • Security
  • /pub/Security
  •  Parent Directory

    
    
    10 Common tasks
    
    
    
    
    
    
    
    next up previous contents 
    Next: 11 Disk partitioning Up: LVM HOWTO Previous: 9 Transitioning from LVM   Contents

    Subsections

    10 Common tasks

    The following sections outline some common administrative tasks for an LVM system.

    10.1 Initializing disk partitions

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

    1. Set the partition type to 0x8e using fdisk or some other similar program.

    2. Run pvcreate on the partition:

      pvcreate <partition>

      eg, pvcreate /dev/hdb1

      This creates a volume group descriptor at the start of the partition.

    10.2 Creating a volume group

    Use the 'vgcreate' program:

    # vgcreate my_volume_group /dev/hda1 /dev/hdb1
    

    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.

    10.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
    

    10.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
    

    10.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
    

    10.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
    

    10.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.

    10.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
    

    10.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
      

    10.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.

    10.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 up previous contents
    Next: 11 Disk partitioning Up: LVM HOWTO Previous: 9 Transitioning from LVM   Contents
    2001-05-08

    Other Sites

    RFC's
  • FAQ's
  • IETF
  • RFC Sourcebook

  • Linux
  • Linux- Intro
  • Bash - Intro
  • Bash - Advanced
  • Command Line
  • System Administration
  • Network Administration
  • Man Pages (& more)
  • More Guides
  • Red Hat Manuals
  • HOWTO's

  • Reference/Tutorials
  • C++ @ cppreference
  • C++ @ cplusplus
  • CSS @ echoecho
  • DNS @ Zytrax
  • HTML @ W3 Schools
  • Java @ Sun
  • LDAP @ Zytrax
  • Linux @ YoLinux
  • MySQL
  • NetFilter
  • Network Protocols
  • OpenLDAP
  • Quagga
  • Samba
  • Unix Programming


  • Sponsors:
  • BrettLee.com
  • TheFrontOffice.BIZ
  • ScubaNavigator.com
  • Nitrox.net

  • [ Statistics by AWStats ]

    [ Powered by Red Hat Linux ] [ Powered by Apache Server] [ Powered by MySQL ]

    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.