In today’s Oracle VM Manager there is no way of extending the disk size of a guest VM. However, via this tutorial I will show you how to extend the .img file.

PLEASE NOTE: It is highly recommended to make a backup of the disktoExtend.img file prior to trying the steps below.

Let us assume we have an Oracle VM guest which contains 3 files. The three files are the following: System.img, disktoExtend.img, and vm.cfg. Our guest VM is running RHEL/OEL.

[root@OVMSERVER]# ll
total 22000640
-rw-r--r-- 1 root root 26847313920 Oct 13 10:28 disktoExtend.img
-rw-r--r-- 1 root root 11630545920 Oct 13 09:57 System.img
-rw-rw-rw- 1 root root 459 Oct 13 10:27 vm.cfg


1) In order to grow the the disktoExtend.img file, we must first ensure that the guest VM is offline.
2) Next, we will make a backup of our disktoExtend.img file using the cp command as shown below:
cp /OVS/running_pool/disktoExtend.img /OVS/running_pool/disktoExtend.img.bkup
3) Now that we have made a backup, we will append zeros to the end of the disktoExtend.img to enlarge it. We do this by using the dd command. Please make sure to notice the “>>”. The “>>” is how to append to a file. The command to do this is
“dd if=/dev/zero bs=1M count=<SIZE_IN_MB> >> ./disktoExtend.img”. The count is the size in megabytes on how much to enlarge the .img file. In my particular example, my disktoExtend.img was 25GB and I wanted to extend it by 5GB for a total of 30GB, hence 5120MB was used.

[root@OVMSERVER]# dd if=/dev/zero bs=1M count=5120 >> ./disktoExtend.img
5120+0 records in
5120+0 records out
5368709120 bytes (5.4 GB) copied, 23.4454 seconds, 229 MB/s

[root@OVMSERVER]# ll
total 29279872
-rw-r--r-- 1 root root 32216023040 Oct 13 15:55 disktoExtend.img
-rw-r--r-- 1 root root 11630545920 Oct 13 14:19 System.img
-rw-r--r-- 1 root root 499 Oct 13 16:53 vm.cfg

Once we have extended the disktoExtend.img file at the OVM Server level, we will need to resize the existing filesystem for that image.
In this example my disktoExtend.img was mounted on my guest VM as /u01 using the /dev/xvdb1 partition.

1) Log into the guest VM
2) Within the /etc/fstab, comment out the line that mounts the ‘/u01’ partition.
3) Reboot the system
4) Now that we have rebooted the system, you will notice that /u01 partition is not mounted. We will now need to delete the existing partition and create a new partition that will use up all the available space on /dev/xvdb.
NOTE: For simplicity, my example only contains 1 partition on /dev/xvdb that will expand across the entire disk.
5) fdisk /dev/xvdb
We will then use the option ‘d’ to delete the partition. (NOTE: Deleting the partition will not cause you to lose any of your DATA.)
Now with the partition deleted, we will create a new partition that spans across the entire disk using the ‘n’ option. When creating a new partition ensure you use a primary partition followed by the partition number, in this case partition number 1.
Once we have created the new partition we will use the ‘w’ command to write our changes and exit out of fdisk.
6) With the expansion of the partition from 25GB to 30GB, we must now extend the filesystem.
First we are required to do a file system check using the command:
e2fsck –f /dev/xvdb1

Once the scan has completed successfully, we will resize the file system using:
resize2fs /dev/xvdb1

7) We can now go to the /etc/fstab and uncomment out the /u01 partition.
8 ) Lastly, we can now remount our /u01 partition as follows:
mount /dev/xvdb1 /u01

Congratulations! We have successfully expanded our disk size and partition. However, the Oracle VM Manager will still show the old values for IMG_SIZE and VD_SIZE. We must update these values via the Oracle VM Manager Repository.

1) Login the Oracle VM Manager as “oracle” user
2) Set the environment to login to the Oracle VM Manager repo database
export ORACLE_SID=XE
export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
export PATH=$ORACLE_HOME/bin:$PATH

3) Next we will login into sqlplus as the “ovs” user using:
sqlplus ovs/oracle
4) SQL> set pages 80;
5) We now must find the IMG_ID and IMG_SIZE of our existing VM from the OVS_VM_IMG table using the following SQL query:
SQL> select * from OVS_VM_IMG where IMG_NAME=<VM_NAME>;

---------------------------------------------------------------------------
IMG_IP
--------------------
UUID
--------------------------------------------------------------------------------
512 <----- IMG_ID

36696 <---- IMG_SIZE
Running
Xen Auto 512 78
13-OCT-10 08.59.27.834165 AM
1 -1 78
13-OCT-10 03.35.00.332181 PM

dacb2506-8c5c-4ded-93fe-19f7a85018fd

The IMG_SIZE 36696MB listed above is calculated by:
Total IMG_SIZE = Size of System.img (in bytes) + ORIGINAL Size of disktoExtend.img (in bytes)
Once you have the total size in bytes, convert bytes to megabytes for an accurate IMG_SIZE and round up to the nearest integer.

We must now set the IMG_SIZE to the new value by using the formula:
Total IMG_SIZE = Size of System.img (in bytes) + UPDATED Size of disktoExtend.img (in bytes)
Once you have the total size in bytes, convert bytes to megabytes for an accurate IMG_SIZE and round up to the nearest integer.

SQL> update OVS_VM_IMG set IMG_SIZE='41816' where IMG_ID='512';
SQL> commit;

6) Next we must update the VD_ID and the VD_SIZE using our IMG_ID of our VM from the OVS_VD_IMG table as follows:
SQL> select * from OVS_VD_IMG where IMG_ID='512';

ID VD_ID IMG_ID
---------- ---------- ----------
STATUS
--------------------------------------------------------------------------------
Q PRIORITY FRONT HARD_DRIVER DISK_SEQUENCE DISK_MODE
- ---------- -------------------- -------------------- ------------- ----------
514 424 <--- this is the VD_ID of our disktoExtend.img 512
Attached
N xvdb auto

513 423 512
Attached
N xvda auto

7) Once we know the VD_ID, in this example it is 424, we will search for the virtual disk data using:
SQL> select * from OVS_VIRTUAL_DISK where VD_ID='424';

VD_ID
----------
VD_NAME
--------------------------------------------------------------------------------
VD_SIZE
--------------------------------------------------------------------------------
SHARABLE SITE_ID GROUP_ID USER_ID VD_TYPE
-------------------- ---------- ---------- ---------- --------------------
STATUS
--------------------------------------------------------------------------------
COMMENTS
--------------------------------------------------------------------------------
VIRTUAL_DEVICE_TYPE
--------------------
DEVICE_NAME
--------------------------------------------------------------------------------
DEVICE_SIZE
-----------
DEVICE_UUID
--------------------------------------------------------------------------------
424 <--- VD_ID
disktoExtend
25604 <----- VD_SIZE
Non-Sharable Xen
Active

File

8 ) Notice how the size 25604MB is my disktoExtend.img original size which was 25GB. I want to now change this to its updated size of 36696MB.
NOTE:I got this number by converting the size of disktoExtend.img in bytes to megabytes and rounded to the nearest integer. The size in bytes can be found within the OVM Server.
We will now set the correct VD_SIZE within the OVS_VIRTUAL_DISK table
SQL> update OVS_VIRTUAL_DISK set VD_SIZE='36696' where VD_ID='424';
SQL> commit;

Congratulations! We have now succesfully updated the disk size within the OVM Manager.

Advertisements