Procedure to convert a real LVM-based RHEL4 linux machine, into a non-LVM-based
virtual machine.
Why go through all this trouble? When the other easier methods fail, you can do it this way.
In my case, all the 'automated' methods failed. It is probably the same root error that caused clonezilla to fail in its clone copy.
build46:
A real IBM machine running RHEL4 with a single (300GB) hard drive partitioned as follows:
/sda1 -> /boot (set as bootable partition) 0.1 GB
/sda2 -> LVM Inode size = 128 299.9 GB
/dev/VolGroup00/LogVol00 -> <swap> 6 GB
/dev/VolGroup00/LogVol01 -> /
/dev/VolGroup00/LogVol02 -> /home
/dev/VolGroup00/LogVol03 -> /tmp
/dev/VolGroup00/LogVol04 -> /usr
/dev/VolGroup00/LogVol05 -> /var
/dev/VolGroup00/LogVol06 -> /usr/local
/dev/VolGroup00/LogVol07 -> /opt
Important Notes:
The Linux kernel on this machine is 2.6.9-5 and grub 0.97
The Clonezilla Live CD I used to clone this image has a newer linux kernel than 2.6.9.
For this Live CD, the default inode size for fdisk is 256. However, grub <= 0.97 cannot
handle boot ext3 file systems with inode size > 128. As my goal is that the new image's
partition hold the entire filesystem (including boot/), I must take care to set the
target filesystem inode size to 128.
The IBM machine has an IBM ServeRaid controller which requires the ips.ko SCSI module
in the initrd image, however the target VM will require the LSI Logic SCSI module
in order to boot. The target initrd image must be modified accordingly in order to
get the system to boot. This is the error I would get:
-----------------------------------------------------------------
Booting 'Red Hat Enterprise Linux ES (2.6.9-5.ELsmp)'
root (hd0,1)
Filesystem type is ext2fs, partition type 0x83
kernel /boot/vmlinuz-2.6.9-5.ELsmp ro root=/dev/sda2 rhgb quiet
[Linux-bzImage, setup=0x1400, size=0x15492c]
initrd /boot/intird-2.6.9-5.ELsmp.img
[Linux-initrd @ 0x1fe69000, 0x76143 bytes]
Uncompressing Linux... Ok, booting the kernel.
audit(1388300047.913:0): initialized
Red Hat nash version 4.1.18 starting
insmod: error inserting '/lib/ips.ko': -1 No such device
ERROR: /bin/insmod exited abnormally!
mount: error 6 mounting ext3
mount: error 2 mounting none
switchroot: mount failed: 22
umount /initrd/dev/failed: 2
Kernel panic - not syncing: Attempted to kill init!
-----------------------------------------------------------------
The above error message means the init script failed to load the ips.ko module
where it was looking for the IBM serveraid SCSI controller (no such device).
Subsequently, all mounts failed and the system could not boot.
I will use a backup copy of the disk image so I can remove any dependency on the old h/w.
=======
0. Make note of your original LVM setup as shown initially
1. Back up original HD image
Note: Original (real) build46 machine was bootable, but clonezilla failed to
clone it using the default 'simple' mode due to some h/w (byte-copy) error.
Since I didn't understand the CZ Advanced mode, I decided to instead go with
something I understood: ddrescue. Since the original system was actually bootable,
I figured a full byte-byte copy, minus any failed bits would be as close to the
original as I could come. It would be a much slower process, but would be a
more-or-less exact copy. (Turned out to be true)
My strategy:
Boot real system with CZ. Use ddrescue for copy (which ignores copy errors).
Save to a disk image file on an SSH server.
a. Boot original machine with clonezilla, and open a cmd line shell.
(I had a DHCP server on my network, so I ended up with an IP automatically)
b. Set up the destination copy (my SSH server had IP 10.0.4.1 and an id e-build)
mkdir /mnt/build46.0
sshfs e-build@10.0.4.1:/pub/1/VM_Images1/build46.bak/ /mnt/build46.0/
vgchange -a n # shut down any LVM devices
cd /mnt/build46.0/
ddrescue /dev/sda sda.img sda.log
c. Wait for the copy to end. On my 1 GB eth network, this copy took about 14 hrs.
d. Power off
2. Restore sda backup copy into a VM image.
a. Create a new virtual machine with these basic components to match my h/w
4096 RAM
2 CPU
300 GB SCSI drive (dynamically allocated)
1 ETH
b. Boot VM with clonezilla, and open a cmd line shell.
(I had a DHCP server on my network, so I ended up with an IP automatically)
c. Restore the backup image into the VM disk (/dev/sda):
mkdir /mnt/build46.0
sshfs e-build@10.0.4.1:/pub/1/VM_Images1/build46.bak/ /mnt/build46.0/
cd /mnt/build46.0/
ddrescue --force sda.img /dev/sda sda2.log
d. Wait for the copy to end. On my 1 GB eth network, this copy took about 14 hrs.
e. Power off
3. Copy LVM disk data into non-LVM disk
a. Add a 2nd SCSI 300 GB drive to the VM (sdb)
b. Boot VM with clonezilla, and open a cmd line shell.
(I had a DHCP server on my network, so I ended up with an IP automatically)
c. Using fdisk, configure new virtual disk with 2 partitions. (sdb)
sdb1: swap (6G)
sdb2: ext3 (294G) (set bootable)
d. Format sdb2 using inode size of 128 (needed by grub 0.97)
mkfs.ext3 -I 128 /dev/sdb2
e. Prepare LVM source data
mkdir /mnt/build46.0
mount /dev/VolGroup00/LogVol01 /mnt/build46.0
cd /mnt/build46.0
mount -t proc proc proc
mount -t sysfs sys sys
mount -o bind /dev dev
mount /dev/VolGroup00/LogVol02 home
mount /dev/VolGroup00/LogVol03 tmp
mount /dev/VolGroup00/LogVol04 usr
mount /dev/VolGroup00/LogVol05 var
mount /dev/VolGroup00/LogVol06 usr/local
mount /dev/VolGroup00/LogVol07 opt
mount /dev/sda1 boot
f. Prepare destination
mkdir /mnt/build46
mount /dev/sdb2 /mnt/build46
g. Copy data from old to new disk
cd /mnt/build46
mkdir {proc,sys,dev}
chmod -w proc
chmod go+w dev
chmod +t dev
chmod a-w sys
for d in $(ls -1 /mnt/build46.0 | grep -v '\(dev\|proc\|lost\|sys\)'); do
cp -v -ax /mnt/build46.0/$d $d/
done
h. Wait for the copy to end. This took about 12 hrs for me.
i. Power off the VM
4. Repair the boot issue due to the difference in SCSI controller
a. Remove the backup disk from the list of VM devices. (sdb will now become sda)
b. Boot the VM with clonezilla and open a cmdline prompt.
d. Mount non-bootable disk (now is sole VM disk, sda)
mkdir /mnt/build46
mount /dev/sda2 /mnt/build46
cd /mnt/build46
mount -t proc proc proc
mount -t sysfs sys sys
mount -o bind /dev dev
chroot /mnt/build46
e. edit fstab
cd /etc
cp fstab fstab.0
vi fstab
--------------------------------------------------------------------------------------
FROM:
# This file is edited by fstab-sync - see 'man fstab-sync' for details
/dev/VolGroupt/LogVol01 / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
none /dev/pts devpts gid-5,mode=620 0 0
none /dev/shm tmpfs defaults 0 0
/dev/VolGroup00/LogVol02 /home ext3 defaults 1 2
/dev/VolGroup00/LogVol07 /opt ext3 defaults 1 2
none /proc proc defaults 0 0
none /sys sysfs defaults 0 0
/dev/VolGroup00/LogVol03 /tmp ext3 defaults 1 2
/dev/VolGroup00/LogVol04 /usr ext3 defaults 1 2
/dev/VolGroup00/LogVol06 /usr/local ext3 defaults 1 2
/dev/VolGroup00/LogVol05 /var ext3 defaults 1 2
/dev/VolGroup00/LogVol00 swap swap defaults 0 0
/dev/hda /media/cdrom auto pamconsole,exec,noauto,managed 0 0
/dev/fd0 /media/floppy auto pamconsole,exec,noauto,managed 0 0
TO:
# This file is edited by fstab-sync - see 'man fstab-sync' for details
/dev/sda2 / ext3 defaults 1 1
/dev/sda1 swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
/dev/hdc /media/cdrecorder auto pamconsole,exec,noauto,managed 0 0
/dev/fd0 /media/floppy auto pamconsole,exec,noauto,managed 0 0
--------------------------------------------------------------------------------------
f. edit mtab
cd /etc
cp mtab mtab.0
vi mtab
--------------------------------------------------------------------------------------
FROM:
/dev/mapper/VolGroup00-LogVol01 / ext3 rw 0 0
none /proc proc rw 0 0
TO:
/dev/sda2 / ext3 rw 0 0
none /proc proc rw 0 0
--------------------------------------------------------------------------------------
g. edit modprobe.conf
cd /etc
cp modprobe.conf modprobe.conf.0
vi modprobe.conf
--------------------------------------------------------------------------------------
FROM:
:
alias scsi_hostadapter ips
:
TO:
:
alias scsi_hostadapter mptscsih
:
--------------------------------------------------------------------------------------
h. edit grub.conf, menu.lst
cd /boot/grub
mv grub.conf grub.conf.0
ln -s menu.lst grub.conf
vi menu.lst
--------------------------------------------------------------------------------------
FROM:
:
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux ES (2.6.9-5.ELsmp)
root (hd0,0)
kernel /vmlinuz-2.6.9-5.ELsmp ro root=/dev/VolGroup00/LogVol01 rhgb quiet
initrd /initrd-2.6.9-5.ELsmp.img
:
TO:
default=0
timeout=5
#splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux ES (2.6.9-5.ELsmp)
root (hd0,1)
kernel /boot/vmlinuz-2.6.9-5.ELsmp ro root=/dev/sda2 rhgb quiet
initrd /boot/initrd-2.6.9-5.ELsmp.img
:
--------------------------------------------------------------------------------------
i. rebuild initrd
cd /boot
mkinitrd -f -v initrd-2.6.9-5.ELsmp 2.6.9-5.ELsmp
j. add new MBR
grub
grub> root (hd0,1)
grub> setup (hd0)
grub> quit
k. activate swap partition
mkswap /dev/sda1
l. reboot
5. After reboot, follow the kudzu prompts to reconfigure your system devices