6.14.1 Adding a New LVM Disk to a Guest

You can add a new LVM disk to an Oracle Linux KVM guest to increase the amount of usable disk space in a guest.

You might add an LVM disk to a guest so that the size of a file system or swap space can be increased. The system remains online while you perform this procedure.

Note:

During this procedure you perform actions in both the KVM host and in the guest.

Run all steps in this procedure as the root user.

  1. In the KVM host, verify that there is sufficient free disk space in /EXAVMIMAGES. For example:
    # df -h /EXAVMIMAGES
    Filesystem                           Size  Used Avail Use%  Mounted on
    /dev/mapper/VGExaDb-LVDbExaVMImages  1.5T   39G  1.5T   3%  /EXAVMIMAGES
  2. In the KVM host, create a new disk image and attach it to the guest.

    For example, the following command adds a guest-specific disk image named pv2_vgexadb.img to the guest dm01db01vm01.example.com:

    # /opt/exadata_ovm/vm_maker --create --disk-image /EXAVMIMAGES/GuestImages/dm01db01vm01.example.com/pv2_vgexadb.img --attach --domain dm01db01vm01.example.com
    [INFO] Allocating an image for /EXAVMIMAGES/GuestImages/dm01db01vm01.example.com/pv2_vgexadb.img, size 52.000000G...
    [INFO] Running 'qemu-img create /EXAVMIMAGES/GuestImages/dm01db01vm01.example.com/pv2_vgexadb.img 52.000000G '...
    [INFO] Create label gpt on /EXAVMIMAGES/GuestImages/dm01db01vm01.example.com/pv2_vgexadb.img.
    [INFO]  Running 'parted -a none -s /EXAVMIMAGES/GuestImages/dm01db01vm01.example.com/pv2_vgexadb.img mklabel gpt'...
    [INFO] Running 'losetup -P -f /EXAVMIMAGES/GuestImages/dm01db01vm01.example.com/pv2_vgexadb.img'...
    [INFO] Finding loop device...
    [INFO]   loop device is /dev/loop0
    [INFO] Finding number of sectors...
    [INFO]   109051904 sectors
    [INFO] Finding sector size...
    [INFO]   512 bytes per sector
    [INFO] Creating filesystem on /dev/VGExaDbDisk.pv2_vgexadb.img/LVDBDisk...
    [INFO]  Running 'mkfs -t xfs   -b size=4096 -f /dev/VGExaDbDisk.pv2_vgexadb.img/LVDBDisk '...
    [INFO] Checking that we have a file system on /dev/VGExaDbDisk.pv2_vgexadb.img/LVDBDisk...
    [INFO] Releasing loop device /dev/loop0...
    [INFO]   Removing device maps for /dev/loop0...
    [INFO]    Running 'kpartx -d -v /dev/loop0'...
    [INFO]  Removing loop device /dev/loop0...
    [INFO] ##
    [INFO] ## Finished .
    [INFO] ##
    [INFO] Created image /EXAVMIMAGES/GuestImages/dm01db01vm01.example.com/pv2_vgexadb.img
    [INFO] Running 'vgscan --cache'...
    [INFO] -------- MANUAL STEPS TO BE COMPLETED FOR MOUNTING THE DISK WITHIN DOMU dm01db01vm01.example.com --------
    [INFO] 1. Check a disk with name /dev/VGExaDbDisk.pv2_vgexadb.img/LVDBDisk exists.
    [INFO] -  Check for the existence of a disk named: /dev/VGExaDbDisk.pv2_vgexadb.img/LVDBDisk. Use the 'lvdisplay' command and check the output.
    [INFO] 2. Create a mount directory for the new disk
    [INFO] 3. Add the following line to /etc/fstab: /dev/VGExaDbDisk.pv2_vgexadb.img/LVDBDisk <mount_point_from_step_2> <fstype> defaults 1 1
    [INFO] 4. Mount the new disk. Use the 'mount -a' command.
    [INFO] Note: when detaching and re-attaching the same disk multiple times, run the following command after detaching and before attaching in the guest domain:
    [INFO] 'lvm vgchange VGExaDbDisk.pv2_vgexadb.img -a -n' when re-attaching the same disk.

    At this time, do not perform the manual steps described at the end of the output. However, take note of the logical volume path identified in manual step number 1. In general, the logical volume path has the form: /dev/VolumeGroupName/LogicalVolumeName. In the example, the logical volume path is /dev/VGExaDbDisk.pv2_vgexadb.img/LVDBDisk.

  3. On the KVM host, list the available disk images for the guest and verify the creation of the new disk image.

    In the example in the previous step, the disk image file is identified as /EXAVMIMAGES/GuestImages/dm01db01vm01.example.com/pv2_vgexadb.img. This image should now appear in the list of disk images for the guest. For example:

    # /opt/exadata_ovm/vm_maker --list --disk-image --domain dm01db01vm01.example.com
    File /EXAVMIMAGES/GuestImages/dm01db01vm01.example.com/System.img
    File /EXAVMIMAGES/GuestImages/dm01db01vm01.example.com/grid19.2.0.0.0.img
    File /EXAVMIMAGES/GuestImages/dm01db01vm01.example.com/db19.2.0.0.0-3.img
    File /EXAVMIMAGES/GuestImages/dm01db01vm01.example.com/pv1_vgexadb.img
    File /EXAVMIMAGES/GuestImages/dm01db01vm01.example.com/pv2_vgexadb.img
  4. On the guest, identify the newly added disk.

    Use the lvdisplay command along with the logical volume path noted earlier.

    # lvdisplay /dev/VGExaDbDisk.pv2_vgexadb.img/LVDBDisk
      --- Logical volume ---
      LV Path                /dev/VGExaDbDisk.pv2_vgexadb.img/LVDBDisk
      LV Name                LVDBDisk
      VG Name                VGExaDbDisk.pv2_vgexadb.img
      LV UUID                ePC0Qe-PfOX-oCoP-Pd5n-2nDj-z0KU-c9IygG
      LV Write Access        read/write
      LV Creation host, time dm01db01vm01.example.com, 2022-01-10 03:06:18 -0800
      LV Status              available
      # open                 0
      LV Size                50.00 GiB
      Current LE             12800
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           252:11
  5. In the guest, remove the logical volume and volume group that were created for the added disk.
    You must perform this step in order to use the newly created disk to extend an existing volume group.
    1. Remove the logical volume.

      In this example, the logical volume path is /dev/VGExaDbDisk.pv2_vgexadb.img/LVDBDisk.

      # lvremove /dev/VGExaDbDisk.pv2_vgexadb.img/LVDBDisk
      Do you really want to remove active logical volume VGExaDbDisk.pv2_vgexadb.img/LVDBDisk? [y/n]: y
        Logical volume "LVDBDisk" successfully removed
    2. Remove the volume group that came with the logical volume.

      In this example, the volume group name is VGExaDbDisk.pv2_vgexadb.img.

      # vgremove VGExaDbDisk.pv2_vgexadb.img
        Volume group "VGExaDbDisk.pv2_vgexadb.img" successfully removed
    At this point, all that is left is the physical volume with no logical volume and no volume group.
  6. In the guest, identify the physical volume device for the newly added disk.

    Use the pvdisplay command and look for the new physical volume.

    In the following example, the output is truncated to highlight the new physical volume:

    # pvdisplay
    ...  
      "/dev/sdf1" is a new physical volume of "<50.00 GiB"
      --- NEW Physical volume ---
      PV Name /dev/sdf1
      VG Name
      PV Size <50.00 GiB
      Allocatable NO
      PE Size 0
      Total PE 0
      Free PE 0
      Allocated PE 0
      PV UUID tfb8lM-eHe9-SPch-8UAu-pkHe-dAYx-ez3Sru
    ...
  7. In the guest, use the new physical volume to extend an existing volume group.

    In the following example, the new physical volume (/dev/sdf1) is used to extend the volume group VGExaDb. The vgdisplay output is truncated to highlight VGExaDb.

    # vgdisplay -s
    ...
      "VGExaDb" 88.00 GiB [88.00 GiB used / 0 free]
    ...
    
    # vgextend VGExaDb /dev/sdf1
      Volume group "VGExaDb" successfully extended
    
    # vgdisplay -s
    ...
      "VGExaDb" <139.24 GiB [88.00 GiB used / <51.24 GiB free]
    ...

To increase the size of various file systems, using the additional space added to the volume group by this procedure, refer to the following topics: