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.
Open a terminal on the Luna Desktop.
Clone the
linux-virt-labsGitHub project.git clone https://github.com/oracle-devrel/linux-virt-labs.gitChange into the working directory.
cd linux-virt-labs/olInstall the required collections.
ansible-galaxy collection install -r requirements.ymlDeploy the lab environment.
ansible-playbook create_instance.yml -e localhost_python_interpreter="/usr/bin/python3.6" -e add_block_storage=true -e block_count=3The free lab environment requires the extra variable
local_python_interpreter, which setsansible_python_interpreterfor 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
Open a terminal and connect via SSH to the ol-node-01 instance.
ssh oracle@<ip_address_of_instance>Verify the block volumes exist.
sudo lsblkThe output should show the boot device for the existing file system and several available disks.
Physical Volume (PV)
Create the physical volumes (PV) using the available disks.
sudo pvcreate -v /dev/sd{b,c}Run the command with the
-voption to get verbose information.Verify PV creation.
sudo pvsExample 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.00gFor more detailed PV information, run
pvdisplayorpvscanto scan all disks for physical volumes.
Volume Group (VG)
Create the volume group (VG) using the newly created physical volumes.
sudo vgcreate -v myvolg /dev/sd{b,c}Verify VG creation.
sudo vgsExample 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 0For more detailed VG information, run
vgdisplayor usevgscanto scan all disks for volume groups.
Logical Volume (LV)
Create the linear logical volume (LV).
sudo lvcreate -v -L 5G -n myvol myvolgWhere:
-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.Verify LV creation.
sudo lvdisplay myvolgThe 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:2For condensed VG information, run
lvsor uselvscanto scan all disks for volume groups.Display the LV type.
sudo lvs -o name,segtype /dev/myvolg/myvol- The
lvscommand 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- The
Create a File System
Create an EXT4 file system on the logical volume.
sudo mkfs.ext4 -F /dev/myvolg/myvolWhere:
-F: Forces the overwrite of an existing file system.
Mount the LV
Mount the file system.
sudo mkdir -p /myvol sudo mount /dev/myvolg/myvol /myvolReport the file system disk usage.
df -hExample Output:
[oracle@ol-node01 ~]$ df -h Filesystem Size Used Avail Use% Mounted on ... /dev/mapper/myvolg-myvol 4.9G 20M 4.6G 1% /myvolUpdate the fstab file.
echo "/dev/mapper/myvolg-myvol /myvol ext4 defaults 0 0" | sudo tee -a /etc/fstab > /dev/nullUnmount the LV.
sudo umount /myvolRemount 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.
Check if the VG has free space.
sudo vgsThe
myvolgVG has 95G space free (VFree).Increase the LV capacity.
sudo lvextend -L 10G -r myvolg/myvolWhere:
-r: Resizes the file system together with the logical volume usingfsadm(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.Verify the increased space on the file system.
df -h /myvolThe 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.
List backups and archives.
sudo ls -l /etc/lvm/backup sudo ls -l /etc/lvm/archiveDisplay the backup contents.
sudo head -n 10 /etc/lvm/backup/myvolgThe description states the system creates the backup after executing the
lvextendcommand.Manually create a metadata backup.
sudo vgcfgbackup myvolgInclude the
-foption 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
Extend the VG by using the remaining available disk
/dev/sdd.sudo vgextend -v myvolg /dev/sddExample 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 extendedVerify the Volume Group.
sudo vgs myvolgExample Output:
[oracle@ol-node01 ~]$ sudo vgs myvolg VG #PV #LV #SN Attr VSize VFree myvolg 3 1 0 wz--n- <149.99g <139.99gNotice the increased PV count (#PV), capacity (VSize), and free space (VFree).
Resize the LV
Increase the size of the logical volume and the file system by 20G.
sudo lvresize -L +20G -r myvolg/myvolWhere:
-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.
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.