Clone Oracle virtual machine to physical server

Jephe Wu -

Environment: Oracle virtual machine image file .img (shutdown VM to make image), use hda as hard disk only, no any scsi driver in initrd image file. Oracle Enterprise Linux 4.5, grub-0.95- rpm which is the latest in OL4.9
Objective: Clone it to a dell PowerEdge 1950 (megaraid scsi driver)


1.  boot from RIP CD(Recovery Is Possible) non-X version, 64bit kernel

login as root without password

vi /etc/hosts.deny to comment out the last line to allow remote ssh

vi /etc/ssh/sshd_config to allow direct root login

dhcpcd eth0 or use ifconfig to manually set up ip address


passwd root

2. transfer System.img which is Oracle VM image file over somewhere on the network which you can mount it

# file System.img

# mkdir iso

# mount System.img iso -o offset=$((512*63))

=========some examples for using offset to mount Oracle VM system image.

[root@oravmdr01 xen]# file dr2.img
dr2.img: x86 boot sector; partition 1: ID=0x83, active, starthead 0, startsector 2048, 208896 sectors; partition 2: ID=0x83, starthead 0, startsector 210944, 24954880 sectors, code offset 0x48

noet: first partition is /boot, the second one is /.

[root@oravmdr01 xen]# mount dr2.img -o offset=$((512*2048)) /tmp/a
[root@oravmdr01 xen]# ls /tmp/a
config-2.6.18-308.  grub                                   initrd-2.6.39-300.17.2.el5uek.img      symvers-2.6.32-300.21.1.el5uek.gz   vmlinuz-2.6.32-300.21.1.el5uek  xen-syms-2.6.18-308.
config-2.6.18-308.   initrd-2.6.18-308.  lost+found                             symvers-2.6.39-300.17.2.el5uek.gz   vmlinuz-2.6.39-300.17.2.el5uek  xen-syms-2.6.18-308.
config-2.6.32-300.21.1.el5uek      initrd-2.6.18-308.   symvers-2.6.18-308.  vmlinuz-2.6.18-308.  xen.gz-2.6.18-308.
config-2.6.39-300.17.2.el5uek      initrd-2.6.32-300.21.1.el5uek.img      symvers-2.6.18-308.   vmlinuz-2.6.18-308.   xen.gz-2.6.18-308.
[root@oravmdr01 xen]# umount /tmp/a

[root@oravmdr01 xen]# mount dr2.img -o offset=$((512*210944)) /tmp/a
[root@oravmdr01 xen]# ls /tmp/a
bin  boot  dev  etc  home  lib  lib64  lost+found  media  misc  mnt  net  opt  proc  root  sbin  selinux  srv  stage  sys  tftpboot  tmp  u01  usr  var

3. transfer file system over physical machine

make partition for the physical server hard disk - sda(2x72G raid1)
fdisk /dev/sda
cd /mnt
mkdir sda
mount /dev/sda1 sda
cd sda
ssh remoteserver 'cd /path/to/iso; tar cvpf - . | tar xvpf -'

4. generate mkinitrd and modify some configuration


vi /etc/modprobe.conf

alias scsi_hostadapter megaraid_sas
alias scsi_hostadapter1 ata_piix

cd /boot

mkinitrd -f /boot/ 2.6.9xxxxsmp (check folder name under /lib/modules)

vi /boot/grub/grub.conf to modify accordingly to use above generated


cd /mnt/sda
chroot .
modify /etc/sysconfig/network-scritps/ifcfg-eth0 and ifcfg-eth1 if necessary
modify /etc/sysconfig/network
modify /etc/fstab
modify /etc/grub.conf
cp /etc/blkid /etc/blkid.bak
rm -f /etc/blkid/*
cp /etc/mtab /etc/mtab.bak
vi /etc/mtab (to correct the / and /boot line to have the correct partition name)
vi /boot/grub/ to something like '(hd0)  /dev/sda'
cd /dev

After that, create root, sys and proc directory for cloned virtual server.

cd /mnt/sda
mkdir proc sys root

5. generate MBR

(install it again everytime you modify file /etc/grub.conf)

# grub-install hd0

Or after reboot, at grub prompt:\

root (hd0,0)  -> hd0 means the first hard disk, 0 means /boot directory is sitting on the first partition, if /dev/sda3 is /boot partition, this should be 'root (hd0,2)'

find /grub/stage1
find /grub/stage2
setup (hd0)


Note: if you cannot use grub-install to install MBR for grub boot loader, you can use RIP CD to boot GRUB from cdrom or usb option to boot the OS on the first hard disk.

then you can fix it from actual os itself.

title Oracle Linux Server (2.6.32-100.26.2.el5uek)
    root (hd0,0)
    kernel /vmlinuz-2.6.32-100.26.2.el5 ro root=/dev/sda3
    initrd /initrd-2.6.32-100.26.2.el5.img 

a. splashimage=(hd0,0)/grub/splash.xpm.gz
means /boot partition is the first partition on first hard disk hd0, it's /grub, not /boot/grub
b. kernel /vmlinuz-2.6.32-100.26.2.el5 ro root=/dev/sda3
means /vmlinuz-2.6.32-100.26.2.el5, not /boot/vmlinuz-2.6.32-100.26.2.el5 since it's already specified root (hd0,0)
c. initrd /initrd-2.6.32-100.26.2.el5.img
means /initrd-2.6.32-100.26.2.el5.img, not /boot/initrd-2.6.32-100.26.2.el5.img if /boot is a separated partition

6. case study

/boot is not separated partition, after clone, it becomes seperated one, you need to change grub configuration as follows:

previous: (no /boot partition, only / one partition)
title Oracle Linux Server (2.6.32-100.26.2.el5)
        root (hd0,0)
        kernel /boot/vmlinuz-2.6.32-100.26.2.el5 ro root=LABEL=/
        initrd /boot/initrd-2.6.32-100.26.2.el5.img

after: (/boot is at /dev/sda3)
title Oracle Linux Server (2.6.32-100.26.2.el5)
        root (hd0,2)
        kernel /vmlinuz-2.6.32-100.26.2.el5 ro root=/dev/sda1
        initrd /

7. possible solution
a. error: /boot/grub/stage1 not read correctly when I tried to install GRUB by grub-install /dev/sdc to the new drive.

Grub consults your /etc/fstab and /etc/mtab files to determine which partition/drive the '/boot' directory is actually on, so check those files are correct. (See the next section for more details about this.)

solution 1: to create a separated /boot partition after boot from RIP CD boot loader, then modify /etc/grub.conf and install grub again:

grub-install /dev/sda


find /boot/grub/stage1
root (hd0,0)
find /boot/grub/stage1
setup hd0

solution 2:
Problem might be that the old legacy GRUB can not handle GPT partition tables. You can simply fix this with the tool gptsync:

gptsync /dev/sdc ( not tested)