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!

  16 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

  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?

  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.

  8. Thank You….it really worked…as opoho said for fedora and centos users they have delete that space

  9. does not work for me on CentOS 7.0. The command says succeeded but when I reboot I don’t see my windows 8.1 boot entry. Can someone please help.
    Below is the output of my commands –

    [root@localhost grub.d]# fdisk -l

    Disk /dev/sda: 320.1 GB, 320072933376 bytes, 625142448 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disk label type: dos
    Disk identifier: 0xc6bb5f09

    Device Boot Start End Blocks Id System
    /dev/sda1 * 2048 210419711 105208832 7 HPFS/NTFS/exFAT
    /dev/sda2 210419712 413171711 101376000 7 HPFS/NTFS/exFAT
    /dev/sda3 413171712 414195711 512000 83 Linux
    /dev/sda4 414195712 625142447 105473368 5 Extended
    /dev/sda5 414197760 625141759 105472000 8e Linux LVM

    Disk /dev/mapper/centos-swap: 9437 MB, 9437184000 bytes, 18432000 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes

    Disk /dev/mapper/centos-root: 98.6 GB, 98561949696 bytes, 192503808 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes

    [root@localhost grub.d]# grub2-install /dev/sda
    Installing for i386-pc platform.
    Installation finished. No error reported.

    [root@localhost grub.d]# grub2-mkconfig -o /boot/grub2/grub.cfg
    Generating grub configuration file …
    Found linux image: /boot/vmlinuz-3.10.0-123.el7.x86_64
    Found initrd image: /boot/initramfs-3.10.0-123.el7.x86_64.img
    Warning: Please don’t use old title `CentOS Linux, with Linux 3.10.0-123.el7.x86_64′ for GRUB_DEFAULT, use `Advanced options for CentOS Linux>CentOS Linux, with Linux 3.10.0-123.el7.x86_64′ (for versions before 2.00) or `gnulinux-advanced-aaef1ef5-d9b1-4980-a624-470fd6b55f7c>gnulinux-3.10.0-123.el7.x86_64-advanced-aaef1ef5-d9b1-4980-a624-470fd6b55f7c’ (for 2.00 or later)
    Found linux image: /boot/vmlinuz-0-rescue-7ab7bfde75e74d1099379d2f75695048
    Found initrd image: /boot/initramfs-0-rescue-7ab7bfde75e74d1099379d2f75695048.img
    Adding Windows
    done

  10. I think I am logged as admin, but I cannot save that script into /etc/grub.d/…

 Leave a Reply

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=""> <s> <strike> <strong>

(required)

(required)

*