38

I am attempting to install Ubuntu on a box which was previously running Windows 7.

I have also experienced the dreaded "Unable to install GRUB" error.

I am not attempting to dual boot. I have previously run a Windows boot disk and removed all existing partitions.

If I run the Ubuntu 12.04 install CD and click install after the config screens, I get the error Executing 'grub-install /dev/sda' failed. This is a fatal error.
(It is the same error as this question: Unable to install GRUB)

All the questions I've read while looking for a solution are related to dual boot. I'm not interested in dual boot, I'm after a clean out the box Ubuntu install. How can I achieve this?

(For my sanity, please use very simple instructions when responding. I don't claim to have any talent either for linux or as a sysadmin)


Additional details copied from comments dated: 2012-05-29 ~15:19Z

After booting from the CD, clicking Try Ubuntu, and then sudo fdisk /dev/sda I get
fdisk: unable to seek on /dev/sda: Invalid argument

sudo fdisk /dev/sdb gives

Device contains neither a valid DOS partiion table, nor Sun, SGI or OSF disklabel. 
Building a new DOS disklabel with disk identifier 0x15228d1d. 
Changes will remain in memory only until you decide to write them. 
After that of course, the previous content won't be recoverable. 
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite). 
Command (m for help):

I should add the Live CD desktop is graphically bad. I've got missing parts of programs and the terminal occasionally reflects to the bottom of the screen. But I can't imagine this is related.

Liath
  • 483
  • What is the error that you are receiving? – harisibrahimkv May 29 '12 at 13:08
  • @harisibrahimkv "Executing 'grub-install/dev/sda' This is a fatal error - the same error as in http://askubuntu.com/questions/62051/unable-to-install-grub however mine is not a dual boot and I am using the detail partitions – Liath May 29 '12 at 13:13
  • You may be experiencing this bug https://bugs.launchpad.net/ubuntu/+source/grub-installer/+bug/976027 – Obsidian Jackal Jun 05 '12 at 17:16
  • I am also facing similar problem when using first option on installation disk where it says, it will manage partition and isstall etc. It says, it is a fatal error. When I choose manual (last option) then it works correctly. I partitioned my harddisk using partition tool and then used CD by selecting manual selection. That way problem won't come. – Satya Prakash Jan 03 '13 at 07:10
  • Please see this link. I had the same trouble you did and solved it. http://superuser.com/questions/1101648/grub2-failed-to-install-into-target/1103187#1103187 I really hope this helps. –  Jul 25 '16 at 19:43
  • I had the same issue when I tried ti install Ubuntu 17.04 on VirtualBox. I solved it by recreating the whole VM again with a new virtual harddisk. – Eng.Fouad May 21 '17 at 04:56

5 Answers5

13

I had the same issue.

Solved it by first clicking on the 'Try Ubuntu' button and then on the 'Install Ubuntu' desktop shortcut.

devav2
  • 36,312
11

I think it might have messed up your hard disk name. Do try reinstalling GRUB.

  1. Boot using a live CD of Ubuntu.

  2. Open a terminal and run the command

    sudo fdisk -l
    

    It lists the complete partition table of the hard disk. In there, identify which partition you have got your linux installed on. You can identify it using the drive size you had allocated for it and looking at the last column of the output which will be ‘extended’ for all of your linux partitions. The partition will most probably be something like /dev/sda5 or something. Remember this partition.

  3. Create a temporary folder in your home directory (Note: You can make the temporary folder anywhere you want. I’m using the home folder just for the sake of explanation). I’m calling it ‘temp’ for now. So that ‘temp’ folder’s path will be /home/ubuntu/temp.

  4. Mount your linux partition there. That is, assuming that you found your linux partition to be /dev/sda5, you mount that at the ‘temp’ folder by doing the following command

    sudo mount /dev/sda5 /home/ubuntu/temp
    
  5. If you want to check whether you have mounted the correct partition, go to your home folder and open temp. You will be in the / directory. In there you will find ‘home’, in which your home folder’s name will be there. Once you’ve confirmed you have mounted the correct partition, do step 6.

  6. You have to install grub by showing the system where to read the data from the hard disk at the beginning. Don’t worry, just run the following command

    sudo grub-install --root-directory=/home/ubuntu/temp /dev/sda
    

    The /dev/sda corresponds to your hard disk name. Replace it by whatever the command sudo fdisk -l command showed you.

  7. You’re done. You may restart your system.

jokerdino
  • 41,320
harisibrahimkv
  • 7,256
  • 11
  • 44
  • 71
  • Thanks for your help so far! I've booted from the CD and clicked "Try Ubuntu", then when doing the fdisk I get "fdisk: unable to seek on /dev/sda: Invalid argument" – Liath May 29 '12 at 13:31
  • 1
    Try "sudo fdisk /dev/sda" or "sudo fdisk /dev/sdb". Also, did you have any external USB devices plugged in to your system while installing your Ubuntu? – harisibrahimkv May 29 '12 at 13:35
  • /dev/sda gives the same as above (unable to seek), /dev/sdb gives "Device contains neither a valid DOS partiion table, nor Sun, SGI or OSF disklabel. Building a new DOS disklabel with disk identifier 0x15228d1d. Changes will remain in memory only until you decide to write them. After that of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite). Command (m for help):" – Liath May 29 '12 at 14:07
  • I should add the trial is graphically bad, I've got missing parts of programs and the terminal occasionally reflects to the bottom of the screen... can't imagine this is related though. – Liath May 29 '12 at 14:08
  • 1
    I think I'm running out of options here. Do you have Gparted in your try-ubuntu? Then launch it and see what it says about your hard disk. – harisibrahimkv May 29 '12 at 14:50
  • I can't see it - I suspect this one may go down to my old hardware, my inexperience and new versions! Thanks for all your help! – Liath May 29 '12 at 15:19
  • @harisibrahimkv There appear to be some technical errors in your answer. The install partition will not be an extended partition if Ubuntu is the only OS installed. Also, the current version of grub-install does not use the --root-directory option. It has been replaced by --boot-directory. See section 19 of the Grub user manual. – irrational John May 31 '12 at 04:52
  • @harisibrahimkv I would suggest mounting the root directory of the Ubuntu install partition as a sub-directory of /mnt rather than /home/ubuntu. This makes it clearer that the directory refers to a mounted file system and that it is not part of the LiveCDs file system. – irrational John May 31 '12 at 04:58
  • The fdisk command can list only MBR and not GPT partitions. – Babbzzz Sep 23 '15 at 17:50
  • Try using the manual partitioning option of the installer and choose the grub installation per the suggestion in this answer. – stanga Nov 16 '16 at 17:18
3

My understanding from your comments to @harisibrahimkv are that when you run the command sudo fdisk /dev/sda in a terminal window, you get the message fdisk: unable to seek on /dev/sda: Invalid argument. I would not expect to see this and it makes me wonder if there is a problem with your computer's hard drive.

Would you please post more information about your hardware? You could do this by booting into Try Ubuntu with your install CD and then adding the output from the two commands below to your question.

sudo lshw -short
sudo lshw -class disk -class storage

Note:
You can select text in a terminal window using either the left mouse button or by pressing Alt+E while the terminal window is active and using the Select All entry in the terminal's Edit menu.

After selecting the text either the keyboard shortcut ShiftCtrl+C or the Copy entry in the terminal window's Edit menu will copy to the clipboard.

You can then add this to your question by using the LiveCD's Firefox browser to edit it and then pasting the command output into the question's edit window in the browser.

screenshot from FAQ showing edit link

Please do not use comments to add the output from the commands. Comments are not intended to be used that way.

If you are experiencing problems with graphics, then I suggest you first verify that your install media (CD) is OK. You can do this by running the Check disc for defects menu option from the Ubuntu CD Advanced Welcome Page Options.

To display this menu, press any key after booting your install CD and while the Ubuntu "small logo" Ubuntu Live CD/USB 'small logo' is displayed at the bottom of your screen.

If your install CD is valid, and therefore not the source of the graphics errors you are seeing, then you might want to try installing using the Ubuntu alternate install CD. The alternate install CD is not a "LiveCD". It performs a text based install which avoids potential problems with graphics drivers. It also contains some hardware drivers which are missing from the standard LiveCD.

You can get the alternate install CD ISO image from the Ubuntu 12.04 LTS releases page. If your hardware is old then you probably want to use the 32-bit version, ubuntu-12.04-alternate-i386.iso

  • I'd also be inclined to check the md5sum of the download you created the cd from - in fact I always check the hash - https://help.ubuntu.com/community/HowToMD5SUM and https://help.ubuntu.com/community/UbuntuHashes – 23 93 26 35 19 57 3 89 May 31 '12 at 06:45
  • @forestpiskie I tend to suggest running Check disc for defects first both because the validity of the install media is what matters most and it is easier in that it only involves making a menu selection, not running another tool. But, yes, if the install media is bad, then the ISO image needs to be checked to determine if the problem was from an error creating the CD or from a bad ISO. – irrational John May 31 '12 at 06:58
  • @forestpiskie FWIW, the entire Check the CD section in the HowToMD5SUM help article strikes me as tedious and pointless. I can't imagine why anyone would want to use the approach outlined there rather than simply using Check disc for defects. It should probably be moved and just linked to. – irrational John May 31 '12 at 07:07
2

I had this same problem earlier today when trying to clean install from a USB drive. I burned the ISO to a disc and did a clean install from there and it worked fine. I know that doesn't really solve the problem but it might prove to be a quick fix if that's all you're after.

enthe0s
  • 33
1

This may sound silly but if you had an mdadm array the partitions may have gotten messed up. Because of mdadm arrays running your partition table will be empty despite the install succeeding (the kernel itself knows the partitions but grub does not understand what to do naturally).

I know this because I broke to the shell and chrooted into /target and ran grub-install and it mentioned something about a missing disk (an fdisk -l /dev/sda showed an empty partition table!).

Reinstalling or recreating a correct partition table will allow the grub-install /dev/sda to succeed after.