Oct 182011
 

I’ve finally terminated my upgrade to Xubuntu 11.10, with the usual small problems, nothing really too bad.
But now, when i boot I don’t see anymore the “Windows” entry in the boot menu made with grub2, I’ve installed os-prober that should help in will find additional entries on the hard disks and add them to the menu, but this don’t solved too my problem.

As alternative you could have your windows Entry in place, but when selecting it, you get an error like:

  • you need to load kernel first
  • chainloader: no such command.
  • no such partition
So this is a small guide to restore your Windows entry in your Grub2 system.



Grub2 super short howto

This part comes from the complete tutorial about grub2 from the site Dedoimedo, while i was searching for an help i’ve read his complete how to about grub2 and i really suggest to take the time to read it for a complete overview.

GRUB 2 has three main parts:

  1. /etc/default/grub – the file containing GRUB 2 menu settings.
  2. /etc/grub.d/ – the directory containing GRUB 2 menu creating scripts.
  3. /boot/grub/grub.cfg – the GRUB 2 configuration file, not editable.

update-grub command reads the /etc/grub.d directory and looks for executable scripts inside it. The scripts are read, in the order of their numbering, and written into the grub.cfg file, along with the menu settings read from the /etc/default/grub file.

Boot entries come from several sources – the default that comes with the distribution, other operating systems probed on the connected disks and custom scripts written by the user, following a strict syntax. The scripts are written as shell (sh).

Step 1, know your hard disk

The first thing that you need to know it’s the exact mapping of your hard-disk, for this we’ll use the old but always good fdisk with the option -l, this is my Xubuntu machine harddisk

linuxaria@xubuntu-home:~$ sudo fdisk -l
[sudo] password for linuxaria: 
 
Disk /dev/sda: 40.0 GB, 40007761920 bytes
255 heads, 63 sectors/track, 4864 cylinders, total 78140160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xcccdcccd
 
Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *          63    36817199    18408568+   7  HPFS/NTFS/exFAT
/dev/sda2        36817200    42698879     2940840    c  W95 FAT32 (LBA)
/dev/sda3        42700798    78139391    17719297    5  Extended
/dev/sda5        42700800    43698175      498688   82  Linux swap / Solaris
/dev/sda6        43700224    59322367     7811072   83  Linux
/dev/sda7        59324416    78139391     9407488   83  Linux

So, in short :

/dev/sda1 = Windows
/dev/sda2 = extra partition formatted with fat32
/dev/sda5 = Linux swap
/dev/sda6 = / partition of Xubuntu
/dev/sda7 = /home partition of Xubuntu

My windows partition is /dev/sda1 that on Grub2 is mapped as (hd0.1), note that this is different from grub (not 2) where the first partition of the first disk was (hd0,0)

Step 2 create a custom Grub 2 script

Create the file /etc/grub.d/15_Windows, and add the following lines to it:

 #! /bin/sh -e
echo "Adding Windows" >&2
cat < < EOF
menuentry "Windows" {
set root=(hd0,1)
chainloader +1
}
EOF

And now make this script executable with the command:

chmod +x /etc/grub.d/15_Windows

Step 3 update grub 2 configuration file

Now, we must tell to grub 2 to recreate his config file, to do it execute, as root, the command update-grub2

root@xubuntu-home:/etc/grub.d# update-grub
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.0.0-12-generic
Found initrd image: /boot/initrd.img-3.0.0-12-generic
Adding Windows
Found memtest86+ image: /boot/memtest86+.bin
done

Now your custom script is included in the file /boot/grub/grub.cfg

You just have to reboot and enjoy (?) your Windows partition.

Popular Posts:

flattr this!

  12 Responses to “Windows entry disappeared in Grub2 menu”

  1. nice; I’ve been adding it manually every update …

  2. why not just run update-grub?

    • Done it, it doesn’t see my windows partition, otherwise it would be much easier

      root@xubuntu-home:/etc/grub.d# ls
      00_header 05_debian_theme 10_linux 15_windows 20_linux_xen 20_memtest86+ 30_os-prober 40_custom 41_custom README
      r
      oot@xubuntu-home:/etc/grub.d# mv 15_windows /tmp/

      root@xubuntu-home:/etc/grub.d# update-grub
      Generating grub.cfg ...
      Found linux image: /boot/vmlinuz-3.0.0-12-generic
      Found initrd image: /boot/initrd.img-3.0.0-12-generic
      Found memtest86+ image: /boot/memtest86+.bin
      done

      No windows entry with a simple update-grub.
      There is something wrong in my Xubuntu 11.10 ?
      It’s a fresh install with all the defaults.. so it took less time to add the windows entry manually than finding than problem.

  3. Quicker way:
    Boot the Live disc

    Mount the Ubuntu partition: sudo mount /dev/sdaX /mnt

    Run grub-install: sudo grub-install –root -directory=/mnt/ /dev/sda

    Reboot, then run sudo update-grub

    This gives you a newly installed grub2, which recognizes Windows

    • Thanks for the feedback Emery,
      i tried that but it didn’t work, check my answer to the other comment.

      Best Regards

  4. I have always this f*#§ing error…
    Generating grub.cfg …
    Found linux image: /boot/vmlinuz-3.0.0-12-generic
    Found initrd image: /boot/initrd.img-3.0.0-12-generic
    Found memtest86+ image: /boot/memtest86+.bin
    errore: syntax error.
    errore: Incorrect command.
    errore: syntax error.
    error: line no: 98
    Syntax errors are detected in generated GRUB config file.
    Ensure that there are no errors in /etc/default/grub
    and /etc/grub.d/* files or please file a bug report with
    /boot/grub/grub.cfg.new file attached.

    What is, by the way?

    • Hello,

      Have you add something on grub.cfg on the directoy /etc/grub.d/ ?
      It seem to be a syntax error somewhere.

  5. what is the script if my windows partition is in /dev/sda3 ??

  6. Works for me, just be carefull with the spaces when you cut & paste the 15_Windows script from this page.
    The shebang (# on the first line) should start the line without a space and the redirection >> should be two right angled brackets with no space in between.

  7. Thanks for your script, it saved my day !

    Quick remark for Fedora users : the “< <" characters give an error due to the space in between. "<<" is ok.
    Also, don't use update-grub but grub2-install /dev/sda && grub2-mkconfig -o /boot/grub2/grub.cfg

    @ Bill John : /dev/sda3 would be (hd0,3) in grub2.

 Leave a Reply

(required)

(required)


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>