This discussion is archived
2 Replies Latest reply: Mar 6, 2013 7:56 PM by Clancy RSS

Cannot install grub on a second disk in a PVM

Terry Phelps Newbie
Currently Being Moderated
I'm trying to build a bootable disk, from within a PVM, as some research into how I might recreate a VM from just file backups. That doesn't sound like a difficult thing to try to do, but I can't get grub to install onto the second disk. I don't know much about grub, yet, but I've been fooling with it for a few hours now, and Googling hasn't helped much.

Details:
I started from an OEL 6 template. Just to test feasiibility of making a bootable disk, here's what I did:
Added a second disk (/dev/xvdb) to the VM.
Partitioned it to match xvda, and marked partition 1 as bootable.
Made filesystems to match /boot and /.
Ran mkswap on the 3rd partition.
Copied all the files from /boot and / on xvda to the corresponding partitions on xvdb.

At this point, I think I'm about done, except for installing grub on it. After some research, I tried this:

# grub-install /dev/xvdb
/dev/xvdb does not have any corresponding BIOS drive.

I checked /boot/grub/device.map. It says:

# this device map was generated by anaconda
(hd0) /dev/xvda

I tried adding this line to device.map:
(hd1) /dev/xvdb

Then I got anothre error:

# grub-install /dev/xvdb
expr: non-numeric argument
expr: non-numeric argument
The file /boot/grub/stage1 not read correctly.

I tried simple things, like this:

# grub
Probing devices to guess BIOS drives. This may take a long time.
grub> root (hd0,0)
root (hd0,0)

Error 21÷: Selected disk does not exist

Am I making some silly mistake? What do I need to do to make this second disk bootable?
  • 1. Re: Cannot install grub on a second disk in a PVM
    Terry Phelps Newbie
    Currently Being Moderated
    I got no replies, but I have found that there seems to be no need to install grub on the disk at all! Xen's magic just makes it work.

    Summary of my first email: I was trying to make a duplicate of an Oracle VM virtual machine's primary disk, by simply creating an empty disk, partitioning it, formatting it, and copying files to it. After all that's done, in a "real" situation, you have to (as best I know) install grub on the disk (MBR or partition) so the BIOS can boot it. I was trying to do that, and couldn't make it work.

    It turns out that there is no need to do that, at least in the case of PVM machines, because there's no simulated BIOS that has to boot the disk. The booting of the kernel in the VM is done by a program called "pygrub" that runs on the Oracle VM server itself. Pygrub is a part of Xen, apparently. Pygrub simply locates the grub.conf file within the virtual disk, reads it, and initiates the boot of the proper kernel with the proper options. As long as grub.conf is right, the VM will boot.

    SO, to create a bootable copy of a virtual machines primary disk, you just need to:
    1. Create a disk of an appropriate size.
    2. Create partitions and format them. This includes the swap partition.
    3. Copy files from the original disk to the new one.
    4. Edit /etc/fstab and /boot/grub/grub.conf on the new disk, and change the partition UUIDs to be those for the partitions you created in step 2.

    Then you can detach the virtual disk from the machine on which you made it, create a new machine, attach the disk to it, and it boots!

    I welcome any (intelligent) comments on the above.
  • 2. Re: Cannot install grub on a second disk in a PVM
    Clancy Newbie
    Currently Being Moderated
    Very, very, very useful post Terry, Thanks!

    I've been facing the same situation restore some linux vm's from commvault filesystem backups.

    I wonder how long it would have taken me to "just try it anyway" without actually successfully installing grub.

    In this case, the problem on existed in my head. Or at least the problem was my ignorance of the XEN boot magic !

    Thanks again

    Clancy

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points