Jephe Wu - http://linuxtechres.blogspot.com
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-3.8.0.1 rpm which is the latest in OL4.9
Objective: Clone it to a dell PowerEdge 1950 (megaraid scsi driver)
Steps:
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
/usr/sbin/sshd
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.20.1.0.1.el5xen grub initrd-2.6.39-300.17.2.el5uek.img symvers-2.6.32-300.21.1.el5uek.gz System.map-2.6.32-300.21.1.el5uek vmlinuz-2.6.32-300.21.1.el5uek xen-syms-2.6.18-308.20.1.0.1.el5
config-2.6.18-308.4.1.0.1.el5xen initrd-2.6.18-308.20.1.0.1.el5xen.img lost+found symvers-2.6.39-300.17.2.el5uek.gz System.map-2.6.39-300.17.2.el5uek vmlinuz-2.6.39-300.17.2.el5uek xen-syms-2.6.18-308.4.1.0.1.el5
config-2.6.32-300.21.1.el5uek initrd-2.6.18-308.4.1.0.1.el5xen.img symvers-2.6.18-308.20.1.0.1.el5xen.gz System.map-2.6.18-308.20.1.0.1.el5xen vmlinuz-2.6.18-308.20.1.0.1.el5xen xen.gz-2.6.18-308.20.1.0.1.el5
config-2.6.39-300.17.2.el5uek initrd-2.6.32-300.21.1.el5uek.img symvers-2.6.18-308.4.1.0.1.el5xen.gz System.map-2.6.18-308.4.1.0.1.el5xen vmlinuz-2.6.18-308.4.1.0.1.el5xen xen.gz-2.6.18-308.4.1.0.1.el5
[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
initrd:
vi /etc/modprobe.conf
alias scsi_hostadapter megaraid_sas
alias scsi_hostadapter1 ata_piix
cd /boot
mkinitrd -f /boot/initrd.img.new 2.6.9xxxxsmp (check folder name under /lib/modules)
vi /boot/grub/grub.conf to modify accordingly to use above generated initrd.img.new
configurations:
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/device.map to something like '(hd0) /dev/sda'
cd /dev
./MAKEDEV sda
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)
reboot
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.
------
/etc/grub.conf
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
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
note:
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)
#boot=/dev/hda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
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)
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,2)/grub/splash.xpm.gz
hiddenmenu
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 /initrd-2.6.32-100.26.2.el5.img.new
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
or
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)
Clone Oracle virtual machine to physical server
Cloning a physical RHEL 5 server to vmware virtual server
Jephe Wu - http://linuxtechres.blogspot.com
Objective: Cloning a physical RHEL 5 server to vmware virtual server from scratch
Environment: RHEL 5.1 (physical server HP Proliant DL360), CentOS 5.5 (vmware host server)
Steps:
1. Setup the vmware server 2.0 under CentOS 5.5
Please refer to another article at http://linuxtechres.blogspot.com/2010/09/how-to-setup-vmware-server-202-under.html
2. Clone physical RHEL 5.1 to vmware virtual server
a. create a vmware virtual environment, use sda as hard disk and boot it up from system rescue CD iso image
You can download iso file from http://www.sysresccd.org/Main_Page
b. make a tar ball from the original RHEL 5.1 physical server
login as root
cd /
tar --exclude root --exclude sys --exclude proc -cvpzf - . | ssh intermediate_server 'cat > rhel.tar.gz'
c. configure IP address, make partitions and change root password
ifconfig eth0 10.0.0.2 netmask 255.255.255.0 up
passwd root
fdisk /dev/sda (make sda1 as /boot(100M), sda2 as swap(2xRAM size), sda3 as /)
mkfs -t ext3 /dev/sda1
mkfs -t ext3 /dev/sda3
mkswap /dev/sda2
d. start to clone the whole OS
cd /mnt
mkdir sda
mount /dev/sda3 sda
cd sda
mount /dev/sda1 boot
scp root@original_server:/etc/passwd /etc/
scp root@original_server:/etc/group /etc/
note: above scp commands to copy original server /etc/passwd and /etc/group file to the rescue CD environment so that untaring the rhel.tar.gz will keep the correct owner and permission for all files systems later on. Otherwise, you will notice /var/spool/clientmqueue directory will not be owned by smmsp, as well as the group permission for /usr/sbin/sendmail.sendmail, and so on.
logout then login again
cd /mnt/sda
ssh root@intermediate_server 'cat rhel.tar.gz' | tar xvpzf -
or
if on the same LAN,use
tar --exclude root --exclude sys --exclude proc -cvpf - . | ssh intermedia_server 'cd /mnt/sda; tar xpf -'
Note: if you use RIP 12.3 non-X version, vi /etc/hosts.deny to comment out the last line which only permit localhost to ssh into RIP server, also you might need to vi /etc/ssh/sshd_config to enable root login by using password.
e. modify configurations after cloning OS
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/device.map to something like '(hd0) /dev/sda'
cd /dev
./MAKEDEV sda
After that, create root, sys and proc directory for cloned virtual server.
cd /mnt/sda
mkdir proc sys root
f. generating new initrd image and install grub
modify /etc/modprobe.conf to have the correct scsi driver, for vmware using sda hard disk, change that file to the follows:
root@jephe # more /etc/modprobe.conf
alias eth0 pcnet32
#alias scsi_hostadapter mptspi
#alias scsi_hostadapter1 mptfc
#alias scsi_hostadapter2 mptsas
alias scsi_hostadapter3 mptbase
alias scsi_hostadapter4 mptscsih
alias scsi_hostadapter5 ata_piix
alias scsi_hostadapter6 usb-storage
then generate new initrd image based on the above scsi drivers (no need to use --preload options to load scsi modules)
root@jephe # mkinitrd -f /boot/initvm.img kernelnumber
error opening /sys/block: No such file or directory
error opening /sys/block: No such file or directory
Note: ignore above errors.
note: you can use commands below to check new initrd content:
mkdir /tmp/initrd
cd /tmp/initrd;gzip -dc /boot/initrd-2.6.22.1-41.fc7.img | cpio -id
Lastly, install grub: (install it again everytime you modify file /etc/grub.conf)
# grub-install hd0
Or after reboot, at grub prompt:
root (hd0,0)
setup (hd0)
reboot
g. reboot
# rm -f /etc/mtab (already backed up as /etc/mtab.bak at section e)
# reboot
Note: if you encountered issue such as getting grub> prompt only , you need to boot into Windows partition, use command 'chainloader (hd0,0)+1' to boot into Windows
# more /etc/grub.conf
title windows chainloader (hd0,0)+1