How to install GRUB on a new drive?

Renjith

I have a virtual box running with CentOS.

I have attached a new virtual disk to the existing CentOS VM and I'm now trying to install GRUB on this newly attached disk.

Later, I will bring up a second VM with a newly prepared bootable hard disk with a custom root filesystem and kernel.

I have tried the following steps:

  • Attached a new virtual disk to the existing working CentOS machine.
  • Created a new partition with fdisk /dev/sdb. While partitioning, I chose the options primary partition, partition number 1 and other default options.
  • 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 the newly prepared hard disk didn't boot; I got the error: could not read from the boot medium. It seems the MBR is not updated after grub-install, but I can see GRUB installed under /boot/grub on the new drive.

But the worst thing is, it has corrupted my existing CentOS GRUB: The CentOS VM hangs showing a black screen with the only text being GRUB.

Why does grub-install /dev/sdb1 not modify the MBR of sdb1? Is this not the right way to install GRUB on new drive?

gogoud

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

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to install Grub in an external hard drive?

분류에서Dev

How to install new system drive while keeping old one available

분류에서Dev

How to install GRUB with dualboot in Legacy mode?

분류에서Dev

chmod hard drive at grub?

분류에서Dev

How to install a "new" command into bash?

분류에서Dev

Why can't (and how can) I install both grub-pc and grub-efi packages?

분류에서Dev

Manually install GRUB

분류에서Dev

How to add a GRUB2 menu entry for booting installed Ubuntu on a USB drive?

분류에서Dev

How to add a GRUB2 menu entry for booting installed Ubuntu on a USB drive?

분류에서Dev

How do I reset hard drive in order to install Windows 8.1?

분류에서Dev

How to install FreeBSD 10 from USB Hard drive?

분류에서Dev

Windows setup unable to install windows 10 on new hard drive - total size 0 - free space 0

분류에서Dev

How to recovery the data inside my hard drive? New to Ubuntu

분류에서Dev

How to install any new software on ubuntu 12.04

분류에서Dev

grub entry for slackware from another drive

분류에서Dev

Ubuntu minimal cd installs GRUB to USB drive

분류에서Dev

Ubuntu Install crashes after Grub

분류에서Dev

Unable to install GRUB in /dev/nvme

분류에서Dev

GRUB2 failed to install

분류에서Dev

grub-install : 오류 : EFI 디렉토리를 찾을 수 없습니다. (Grub Boot Loader Windows 10 / Kali Linux Dual Boot with Dual Hard Drive 재설치)

분류에서Dev

How to install grub2 on second disk and using EFI on first disk

분류에서Dev

Drive won't boot from its Grub, but will from another drive's Grub, after cloning, why?

분류에서Dev

Mirror Hard Drive To New Hard Drive

분류에서Dev

Install on usb external hard drive

분류에서Dev

How can I install Ubuntu on an old MacBook without a CD or USB drive?

분류에서Dev

How do I install Windows on an encrypted drive when I've forgotten the password?

분류에서Dev

How do i install Windows 7 on separate hdd and ubuntu on a separate drive?

분류에서Dev

How do i install Windows 7 on separate hdd and ubuntu on a separate drive?

분류에서Dev

How many times can I use a bootable usb flash drive to install Ubuntu

Related 관련 기사

  1. 1

    How to install Grub in an external hard drive?

  2. 2

    How to install new system drive while keeping old one available

  3. 3

    How to install GRUB with dualboot in Legacy mode?

  4. 4

    chmod hard drive at grub?

  5. 5

    How to install a "new" command into bash?

  6. 6

    Why can't (and how can) I install both grub-pc and grub-efi packages?

  7. 7

    Manually install GRUB

  8. 8

    How to add a GRUB2 menu entry for booting installed Ubuntu on a USB drive?

  9. 9

    How to add a GRUB2 menu entry for booting installed Ubuntu on a USB drive?

  10. 10

    How do I reset hard drive in order to install Windows 8.1?

  11. 11

    How to install FreeBSD 10 from USB Hard drive?

  12. 12

    Windows setup unable to install windows 10 on new hard drive - total size 0 - free space 0

  13. 13

    How to recovery the data inside my hard drive? New to Ubuntu

  14. 14

    How to install any new software on ubuntu 12.04

  15. 15

    grub entry for slackware from another drive

  16. 16

    Ubuntu minimal cd installs GRUB to USB drive

  17. 17

    Ubuntu Install crashes after Grub

  18. 18

    Unable to install GRUB in /dev/nvme

  19. 19

    GRUB2 failed to install

  20. 20

    grub-install : 오류 : EFI 디렉토리를 찾을 수 없습니다. (Grub Boot Loader Windows 10 / Kali Linux Dual Boot with Dual Hard Drive 재설치)

  21. 21

    How to install grub2 on second disk and using EFI on first disk

  22. 22

    Drive won't boot from its Grub, but will from another drive's Grub, after cloning, why?

  23. 23

    Mirror Hard Drive To New Hard Drive

  24. 24

    Install on usb external hard drive

  25. 25

    How can I install Ubuntu on an old MacBook without a CD or USB drive?

  26. 26

    How do I install Windows on an encrypted drive when I've forgotten the password?

  27. 27

    How do i install Windows 7 on separate hdd and ubuntu on a separate drive?

  28. 28

    How do i install Windows 7 on separate hdd and ubuntu on a separate drive?

  29. 29

    How many times can I use a bootable usb flash drive to install Ubuntu

뜨겁다태그

보관