Configure Logical Volumes on Oracle Linux

5
0
Send lab feedback

Configure Logical Volumes on Oracle Linux

Introduction

Logical Volume Management allows combining multiple individual hard drives or disk partitions into a single volume group (VG). That volume group can then be subdivided into logical volumes (LV) or used as a single large volume. Standard file systems, such as EXT4 or XFS, can be created on a logical volume.

This tutorial will work with the Oracle Linux Volume Manager utilities to create, mount, and increase the capacity of logical volumes.

Objectives

In this tutorial, you will learn to:

  • Create a logical volume
  • Increase the capacity of a logical volume

Prerequisites

  • Minimum of one Oracle Linux system

  • Each system should have Oracle Linux installed and configured with:

    • A non-root user account with sudo access
    • Access to the Internet
    • An additional block device

Deploy Oracle Linux

Note: If running in your own tenancy, read the linux-virt-labs GitHub project README.md and complete the prerequisites before deploying the lab environment.

  1. Open a terminal on the Luna Desktop.

  2. Clone the linux-virt-labs GitHub project.

    git clone https://github.com/oracle-devrel/linux-virt-labs.git
  3. Change into the working directory.

    cd linux-virt-labs/ol
  4. Install the required collections.

    ansible-galaxy collection install -r requirements.yml
  5. Deploy the lab environment.

    ansible-playbook create_instance.yml -e localhost_python_interpreter="/usr/bin/python3.6" -e add_block_storage=true -e block_count=3

    The free lab environment requires the extra variable local_python_interpreter, which sets ansible_python_interpreter for plays running on localhost. This variable is needed because the environment installs the RPM package for the Oracle Cloud Infrastructure SDK for Python, located under the python3.6 modules.

    The default deployment shape uses the AMD CPU and Oracle Linux 8. To use an Intel CPU or Oracle Linux 9, add -e instance_shape="VM.Standard3.Flex" or -e os_version="9" to the deployment command.

    Important: Wait for the playbook to run successfully and reach the pause task. At this stage of the playbook, the installation of Oracle Linux is complete, and the instances are ready. Take note of the previous play, which prints the public and private IP addresses of the nodes it deploys and any other deployment information needed while running the lab.

Connect and Format a Block Device

  1. Open a terminal and connect via SSH to the ol-node-01 instance.

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

    sudo lsblk

    The output should show the boot device for the existing file system and several available disks.

Physical Volume (PV)

  1. Create the physical volumes (PV) using the available disks.

    sudo pvcreate -v /dev/sd{b,c}

    Run the command with the -v option to get verbose information.

  2. Verify PV creation.

    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             lvm2 ---  50.00g 50.00g
      /dev/sdc             lvm2 ---  50.00g 50.00g

    For more detailed PV information, run pvdisplay or pvscan to scan all disks for physical volumes.

Volume Group (VG)

  1. Create the volume group (VG) using the newly created physical volumes.

    sudo vgcreate -v myvolg /dev/sd{b,c}
  2. Verify VG creation.

    sudo vgs

    Example Output:

    [oracle@ol-node01 ~]$ sudo vgs
      VG             #PV #LV #SN Attr   VSize   VFree  
      myvolg           2   0   0 wz--n- 99.99g  99.99g
      ocivolume        1   2   0 wz--n- 45.47g      0 

    For more detailed VG information, run vgdisplay or use vgscan to scan all disks for volume groups.

Logical Volume (LV)

  1. Create the linear logical volume (LV).

    sudo lvcreate -v -L 5G -n myvol myvolg

    Where:

    • -L: Total size of the RAID array.
    • -n: Name of the RAID array.

    Example Output:

    [oracle@ol-node01 ~]$ sudo lvcreate -v -L 5G -n myvol myvolg
      Archiving volume group "myvolg" metadata (seqno 1).
      Creating logical volume myvol
      Creating volume group backup "/etc/lvm/backup/myvolg" (seqno 2).
      Activating logical volume myvolg/myvol.
      activation/volume_list configuration setting not defined: Checking only host tags for myvolg/myvol.
      Creating myvolg-myvol
      Loading table for myvolg-myvol (252:2).
      Resuming myvolg-myvol (252:2).
      Wiping known signatures on logical volume myvolg/myvol.
      Initializing 4.00 KiB of logical volume myvolg/myvol with value 0.
      Logical volume "myvol" created.
  2. Verify LV creation.

    sudo lvdisplay myvolg

    The output shows all logical volumes contained within the myvolg VG.

    Example Output:

    [oracle@ol-node01 ~]$ sudo lvdisplay myvolg
      --- Logical volume ---
      LV Path                /dev/myvolg/myvol
      LV Name                myvol
      VG Name                myvolg
      LV UUID                1gfINq-AcWq-Bhys-gafP-21RL-x39A-vR6hqE
      LV Write Access        read/write
      LV Creation host, time ol-node01, 2022-05-20 23:27:38 +0000
      LV Status              available
      # open                 0
      LV Size                5.00 GiB
      Current LE             1280
      Segments               1
      Allocation             inherit
      Read ahead sectors     auto
      - currently set to     256
      Block device           252:2

    For condensed VG information, run lvs or use lvscan to scan all disks for volume groups.

  3. Display the LV type.

    sudo lvs -o name,segtype /dev/myvolg/myvol
    • The lvs command can take the full LV path as an option to narrow the results.

    Example Output:

    [oracle@ol-node01 ~]$ sudo lvs -o name,segtype /dev/myvolg/myvol
      LV    Type  
      myvol linear

Create a File System

  1. Create an EXT4 file system on the logical volume.

    sudo mkfs.ext4 -F /dev/myvolg/myvol

    Where:

    • -F: Forces the overwrite of an existing file system.

Mount the LV

  1. Mount the file system.

    sudo mkdir -p /myvol
    sudo mount /dev/myvolg/myvol /myvol
  2. Report the file system disk usage.

    df -h

    Example Output:

    [oracle@ol-node01 ~]$ df -h
    Filesystem                         Size  Used Avail Use% Mounted on
    ...
    /dev/mapper/myvolg-myvol           4.9G   20M  4.6G   1% /myvol
  3. Update the fstab file.

    echo "/dev/mapper/myvolg-myvol /myvol ext4  defaults  0 0" | sudo tee -a /etc/fstab > /dev/null
  4. Unmount the LV.

    sudo umount /myvol
  5. Remount the LV using the fstab entry and verify the file system exists.

    sudo mount -a
    df -h

Increase the Size of a Logical Volume

Using the available free space in the VG, increase the LV size to 10G.

  1. Check if the VG has free space.

    sudo vgs

    The myvolg VG has 95G space free (VFree).

  2. Increase the LV capacity.

    sudo lvextend -L 10G -r myvolg/myvol

    Where:

    • -r: Resizes the file system together with the logical volume using fsadm(8).

    Example Output:

    [oracle@ol-node01 ~]$ sudo lvextend -L 10G -r myvolg/myvol
      Size of logical volume myvolg/myvol changed from 5.00 GiB (1280 extents) to 10.00 GiB (2560 extents).
      Logical volume myvolg/myvol successfully resized.
    resize2fs 1.45.6 (20-Mar-2020)
    Filesystem at /dev/mapper/myvolg-myvol is mounted on /myvol; on-line resizing required
    old_desc_blocks = 1, new_desc_blocks = 2
    The filesystem on /dev/mapper/myvolg-myvol is now 2621440 (4k) blocks long.
  3. Verify the increased space on the file system.

    df -h /myvol

    The size of the file system is now 9.8G (Size) with 9.3G available (Avail).

Backup VG Metadata

Logical Volume Manager (LVM) metadata contains configuration details about the volume groups. Oracle Linux automatically creates metadata backups after every volume group and logical volume configuration change.

  1. List backups and archives.

    sudo ls -l /etc/lvm/backup
    sudo ls -l /etc/lvm/archive
  2. Display the backup contents.

    sudo head -n 10 /etc/lvm/backup/myvolg

    The description states the system creates the backup after executing the lvextend command.

  3. Manually create a metadata backup.

    sudo vgcfgbackup myvolg

    Include the -f option along with a full path and file name (/var/tmp/myvolg-meta.bkp) to back up the metadata to a different location.

See the vgcfgbackup(8) and vgcfgrestore(8) manual pages for more information.

Grow the VG and LV

Add a disk or partition to the Volume Group and resize the Logical Volume.

Add Another Disk to a VG

  1. Extend the VG by using the remaining available disk /dev/sdd.

     sudo vgextend -v myvolg /dev/sdd

    Example Output:

    [oracle@ol-node01 ~]$ sudo vgextend -v myvolg /dev/sdd
      Wiping signatures on new PV /dev/sdd.
      Set up physical volume for "/dev/sdd" with 104857600 available sectors.
      Zeroing start of device /dev/sdd.
      Writing physical volume data to disk "/dev/sdd".
      Physical volume "/dev/sdd" successfully created.
      Archiving volume group "myvolg" metadata (seqno 3).
      Adding physical volume '/dev/sdd' to volume group 'myvolg'
      Volume group "myvolg" will be extended by 1 new physical volumes
      Creating volume group backup "/etc/lvm/backup/myvolg" (seqno 4).
      Volume group "myvolg" successfully extended
  2. Verify the Volume Group.

    sudo vgs myvolg

    Example Output:

    [oracle@ol-node01 ~]$ sudo vgs myvolg
      VG     #PV #LV #SN Attr   VSize    VFree   
      myvolg   3   1   0 wz--n- <149.99g <139.99g

    Notice the increased PV count (#PV), capacity (VSize), and free space (VFree).

Resize the LV

  1. Increase the size of the logical volume and the file system by 20G.

    sudo lvresize -L +20G -r myvolg/myvol

    Where:

    • -r: Resizes the underlying file system together with the logical volume using fsadm(8).
    • -L: Changes or sets the logical volume size. The + adds to the actual logical volume size.
  2. Verify the increased space on the file system.

    df -h /myvol

Next Steps

You should now be able to use the Oracle Linux Logical Volume Manager utilities to create, mount, and increase the capacity of logical volumes. Check out our other content on the Oracle Linux Training Station.

SSR