I get asked this question all the time… “Can you please add 20 G to/u01 for me?” Many DBAs and Middleware admins are nervous about making changes to their Linux systems, especially if they do not understand how changes effect their systems. I always encourage folks to ask for help if there are any concerns, and try to teach them how to help themselves in the future, especially with the more simple tasks, like growing file systems.
Growing file systems is easy, IF the file systems is under logical volume manager (LVM) control. Many of the Oracle Engineered Systems (ES), like the ODA use LVM for the OS disk, giving the admin a ton of flexibility to grow any file system as needed. As a note, just watch how much free space the volume group has, as on most ES you can not grow that.
You can tell if the file system is under LVM control, if you see the device like a /dev/sdaX, /dev/mdX or /dev/xvdaX then you are likely using physical partitions. If you see something like /dev/mapper/X your likely under LVM/
Here is an example using physical partitions, growing this is not easy, and requires downtime if it is even possible.
And here is an example using the LVM, which is easy to grow on the fly;
There are 3 concepts that are important to understand with the LVM, and the relationship between the three objects and the file systems using the LVM;
- Volume Groups – A Volume Group is a group of physical and logical volumes. Most systems have one Volume Group that contain all of the physical and logical volumes on the system. In this example the Volume Group is vg_ol6
- Physical Volumes – Physical Volumes correspond to disks; they are block devices that provide the space to store logical volumes. In this example a new physical volume will be added, called /dev/xvdb1
- Logical Volumes – Logical Volumes correspond to partitions: they hold a file system or ASM device. Unlike partitions though, logical volumes get names rather than numbers, they can span across multiple disks, and do not have to be physically contiguous. In the following example, the /u01 file system resides in the lv_u01 volume.
One additional WARNING, if you have no free space in the volume and file sytem you will be unable to grow it.
First, lets look at the file system we want to grow, in this case /u01. Using the command “df –h /u01” , lets check what space is being used at what volume the file system is using.
The file system is using the volume lv_u01 in the volume group vg_ol6. So this is what we will grown.
Next, lets check how much free space is in the volume group, using the command “vgs”
The group has 22.66G of free space. While that accommodates the request to add 20G to /u01, it doesn’t leave much free space. So let’s go ahead and add space to the volume group first. First, a new disk will be added to the VM, this is done using a process specific to your hypervisor or physical SAN. In this case, I am running on Oracle VM and added a new 300G disk. I happen to know the new disk will be /dev/xvdb, as /devxvda was the only other disk, but if you look in the /var/lof/messages file you will see the new disk added;
Next, I will use the “fdisk /dev/xvdb” command to add a partition on the disk’. While partitions are not required, but I like adding them as a warning sign to other admins that this disk is being used, DO NOT TOUVH IT!
After the partition is created, let’s change the type to LVM, using the “t” option if fdisk, and save the configuration to the disk using “w”. the configuration does not actually write to the disk and refresh the kernel until “w” is used.
Next, we will initialize the partition, using pvcreate /dev/xvdb1. This writes metadata data to the device, like block size and label header.
The command pvs will now show this disk, along with the disk already in use /dev/xvda2.
Next we will extend the vg_ol6 volume group with the new disk, using the command “vgextend vg_ol6 /dev/xvdb1”
Now, grow the volume by 30G using the command “lvextend -L +30G /dev/mapper/vg_ol6-lv_u01”. If we exclude the “+” option, instead of growing the volume by 30G, it will set the volume to 30G in size.
After and then resize the filesystem using the command resize2fs /dev/mapper/vg_ol6-lv_u01
All done, with the file system now at 50G, and an additional 292G ready to add to another file system in the volume group.
If you have any request on how to do things, please drop me a note by clicking on the “Contact Me/ Ask a Question” section in the title bar.
Pingback: How to grow a file system with Oracle Linux 6, Vision R12.2.8, using Antsle antlet from vbox appliance. – Roseltek Inc.
Thanks for the reference when you wrote up your version.
Erik