How can I fix/install/reinstall grub?

69,364

So, it sounds like you have not installed a boot loader (e.g. grub) on the disk. This means that although you have a valid OS on it, there is no way to boot it and so you can't use it.

You need to attach the HDD to a working computer (you can use a live CD), set up a chroot environment and install grub on it.

  1. Mount the partition you will be using as / (I will call the drive /dev/sdb and the / partition sdb1, the names may be different on your system, you will need to use the correct ones) somewhere :

    sudo mount /dev/sdb1 /mnt/foo
    
  2. Bind the directories that grub needs to have access to

    sudo mount --bind /dev /mnt/foo/dev && 
    sudo mount --bind /dev/pts /mnt/foo/dev/pts && 
    sudo mount --bind /proc /mnt/foo/proc && 
    sudo mount --bind /sys /mnt/foo/sys
    
  3. Set up the chroot environment

    sudo chroot /mnt/foo
    
  4. Create grub's configuration file:

    sudo grub-mkconfig -o /boot/grub/grub.cfg
    

    If you have multiple operating systems installed, make sure that the command above lists all of them. For example:

    $ sudo grub-mkconfig -o /boot/grub/grub.cfg
    Generating grub.cfg ...
    Found background image: /usr/share/images/desktop-base/desktop-grub.png
    Found linux image: /boot/vmlinuz-3.10-2-amd64
    Found initrd image: /boot/initrd.img-3.10-2-amd64
    Found linux image: /boot/vmlinuz-3.2.0-4-amd64
    Found initrd image: /boot/initrd.img-3.2.0-4-amd64
    Found linux image: /boot/vmlinuz-3.2.0-3-amd64
    Found initrd image: /boot/initrd.img-3.2.0-3-amd64
    Found linux image: /boot/vmlinuz-3.2.0-2-amd64
    Found initrd image: /boot/initrd.img-3.2.0-2-amd64
    Found memtest86+ image: /boot/memtest86+.bin
    Found memtest86+ multiboot image: /boot/memtest86+_multiboot.bin
    Found Windows 7 (loader) on /dev/sda2
    done
    
  5. Now install grub to the MBR of your drive (remember to change /dev/sdb to whichever drive you actually want to install it on)

    grub-install /dev/sdb
    grub-install --recheck /dev/sdb
    
  6. Exit the chroot and unmount everything so your running system is back to normal:

    exit
    sudo umount /mnt/foo/dev/pts /mnt/foo/dev /mnt/foo/proc /mnt/foo/sys /mnt/foo
    
  7. Try booting from the drive, you should have a grub menu this time.

Share:
69,364

Related videos on Youtube

the.keV.nc
Author by

the.keV.nc

Updated on September 18, 2022

Comments

  • the.keV.nc
    the.keV.nc over 1 year

    So I started out with a 250GB HDD, the stock drive from an EeePC 1015pem that I am trying to turn into a MintBook. The drive is physically operable, but all data has been nuked, including the old OS. Given this, I attached the HDD to my desktop and installed Linux Mint 16 Xfce from a live USB created through Unetbootin-585. Set aside 10GB for swap and 240GB for ext4 and /.

    The drive now refuses to boot for either the desktop or netbook. Both motherboards are sounding the correct sequence of beeps, so they seem healthy, and I can successfully access the BIOS on both systems. However, the only thing that comes up after starting the computer is a nonresponsive command-line. There is no error message, no grub or grub-rescue, nothing.

    Is there anything I can try besides reformatting and starting over? How would I go about installing a boot loader that can boot my OS?

    • terdon
      terdon over 10 years
      Why are you installing on the desktop? Why not install directly on the target netbook? 10 GB for swap!? 240 for Ext4 and / ? Have you installed grub on the drive's MBR? Are you using UEFI? Could you show us the partitioning scheme you set up?
    • the.keV.nc
      the.keV.nc over 10 years
      In order: >Why are you installing on the desktop? Why not install directly on the target netbook? I installed from the desktop because the netbook is having a glitchy reaction to the live USB. I can boot the desktop from the USB, but when I try to boot the netbook it shows a rapidly blinking Mint logo for ~45min before shutting down. >10 GB for swap!? I saw no good reason not too; I have no urgent need for that space. > 240 for Ext4 and / ? ... Is that somehow bad? Every source I found said "Use Ext4" and the installer demanded / for the partition.
    • terdon
      terdon over 10 years
      OK, fair enough (though this might be due to having used unetbootin, I've had similar issues and it worked with USBs created with MultiSystem also see this thread. Could you also answer my other questions? Are you using UEFI? Have you installed grub on the drive and if so, where?
    • the.keV.nc
      the.keV.nc over 10 years
      > Have you installed grub on the drive's MBR? No, I have not. I thought the installer edited the MBR on its own. > Are you using UEFI? Not to my knowledge. Should I? > Could you show us the partitioning scheme you set up? Give me a second.
    • Alen Milakovic
      Alen Milakovic over 10 years
      Personally I'd try harder for a direct installation on the laptop. Installing one something else is just adding an extra layer of complexity imo. Try something different from a live USB install. I don't know anything about @terdon's suggestions, but I'd try them.
    • the.keV.nc
      the.keV.nc over 10 years
      @FaheemMitha Unfortunately, that isn't possible at the moment. In other words, terdon's suggestion worked but the HDD is now giving me the same reaction as the live boot. In other words, blinky logo and nothing else. If you want to help me solve this, I've posted a follow up question.
  • the.keV.nc
    the.keV.nc over 10 years
    On your earlier suggestion, I did exactly that by following the instructions on nooblab.com. And it worked! On my desktop, I can boot into Mint from the newly created grub. Unfortunately, that hasn't solved the netbook issue, so watch for the follow-up post.
  • terdon
    terdon over 10 years
    @the.keV.nc what do you mean my earlier suggestion? You used something other than unetbootin? If you followed the procedure in my answer to solve your issue, please mark it as accepted so that others can see that it is the right solution.
  • the.keV.nc
    the.keV.nc over 10 years
    I mean you asked if I had grub installed. It appears I didn't, so I followed the instructions here to reinstall from the live boot of Mint. It worked and I can now access Mint 16 by attaching the HDD to my desktop. However, it still won't work on my netbook, hence the follow-up. (And thanks for mentioning about marking it accepted.)
  • Graeme
    Graeme about 10 years
    From the update-grub man page - update-grub is a stub for running grub-mkconfig -o /boot/grub/grub.cfg. So no need to do grub-mkconfig and update-grub. I think after grub-install is the correct time (if it makes any difference), so you basically don't need step 4 (although you can probably just shift the output to step 5 since it will be the same).
  • Admin
    Admin about 10 years
    Nr 4 is also called update-grub
  • terdon
    terdon about 10 years
    @bersch what is Nr 4? In any case, is it needed there or is update-grub just calling grub-mkconfig there also? On Debian update-grub is literally a shell script running set -x; grub-mkconfig -o /boot/grub/menu.cfg.
  • ericn
    ericn over 8 years
    Hi @terdon, how am I supposed what to use for step 1? I'm using Fedora 23 and df -h gives me ` devtmpfs 3.9G 0 3.9G 0% /dev tmpfs 3.9G 176K 3.9G 1% /dev/shm tmpfs 3.9G 1.7M 3.9G 1% /run tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup /dev/sdb1 15G 4.7G 9.9G 33% /run/initramfs/live /dev/mapper/live-rw 5.8G 3.8G 2.0G 66% / ...`
  • terdon
    terdon about 8 years
    @eric I'm sorry, for some reason I only just saw your comment. You would need to use /dev/sdb1 just like in my example since that's the partition that is mounted at / in your case. I know this is almost certainly too later but it might help for next time.