Thursday, February 3, 2011

Convert Virtulabox disk(.vdi) to Oracle VM (.img)

Below is the step for converting your VirtualBox disk to Oracle Virtual Server Image.


On My Windows OS I have VirtualBox  installed and Guest OS (Ubuntu) running.


Steps:
1) Login to Guest OS on Virtual Box and create a label for filesytem and add it to /etc/fstab.
2) Reboot and check if Guest OS is ok.
3) Shutdown the Guest OS.
4) Go to VirtualBox Installation path on Windows Host OS and run the VBoxManage command to convert from (.vdi) to (.img)




1) Step one Create label on Guest OS for filesystems

a) First i Logged in to Guest OS (Ubuntu) to create a label for my filesystem.
So the file-system is know by label and not by any defined partition.

Check filesystem type

root@sriram-VirtualBox:/home/sriram# df -T
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/sda1     ext4     5903296   2120868   3482552  38% /
none      devtmpfs      248644       224    248420   1% /dev
none         tmpfs      254244       208    254036   1% /dev/shm
none         tmpfs      254244        88    254156   1% /var/run
none         tmpfs      254244         0    254244   0% /var/lock
/dev/sr0   iso9660       36238     36238         0 100% /media/VBOXADDITIONS_4.0.0_69151

b) Create Label:
 root@sriram-VirtualBox:/home/sriram# e2label /dev/sda1 sriram1

c) Verify if Label is created with mount command 
root@sriram-VirtualBox:/home/sriram# mount -l
/dev/sda1 on / type ext4 (rw,errors=remount-ro,commit=0) [sriram1]
proc on /proc type proc (rw,noexec,nosuid,nodev)


d) Edit your /etc/fstab file:

---------------------------------------------
# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' to print the universally unique identifier
# for a device; this may be used with UUID= as a more robust way to name
# devices that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
# / was on /dev/sda1 during installation
#commented below sriram
#UUID=f6fb2bc7-d0f9-4a91-ab2d-1d7be4cb2055 /               ext4    errors=remount-ro 0       1

LABEL=sriram1 /               ext4    errors=remount-ro 0       1


# swap was on /dev/sda5 during installation
UUID=c2583cce-307b-42c4-991c-4be900869b38 none            swap    sw              0       0
---------
#UUID=f6fb2bc7-d0f9-4a91-ab2d-1d7be4cb2055 /               ext4    errors=remount-ro 0       1
-------------------------------------------

e)  Reboot and check if you are good with the guest os (for me things were good)



f) now shut down the Guest OS




Step2 : Go to Virtualbox installed path on Windows (Host OS) and run below command:


For converting .vdi to .img  file :


C:\Program Files\Oracle\VirtualBox>


C:\Program Files\Oracle\VirtualBox>VBoxManage clonehd 
D:\Softwares\ubuntu10.vdi   ovm.img -format raw
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'raw'. UUID: fe02c861-112f-4c29-9a78-c62f93ef5
be2

C:\Program Files\Oracle\VirtualBox>dir
02/03/2011  06:36 PM     6,477,053,952 ovm.img


When i checked both of them are of same size.


vm.cfg would be something like this for Oracle VM :
-------
acpi = 1
apic = 1
bootloader = '/usr/bin/pygrub'
disk = ['file:/vms/sample/DomU-5EL-U5-x86_64-1.0.3.img,hda,w',
'file:/vms/sample/ovm.img ,sdb,w',
#'phy:/dev/mapper/DomUVol-appohs_d2,sdc,w',
'file:/FMW/vms/sample/swap,sdd,w',
'file:/FMW/vms/sample/tmp,sde,w',
]
localtime = 0
memory = 6144
name = 'guest1'
ne2000 = 0
on_crash = 'preserve'
on_poweroff = 'destroy'
on_reboot = 'restart'
on_shutdown = 'shutdown'
pae = 1
sdl = 0
serial = 'pty'
superpages = 1
timer_mode = 2
vcpus = 16
vif = ['ip=192.168.10.10']
vif_other_config = []
vnc = 1
vncunused = 1



Also check this link for more info:

http://blogs.oracle.com/wim/2011/01/converting_an_oracle_vm_virtua.html

1 comment:

  1. Hi, i want to convert exactly the reverse *.img to *.vdi.
    Is this possible?

    ReplyDelete