Oct 182011
 

Ho finalmente terminato il mio aggiornamento a Xubuntu 11.10, con i soliti piccoli problemi, nulla di troppo preoccupante.
Ma ora, quando faccio boot non vedo più la voce “Windows” nel menu di avvio, creato con grub2, ho anche installato os-prober che dovrebbe aiutare a trovare voci aggiuntive per il menù di grub2 scansionando i dischi rigidi, ma anche questo non ha risolto il problema.

In alternativa si potrebbe avere la vostra voce Windows, ma quando si seleziona si ottiene un errore del tipo:

  • you need to load kernel first
  • chainloader: no such command.
  • no such partition

Quindi questa è una piccola guida per ripristinare la voce di Windows nel vostro sistema con Grub2.

Grub2 howto super breve

Questa parte viene dal tutorial completo su grub2 del sito Dedoimedo , mentre ero alla ricerca di un aiuto ho letto la sua guida completa su grub2 e vi consiglio di prendervi il tempo di leggerlo per averne una panoramica completa.

GRUB 2 ha 3 parti principali:

  1. /etc/default/grub – Il file contenente le opzioni del menu di GRUB 2.
  2. /etc/grub.d/ – la directory contenente gli script per creare il menu di GRUB 2.
  3. /boot/grub/grub.cfg – il file di configurazione di GRUB 2, non editabile.

Il comando update-grub legge la directory /etc/grub.d e cerca gli script eseguibili contenuti all’interno di essa. Gli script sono letti, nel loro ordine numerico, e scritti nel file grub.cfg, insieme alle configurazioni del menu lette dal file /etc/default/grub.

Le voci con cui fare boot provengono da diverse fonti – le voci di default vengono dalla distribuzione, altri sistemi operativi, presenti sui dischi e scoperti con osprober, e script personalizzati dall’utente, tutti seguono una rigida sintassi. Gli script sono scritti in shell (sh)

Passo 1, conoscere il vostro hard disk

La prima cosa che dovete sapere è la mappatura esatta del vostro hard-disk, per questo useremo il comando fdisk , vecchio ma sempre buono, con l’opzione -l, questo è il disco fisso della mia macchina Xubuntu

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

Quindi, per farla breve :

/dev/sda1 = Windows
/dev/sda2 = partizione extra formattata con fat32
/dev/sda5 = Linux swap
/dev/sda6 = Xubuntu partizione /
/dev/sda7 = Xubuntu partizione /home

La mia partizione windows è /dev/sda1 che in Grub2 è mappata come (hd0.1), notare che questo è diverso da grub (non 2) in cui la prima partizione del primo disco era (hd0, 0).

Passo 2 creare uno script personalizzato per Grub 2

Create il file /etc/grub.d/15_Windows, e metteteci le seguenti linee di codice:

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

E ora fate questo script eseguibile con il comando:

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

Passo 3 aggiornare la configurazione di grub 2

Ora, dobbiamo dire a grub 2 a ricreare il suo file di configurazione, per farlo eseguire, come root, il comando 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

Adesso il vostro script personalizzato è incluso nel file /boot/grub/grub.cfg

Dovete solo riavviare il sistema e godervi (?) la vostra partizione Windows.

Popular Posts:

Flattr this!

  16 Responses to “Voce Windows scomparsa nel menu di Grub2”

  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?

  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 to Sinethra Cancel 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)

*