Reduce and Relocate Volume Groups on Oracle Linux

4
0
Send lab feedback

Reduce and Relocate Volume Groups on Oracle Linux

Introduction

Logical Volume Management allows for removing unused physical volumes (PVs) and for the moving of an entire volume group (VGs). The removal of a PV shrinks the overall size of the VG.

This tutorial will work with the Oracle Linux Volume Manager utilities to shrink a volume group by removing a physical volume and then transferring the volume group to another system.

Objectives

  • Move a logical volume
  • Shrink a volume group
  • Transfer a volume group to another system

Prerequisites

Two Oracle Linux 8 systems with the following configurations:

  • a non-root user with sudo permissions
  • additional block volumes for use with LVM

Setup Lab Environment

Note: When using the free lab environment, see Oracle Linux Lab Basics for connection and other usage instructions.

  1. If not already connected, open a terminal and connect via ssh to the ol-node01 instance.

    ssh oracle@<ip_address_of_instance>
  2. Verify the block volumes exist.

    sudo lsblk

    The output for the free lab environment should show the /dev/sda for the root file system, /dev/sdb for the demo volume group, and the available disks /dev/sdc and /dev/sdd.

  3. Show the consistent device name mappings.

    The free lab environment uses consistent device name paths for the attached block volumes.

    ll  /dev/oracleoci/oraclevd*

    Example Output:

    [oracle@ol-node01 ~]$ ll /dev/oracleoci/oraclevd*
    lrwxrwxrwx. 1 root root 6 Jun  9 13:27 /dev/oracleoci/oraclevda -> ../sda
    lrwxrwxrwx. 1 root root 7 Jun  9 13:27 /dev/oracleoci/oraclevda1 -> ../sda1
    lrwxrwxrwx. 1 root root 7 Jun  9 13:27 /dev/oracleoci/oraclevda2 -> ../sda2
    lrwxrwxrwx. 1 root root 7 Jun  9 13:27 /dev/oracleoci/oraclevda3 -> ../sda3
    lrwxrwxrwx. 1 root root 6 Jun  9 13:27 /dev/oracleoci/oraclevdb -> ../sdd
    lrwxrwxrwx. 1 root root 6 Jun  9 13:45 /dev/oracleoci/oraclevdd -> ../sdc

    Notice that the consistent name endings defined in Oracle Cloud Infrastructure do not match one-for-one with the device names provided by the Linux OS. Knowing these mappings will be essential later when detaching and attaching block volumes in the Cloud Console.

Remove PV from VG

Before removing an active physical volume from a volume group, move any data and logical volumes on the physical volume to some other free PV.

  1. Check the disk space used by the physical volumes.

    sudo pvs -o+pv_used

    Example Output:

    [oracle@ol-node01 ~]$ sudo pvs -o+pv_used
      PV         VG        Fmt  Attr PSize  PFree  Used  
      /dev/sda3  ocivolume lvm2 a--  45.47g     0  45.47g
      /dev/sdb   labvolume lvm2 a--  49.98g 47.98g  2.00g

    The output shows the /dev/sdb PV uses 2g.

  2. Extend the volume group.

    Add another physical volume by extending the volume group.

    sudo vgextend labvolume /dev/sdc

    Adding /dev/sbc provides a free physical volume to accept the transfer of data and logical volumes from the original /dev/sdb physical volume.

  3. Verify the addition of the /dev/sdc physical volume.

    sudo pvs

    Example Output:

    [oracle@ol-node01 ~]$ sudo pvs
      PV         VG        Fmt  Attr PSize  PFree 
      /dev/sda3  ocivolume lvm2 a--  45.47g     0 
      /dev/sdb   labvolume lvm2 a--  49.98g 47.98g
      /dev/sdc   labvolume lvm2 a--  49.98g 49.98g
  4. Move the existing data and logical volumes to the newly added free PV.

    sudo pvmove /dev/sdb /dev/sdc

    The pvmove command allows moving the allocated physical extents (PEs) on a source PV to one or more other PVs. The transfer uses the normal allocation rules for the volume group if a destination PV is not specified. The task is completed online without interruption, and the command line output shows progress.

    See the pvmove(8) manual for more details.

  5. Verify the move completed.

    sudo pvs -o+pv_used

    Example Output:

    [oracle@ol-node01 ~]$ sudo pvs -o+pv_used
      PV         VG        Fmt  Attr PSize  PFree  Used  
      /dev/sda3  ocivolume lvm2 a--  45.47g     0  45.47g
      /dev/sdb   labvolume lvm2 a--  49.98g 49.98g     0 
      /dev/sdc   labvolume lvm2 a--  49.98g 47.98g  2.00g

    The output shows the /dev/sdc PV uses 2g and /dev/sdb is unused.

  6. Release the original physical volume.

    sudo vgreduce labvolume /dev/sdb
  7. Confirm original physical volume is completely free.

    sudo pvs -o+pv_used

    Example Output:

    [oracle@ol-node01 ~]$ sudo pvs -o+pv_used
      PV         VG        Fmt  Attr PSize  PFree  Used  
      /dev/sda3  ocivolume lvm2 a--  45.47g     0  45.47g
      /dev/sdb             lvm2 ---  50.00g 50.00g     0 
      /dev/sdc   labvolume lvm2 a--  49.98g 47.98g  2.00g

    Notice the volume group name labvolume is no longer associated with the physical volume /dev/sdb and is now associated with /dev/sdc.

  8. Remove the original physical volume.

    sudo pvremove /dev/sdb

    The physical volume /dev/sdb is now free to use in another volume group or be removed physically from the system.

Move PV Between Systems

LVM allows moving an entire volume group from one system to another. The example moves the volume group named labvolume with a logical volume mounted at /u01 from ol-node01 to ol-node02.

  1. Unmount the file system on ol-node01.

    sudo umount /u01
  2. Make the volume group inactive.

    Marking the volume group inactive means the logical volumes in the group are not accessible and unable to change. This deactivation of the volume group further makes it unknown to the kernel.

    sudo vgchange -an labvolume
  3. Prepare the volume to be removed.

    sudo vgexport labvolume
  4. Determine the block volume device path.

    The next step removes the physical volume /dev/sdc associated with the volume group labvolume from instance ol-node01. To select the correct block device within the Cloud Console to detach, get the block device path name oraclevd* associated with the PV /dev/sdc.

    ll /dev/oracleoci/oraclevd* | grep sdc
  5. Remove the disk from the ol-node01 server.

    With a physical server, shut down the system and unplug the disk. However, in the free lab environment, we must detach the volume from the instance.

    Although there are several ways to accomplish this task, we'll use the Cloud Console.

    1. Log in to the Cloud Console.

    2. Open the navigation menu and click Compute. Under Compute, click Instances.

      navigation menu

    3. Click on the ol-node01 instance in the list.

    4. Under Resources in the lower left of the page, select Attached block volumes.

      Resources menu

    5. Use the three-dot menu next to the block device Name associated with the physical volume /dev/sdc and select Detach.

      Detach volume

      Important: The block device Name to choose is the one matching the Device path reported in the

      Determine the block volume device path
      https://luna.oracle.com/api/v1/labs/ee495d1a-4e00-4d77-9719-2f27591d1ecd/gitlab/tutorial/#s4
      step above. It may not match the Name selected in the screenshot provided.

    6. Select the Ok button in the pop-up window, and wait for the volume to detach.

    7. Use the breadcrumbs at the top of the page, and select Instances.

      Breadcrumb menu

    8. Select the ol-node02 instance in the list.

    9. Under Resources on the lower left, select Attached block volumes.

    10. Click the Attach block volume button.

    11. In the pop-up window, attach the block volume removed from ol-node01.

      Select the block device Name previously detached from the ol-node01 instance for the Volume.

      Then select oraclevdb for Device path, Paravirtualized for Attachment type, and Read/write for Access.

      Attach volume settings
      Attach type settings

    12. Click the Attach button, and wait for the volume to attach.

  6. Open a new terminal and connect via ssh to the ol-node02 instance.

    ssh oracle@<ip_address_of_instance>
  7. Verify the new block volume exists.

    sudo lsblk

    The output for the free lab environment should show the /dev/sda for the root file system and /dev/sdb for the volume group.

  8. Scan the attached volume.

    Run an initial scan to recognize the attached LVM physical volumes.

    sudo pvscan

    Example Output:

    [oracle@ol-node02 ~]$ sudo pvscan
      PV /dev/sdb     is in exported VG labvolume [49.98 GiB / 47.98 GiB free]
      PV /dev/sda3   VG ocivolume       lvm2 [45.47 GiB / 0    free]
      Total: 2 [<95.46 GiB] / in use: 2 [<95.46 GiB] / in no VG: 0 [0   ]

    The scan shows the PV device /dev/sdb contains the volume group export from ol-node01.

  9. Import the volume group.

    sudo vgimport labvolume
  10. Activate the volume group.

    sudo vgchange -ay labvolume
  11. Mount the file system.

    sudo mkdir /u01
    sudo mount /dev/labvolume/data /u01
  12. Verify the space on the file system.

    df -h

    Example Output:

    [oracle@ol-node02 ~]$ df -h
    Filesystem                  Size  Used Avail Use% Mounted on
    ...
    /dev/mapper/labvolume-data  2.0G  6.0M  1.8G   1% /u01

For More Information:

SSR