I have a virtual box running with CentOS, I am attaching new disk to existing centos VM and trying to install grub on this newly attached virtual disk. Later I will bring-up a second VM with newly prepared bootable hard-disk with custom root file-system and kernel.I have tried following steps,Attached a new virtual disk to existing working centos machine.Created a new partition with fdisk /dev/sdb. While portioning, given the options primary partition,partition number 1 and other options default.Formatted the disk with mkfs.ext3 /dev/sdb1.Mounted the disk to /media/new_drive.Installed grub grub-install /dev/sdb1 --root-directory=/media/new_drive/.After this the second VM with newly prepared hard disk didn't come-up with error could not read from the boot medium ie MBR is not updated after grub-install, but I can see grub installed under /boot/grub in new drive.But the worst thing is, it has corrupted my existing CentOS grub, CentOS VM hangs with black screen with only text GRUB.Why grub-install /dev/sdb1 is not modifying MBR of sdb1? Is this not the right way to install grub on new drive?
How to install grub on a new drive?
linux;virtualbox;grub legacy
I'm not a grub2 expert (sorry) but try adding --skip-fs-probe to your grub-install line, I have found this prevents creation of /boot/grub/device.map which can cause booting to a grub prompt. I think that without this parameter grub-install, instead of doing what you tell it, thinks it is cleverer than you, and may do something different.Another thing is to be sure you are using the right grub-install (i.e. for grub2 and not for original grub). This isn't a problem if you are inside Centos but with SystemRecoveryCD both versions are available and so you have to use grub2-install. I learned the hard way...And as @wurtel pointed out (kudos), you should specify a drive not a partition. Grub2 installs in sector 0 of the whole disk drive, and this 'stub' is what runs at boot time, but it needs to know whereabouts on the disk it should install the files for the next stage of booting - this is what the --root-directory parameter is for. (I think.)Reading man grub-install and googling I see that --root-directory is not really meant to be used for grub2 versions 1.99++, though it does work in my experience. You are meant to use --boot-directory and refer to the actual boot directory, so this would give you:grub-install /dev/sdb --skip-fs-probe --boot-directory=/media/new_drive/boot