Wiki Ubuntu-it

Indice
Partecipa
FAQ
Wiki Blog
------------------
Ubuntu-it.org
Forum
Chiedi
Chat
Cerca
Planet
  • Pagina non alterabile
  • Informazioni
  • Allegati

Versione 1 del 20/10/2009 09.34.35

Nascondi questo messaggio

BR WikiBanner(ArticoloInTraduzione) BR Indice()

Aggiungere voci al menu

Il file grub.cfg viene aggiornato quando vengono eseguiti i comandi update-grub o update-grub2. Per modificare grub.cfg si debbono utilizzare gli appositi script presenti nella cartella /etc/grub.d/, senza modificare direttamente il file stesso.

Immagine(Icone/Piccole/note.png,,center)

Il primo commento del file grub.cfg è «DO NOT EDIT THIS FILE». Il file risulta di fatti sempre in sola lettura e ritorna in questo stato ogni qual volta viene eseguito il comando update-grub.

Voci automatiche

<-- SONO RIPETUTE INFORMAZIONI GIÀ INSERITE PRIMA

  • When "update-grub" is executed, Grub 2 will read /etc/default/grub and the files in contained in the /etc/grub.d folder. This combination will set the visual parameters of the grub menu (/etc/default/grub) and search for linux kernels, other operating systems, and items designated in user-created scripts in /etc/grub.d. The script files in /etc/grub.d perform the following tasks:

    • 10_linux searches for installed linux kernels.

    • 30_os-prober searches for other operating systems.

    • 40_custom and any other user-created files in the /etc/grub.d folder add menu items designated in the script files created by users.

  • The name of the file determines the order in the menu. 30_os-prober entries will be placed before 40_custom entries, which will be placed before any higher-numbered entries.
  • Any user-created file must be made executable. This can be done as root by running

sudo chmod u+x /etc/grub.d/filename
  • FINE -->

Aggiungere voci

Gli utenti con i [:AmministrazioneSistema/Sudo:privilegi di amministrazione] possono creare script all'interno della cartella /etc/grub.d/ che saranno poi inclusi nel file grub.cfg quando il comando update-grub verrà lanciato.

Immagine(Icone/Piccole/note.png,,center)

I file appena creati dovrebbero avere il nome nel formato XX_nome, dove la dicitura «XX» corrisponde ad un numero. Si ricorda che l'ordine con il quale sono eseguiti i file è alfabetico crescente, i file il cui nome inizia con una cifra hanno priorità su quelli in cui il nome inizia con una lettera.

Il file deve essere eseguibile al fine di poterlo lanciare insieme agli altri script. Per rendere eseguibile il file, da riga di comando digitare:

sudo chmod u+x /etc/grub.d/nome-file

Sostituire la dicitura «nome-file» con il nome del file appena creato.

Segue un semplice esempio di aggiunta voce al menu di Grub. Questo file crea una voce per eseguire l'installazione di un CD di ripristino di sistema sulla partizione «sdb10» e aggiunge al menu un kernel personalizzato dalla partizione «sda1».

Immagine(Icone/Piccole/note.png,,center)

Il conteggio dei dispositivi parte da 0, ovvero sda è indicato come hd0, sdb è hd1 e così via. Il nome delle partizioni parte invece da 1, la prima partizione è indicata come sda1, la quinta partizione è sda5

echo "Adding Custom Kernel & SystemRescue" >&2
cat << EOF
menuentry "Ubuntu, linux 2.6.31-11-custom" {
        set root=(hd0,9)
        linux /boot/vmlinuz-2.6.31-11-custom root=UUID=c6829e27-2350-4e84-bdbb-91b83f018f98 ro 
        initrd /boot/initrd.img-2.6.28-11-generic
}

menuentry "Boot SystemRescue CD from hard drive" {
        set root=(hd1,10)
        linux   /sysrcd/rescuecd subdir=sysrcd setkmap=us
        initrd  /sysrcd/initram.igz
} 
EOF

Ai fini della modifica del menu, non è necessaria la riga:

"echo "Adding SystemRescueCD" >&2"

Essa sarà mostrata durante l'esecuzione del comando update-grub2. La comparsa della riga nel terminale indica l'avvenuta lettura ed esecuzione del nuovo script.

Se lo script è corretto saranno inserite le nuove voci nel menu di grub.cfg. Nessuna modifica in caso contrario.

Rimuovere voci

Le voci del menu dovrebbero essere rimosse modificando o rimuovendo i file presenti nella cartella /etc/grub.d. Il file grub.cfg è in sola lettura e non dovrebbe essere modificato direttamente.

  • Automatically.
    • Kernels removed by Synaptic will automatically update grub.cfg and no user action is required.

    • Other operating systems which have been removed from the computer will also be removed from the menu once "update-grub2" is run as root.

  • Manually.
    • To prevent a file in /etc/grub.d from adding items to the menu, remove the executable bit or remove the applicable file.

    • memtest86+: If you don't want to have memtest86+ displayed in your menu, run sudo chmod -x /etc/grub.d/20_memtest86+. The file will remain but will not be acted upon by update-grub.

    • Recovery mode: If you don't want Recovery mode entries for your linux kernels, edit /etc/default/grub and add this line:

      • GRUB_DISABLE_LINUX_RECOVERY=true
    • If a custom script in the /etc/grub.d/ folder contains multiple menu entries, individual items may be removed and others retained.

    • Tip: If the user wants his custom entries to appear at the top of the menu, the file can be named a value less than "10_linux", such as "07_custom". Check that the "DEFAULT" value in /etc/default/grub points to the correct menuentry after making this change.

    • Changes will not take effect on the Grub 2 menu until "update-grub" is run to update grub.cfg

Modifica manuale

  • Manual Editing of grub.cfg

    • If you must edit this file:

      sudo chmod +w /boot/grub/grub.cfg  # Remove 'read-only', necessary even for "root"
      sudo nano /boot/grub/grub.cfg      # Edit as "root"
    • Note: This file is returned to 'read-only' status and user inputs are overwritten anytime the "update-grub" command is run.