-8

Due to "Meltdown" I am in the progress of moving our CentOS7-XEN-PV-DomUs to HVM mode. See here on why I need to migrate to HVM

This involves installing a bootloader - unnessesary on PV-DomUs, since they use pygrub to emulate the grub/grub2 boot process.

What works: Boot the HVM DomU via PXE into a rescue CentOS7 image, chroot the disks, grub2-install. I can not do this from the Dom0 - since that is SLES11 SP4 - with grub, not grub2.

I would like to automate this by just copying the grub2-sectors via dd from an alredy converted VM to a VM which still needs the step.

Question: How big is grub2 - so how many bytes do I have to copy?

I already found out that 62 sectors with sector-size 512 byte is not enough.

Update 2018-01-22: The first answer hinted a potential problem.

In my scenario you will have a uniform disk-layout with identical first partition, starting at about 9 MiB. On that partition /boot is located.

I could do what I wanted by:

sfdisk -d ALREADYCONVERTEDDISK >oldpart.sfdisk
dd if=VM-DISK-WITH-GRUB2 of=NEWDISK bs=1M count=8
sfdisk ALREADYCONVERTEDDISK <oldpart.sfdisk

The the question boils down to: What would be the minimal space needed for grub2?

Nils
  • 7,657
  • 3
  • 31
  • 71

1 Answers1

3

You cannot copy GRUB2 that way.

The first part of the GRUB code is located in the boot sector which may also contain metadata about your disk (either partition table or file system metadata).

Since these early stages of boot have to operate with a very limited amount of space available to the code they cannot contain a file system driver. So instead it uses an embedded list of sectors to load.

This means the copied sectors have to be in the exact same location on the destination disk and that location might be in use. And even if the location isn't in use the file system will think those sectors are still unused and will eventually overwrite your boot sectors.

You can copy GRUB2 by copying an entire disk image including partition tables up to and including the entire /boot partition. But in doing so you are effectively going to delete what was on the destination disk.

If you want to install GRUB2 on a disk without deleting everything else that was on the disk, you need to use the real installer.

kasperd
  • 29,894
  • 16
  • 72
  • 122
  • Let us assume that the first Partition of the clone has exactly the same position and contains /boot – Nils Jan 21 '18 at 17:38
  • [Look here](http://www.gnu.org/software/grub/manual/grub/grub.html#BIOS-installation) to make a perfect answer. You already got 75%. – Nils Jan 23 '18 at 14:56
  • 1
    According to the page (xen-orchestra.com) you linked, installing grub needs to be done before migrating. So use your software deployment method of choice (ansible, puppet, chef, etc.) to install grub2 before migrating. Kasperd's answer is correct. – Jeter-work Jan 23 '18 at 17:58
  • @Xalorous I do not use Citrix XEN, I use SLES11SP4. The link provided shows how to solve this with Citrix XEN. Not feasible for SLES. – Nils Jan 25 '18 at 10:30
  • **core.img** is the part that contains enough intelligence to find /boot and read ext3/4. This is located before the first partition - so how big is it and where exactly is it located? – Nils Jan 28 '18 at 22:21
  • See my answer at [this question](https://serverfault.com/questions/896687/find-out-exact-location-of-grub-grub-not-working-after-copying-disk-image/). – telcoM Feb 11 '18 at 14:59