On Fri, Sep 25, 2009 at 4:59 PM, Zhang Li <cindy.zhangli@xxxxxxxxx> wrote:
> Hi, all
>
> I am trying to convert an linux machine to an image. I use the
> following way to convert it:
>
> 1. resize2fs /dev/sda3 4G
> 2. dd if=/dev/sda3 of=./rhel_hvm.img bs=512 count=8M
> 3. The image file has no MBR, then I add the mbr and partition.
> I use `parted rhel_hvm.img` command,
>
> 1) mklabel msdos
> 2) mkpart primary ext3 0kB 4G (only one partition)
>
> the mbr and the partition is created.
>
> But the problem is that kernel can't be loaded when grub is running.
I'm surprised you even got it to work. The "normal" way to do this:
- create a partition table first.
- dd to that partition, or create file system and copy the data. You
can use kpartx to mount partition inside an image.
When you create a partition you reserve the beginning of the disk (or
the image), usually 1 track worth (63 sectors on most modern disk or
images). You did the opposite, dd a partition to an image (not a
partition on that image) then create a partition table on it. My guess
is you pretty much destroy the file system information. Did you try
mounting the image afterwards?
> Then I boot the guest with another centos image,
> and rhel_hvm.img is used as slave disk /dev/hdb.
> Then I use `grub-install /dev/hdb`, to reinstall the grub, and it is
> successfull.
>
> Then I boot the guest with rhel_hvm.img, but it still fails. Grub is
> stop with the line
> "Booting froom Hard Disk".
>
> Any ideas?
grub-install is somewhat tricky. What you did is install grub on MBR
of the SECOND disk that will load data from your FIRST disk (centos).
Generally not what you want.
Assuming your disk image is correct (i.e. it has the correct partition
table, correct file system, etc.), when installing grub to a second
disk (like when using external USB drive) I had to edit two files
first on current environment (the centos image in your setup):
- /boot/grub/device.map, pointing (hd0) to the new disk (sdb or hdb)
- /etc/mtab, changing partition of "/" (or "/boot") to the new disk
(e.g. from /dev/sda1 to /dev/sdb1)
Then do a grub-install /dev/sdb (or hdb) and it should work. Change
back the files afterwards.
I believe there's a better method to do this (using grub shell and
"setup" command), but if you want to use grub-install then you need
the hack above.
--
Fajar
_______________________________________________
Xen-users mailing list
Xen-users@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-users
|