Using the Linux Logical Volume Manager (LVM) to Manage Free Disk Space

This section shows you how to use the Linux Logical Volume Manager (LVM) to Manage Free Disk Space.

The following procedures demonstrate how to extend the /u01 disk file system. An LVM command summary is also provided.

Prerequisite

  • An understanding of Linux system administration.
  • Appropriate sudo permissions at the Linux file system level.
  • Appropriate access and authority to the Oracle Cloud Infrastructure environment.

Using the Linux Logical Volume Manager (LVM) to Manage Free Disk Space

The following procedures demonstrate how to extend the /u01 disk file system by:

  • Recreating the partition table to include the free space
  • Resizing the physical volume
  • Extending the physical volume to the existing logical volume

Recreating the Partition Table

To make the free disk usable, you must recreate the partition table. This is done using the fdisk command as illustrated in the following procedure.

To recreate the a partition table:

  1. Log into the instance as the opc user and switch to the root user using this command:

    sudo -i

  2. Review available disk space in /u01 prior to adding the new disk space by running this command:

    df -h /u01

    Example:

     df -h /u01
     Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_jde00-lv_jde00
     6.9G          3.0G 3.7G 45%        /u01
  3. Run these commands to show unallocated space:

    parted /dev/xvdb

    print free

    quit

    Example:

    parted /dev/xvdb

    GNU Parted 2.1

    Using /dev/xvdb

    Welcome to GNU Parted! Type 'help' to view a list of commands. (

    parted) print free

    Number Start End Size Type File system Flags

    32.3kB 1049kB 1016kB Free Space

    1 1049kB 538MB 537MB primary ext3 boot

    2 538MB 20.7GB 20.2GB primary lvm

    3 20.7GB 28.2GB 7509MB primary lvm

    28.2GB 39.7GB 11.5GB Free Space

    (parted) quit

  4. To modify the partition table, run fdisk on the disk device. For example, in the example used in this guide is xvdb. fdisk /dev/xvdb

  5. Next, at the prompts from the fdisk command, enter the following command letters to delete the current partition number 3, and recreate primary partition #3 with all the remaining free sectors:

    d
    3
    n
    p
    3
    <enter>
    <enter>
    w

    Example:

    fdisk /dev/xvdb

    Warning: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u').

    Command (m for help): d

    Partition number (1-4): 3

    Command (m for help): n

    Command action

    e extended

    p primary partition (1-4)

    p

    Partition number (1-4): 3

    First cylinder (2520-4830, default 2520):

    Using default value 2520

    Last cylinder, +cylinders or +size{K,M,G} (2520-4830, default 4830):

    Using default value 4830

    Command (m for help): w

    The partition table has been altered!

    Calling ioctl() to re-read partition table.

    Warning: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.
  6. This process extended the /dev/xvdb partition to include all of the free space. This new disk will be added to the /u01 logical volume.The system now needs to be rebooted before the partition table change will be recognized by the system. Use the reboot command to reboot now. Continue with the next section after rebooting.

Resizing the Physical Volume with the Partition Table Changes

After you resize the partition table as described in the previous procedure, the disk image is now ready to become a physical volume that can be added to a logical volume.

To resize the physical volume with the new partition space:

  1. After the system finishes rebooting, log back into the instance as the opc user and switch to the roof user using this command: sudo -i
  2. Execute the pvresizecommand as shown below:

    pvresize /dev/xvdb3

    Example:

    pvresize /dev/xvdb3

    Physical volume "/dev/xvdb3" changed<

    1 physical volume(s) resized / 0 physical volume(s) not resized

    See Also

    For more information refer to the Linux man pages for the pvresize command.

Extending the Volume Group with the New Physical Disk

To extend the volume group with the new physical disk:

  1. You must determine the name of the volume group to which the disk will be added by using the vgs and lvscan commands. In the below example, the name of the volume group with free space is vg_jde00, and it is located in this directory: /dev/mapper/vg_jde00-lv_jde00

    Example:

    vgs

    VG #PV #LV #SN Attr VSize VFree

    vg_apol 1 7 0 wz--n- 18.78g 32.00m

    vg_jde00 1 1 0 wz--n- 17.70g 10.71g

    The vgs command shows the 10.71g of free space is in volume group vg_jde00

    Example:

    lvscan

    ACTIVE '/dev/vg_jde00/lv_jde00' [6.99 GiB] inherit

    ACTIVE '/dev/vg_apol/lv_root' [4.00 GiB] inherit

    ACTIVE '/dev/vg_apol/lv_home' [1.00 GiB] inherit

    ACTIVE '/dev/vg_apol/lv_tmp' [6.00 GiB] inherit

    ACTIVE '/dev/vg_apol/lv_var' [1.50 GiB] inherit

    ACTIVE '/dev/vg_apol/lv_var.log' [2.00 GiB] inherit

    ACTIVE '/dev/vg_apol/lv_var.log.audit' [256.00 MiB] inherit

    ACTIVE '/dev/vg_apol/lv_swap' [4.00 GiB] inherit

    The lvscan shows that volume group vg_jde00 has one logical volume named lv_jde00. This is where the free disk space will be put in this example. Take the volume group name (vg_jde00) and the logical volume name (lv_jde00) and confirm the location of the logical volume in the /dev/mapper directory.

    Example:

    ls /dev/mapper/vg_jde00-lv_jde00

    /dev/mapper/vg_jde00-lv_jde00

  2. Using the volume group name found in the previous step, extend the volume group by using the lvextend command. The below example uses /dev/mapper/vg_jde00-lv_jde00.

    lvextend --resizefs -l +100%FREE /dev/mapper/vg_jde00-lv_jde00

    Example:

    lvextend --resizefs -l +100%FREE /dev/mapper/vg_jde00-lv_jde00

    Size of logical volume vg_jde00/lv_jde00 changed from 6.99 GiB (1790 extents) to 17.70 GiB (4531 extents).

    Logical volume lv_jde00 successfully resized

    resize2fs 1.43-WIP (20-Jun-2013)

    Filesystem at /dev/mapper/vg_jde00-lv_jde00 is mounted on /u01; on-line resizing required

    old_desc_blocks = 1, new_desc_blocks = 2

    Performing an on-line resize of /dev/mapper/vg_jde00-lv_jde00 to 4639744 (4k) blocks.

    The filesystem on /dev/mapper/vg_jde00-lv_jde00 is now 4639744 blocks long.

  3. Confirm the space is now available for use by running this command:

    df -h /u01

    Example:

    df -h /u01

    Filesystem Size Used Avail Use% Mounted on

    /dev/mapper/vg_jde00-lv_jde00

    18G 3.0G 14G 18% /u01

    See Also

    For more information refer to the Linux man pages for the lvextend command.

Logical Volume Manager Command Summary

This section provides a summary of the Logical Volume Manager commands used in the previous steps of this tutorial.

[fdisk]

This is the disk utility command.

To resize the number 3 primary partition, use this syntax where subsequent values are entered at the command prompts:

 fdisk /dev/xvdb
 d
 3
 n
 p
 3
 <enter>
 <enter>
 w

[pvresize]

Use this utility to resize a disk or partition for use by LVM. For example:

pvresize /dev/xvdb3

[vgscan]

Use this command to scan all disks for volume groups and rebuild caches (returns names).

[vgextend]

Use this utility to resize a disk or partition for use by LVM. For example:

vgextend VolGroup00 /dev/hdc1

[lvextend]

Use this command to extend the size of a logical volume. For example:

vlvextend --resizefs -l +100%FREE /dev/mapper/vg_jde00-lv_jde00