Extend Disk Space in Oracle VM
1. Oracle provides templates of Linux Enterprise (OEL5), but the free disk space is very small (around 10G).
Enterprise Linux Release 5 Update 4 Media Pack for x86 (32 bit)
2. If you want to extend the system to install more software, the free disk space is not enough. Here are the steps to enlarge the free disk space of the guest OVM.
[root@oslcn33 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/xvda2 4079492 2057376 1980108 51% /
/dev/xvda1 93307 11635 76855 14% /boot
tmpfs 2097240 0 2097240 0% /dev/shm
a) In the host server, run dd command to create img file to allocate extra disk space.
Allocate 150G free disk space to expand.img.
[root@oslcn30 OVM_EL5U4_X86_PVM_4GB]# dd if=/dev/zero bs=1G count=150 >> /OVS/seed_pool/OVM_EL5U4_X86_PVM_4GB/expand.img
150+0 records in
150+0 records out
161061273600 bytes (161 GB) copied, 1957.43 seconds, 82.3 MB/s
b) Shutdown guest VM
[root@oslcn30 OVM_EL5U4_X86_PVM_4GB]# xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 569 2 r----- 1455.3
OVM_EL5U4_X86_PVM_4GB 11 4096 2 -b---- 20.9
[root@oslcn30 OVM_EL5U4_X86_PVM_4GB]# xm shutdown OVM_EL5U4_X86_PVM_4GB
c) Change vm.cfg
add ,'file:/OVS/seed_pool/OVM_EL5U4_X86_PVM_4GB/expand.img,xvdb,w' to disk line
[root@oslcn30 OVM_EL5U4_X86_PVM_4GB]# vi vm.cfg
bootloader = '/usr/bin/pygrub'
disk = ['file:/OVS/seed_pool/OVM_EL5U4_X86_PVM_4GB/System.img,xvda,w', 'file:/OVS/seed_pool/OVM_EL5U4_X86_PVM_4GB/expand.img,xvdb,w']
memory = '4096'
name = 'OVM_EL5U4_X86_PVM_4GB'
vcpus = 2
on_crash = 'restart'
on_reboot = 'restart'
vfb = ['type=vnc,vncunused=1,vnclisten=0.0.0.0']
vif = ['']
d) Re-create guest VM
[root@oslcn30 OVM_EL5U4_X86_PVM_4GB]# xm create vm.cfg
Using config file "./vm.cfg".
Started domain OVM_EL5U4_X86_PVM_4GB (id=11)
e) Using VNC to login the guest VM and Use fdisk to create new partition
[root@oslcn33 software]# fdisk /dev/xvdb
The number of cylinders for this disk is set to 19581.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Use ‘t’ to change the system id: 8e --this is LVM type
Use ‘n’ to create new partition
Use ‘w’ to write and exit
f) Using the LVM to make the new partition available to current system.
# pvcreate /dev/xvdb --create physical volume
# pvcreate /dev/xvdb1 -- use the disk partition
# vgcreate extvg /dev/xvdb1 –create volume group
# vgchange -a y extvg --active the volume group
# vgdisplay extvg | grep "Total PE" –check volume group size.
Total PE 38399
# lvcreate -l 38399 extvg -n extlv –create logic volume with the max size.
Create file system on logic volume.
# mke2fs /dev/extvg/extlv
or reiserfs:
# mkreiserfs /dev/extvg/extlv
g) Mount the new partition to current file sysem.
[root@oslcn33 ~]# mount /dev/extvg/extlv /u01
h) Check result:
[root@oslcn33 software]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/xvda2 4079492 2058508 1978976 51% /
/dev/xvda1 93307 11635 76855 14% /boot
tmpfs 2097240 0 2097240 0% /dev/shm
/dev/mapper/extvg-extlv
154814444 60872 146889460 1% /u01
i) auto mount on startup:
[root@oslcn33 ~]# vi /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
/dev/extvg/extlv /u01 ext2 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-VM swap swap defaults 0 0