GNU GRUB és en l'actualitat (--acacha 15:19, 26 ago 2009 (UTC)) el gestor d'arrancada o bootloader més utilitzat en distribucions Linux, to i que encara, també és molt utilitzat LILO.
NOTA: Per accedir al menú de grub amb Lucid cal mantenir premuda la tecla shift
IMPORTANT: El tema de les fases a canviat força a la versió 2 de Grub. Consulteu Stages a Grub 2
GRUB, s'instal·la en tres parts (una d'elles opcional) que coincideixen amb les fases per les quals passa l'execució de GRUB. Vegeu també l'article
bootloader
Les fases són:
NOTA: La versió 2 de GRUB introdueix més flexibilitat en aquestes fases.
Recursos:
El fitxer stage1 de GRUB:
$ ls -la /boot/grub/stage1 -rw-r--r-- 1 root root 512 2009-04-26 10:51 /boot/grub/stage1
és una còpia del que s'ha copiat al MBR del disc dur. El fitxer ocupa 512 bytes tot i que al MBR només s'escriuen 446 per que la resta contenen altre informació com la taula de particions.
La feina de l'stage 1 (conjuntament amb la opcional stage 1.5) és apuntar al fitxer de l'stage2. Aquest fitxer s'ha de trobar en algun lloc del disc dur si no hi haurà un error.
L'stage 1 també es pot instal·lar al primer sector d'una partició en comptes del MBR. En aquest cas no es necessita l'stage 1.5 excepte que el sistema de fitxers sigui ReiserFS.
Hi ha fins a 6 fitxers de l'stage 1_5:
$ ls -la | grep stage1_5 -rw-r--r-- 1 root root 8288 2009-04-26 10:51 e2fs_stage1_5 -rw-r--r-- 1 root root 7856 2009-04-26 10:51 fat_stage1_5 -rw-r--r-- 1 root root 8712 2009-04-26 10:51 jfs_stage1_5 -rw-r--r-- 1 root root 7352 2009-04-26 10:51 minix_stage1_5 -rw-r--r-- 1 root root 9756 2009-04-26 10:51 reiserfs_stage1_5 -rw-r--r-- 1 root root 9556 2009-04-26 10:51 xfs_stage1_5
Aquest fitxers s'instal·len a l'àrea de compatibilitat de DOS, als primers 21 sectors després del MBR (dins encara de la primera pista que normalment no es utilitzada pels sistemes de fitxers).
Com podeu veure es tracta de codi especific per tal que GRUB pugui treballar amb sistemes de fitxers especials com e2fs, fat, jfs, minix, reiserfs o xfs. Si observeu no apareixen els sistemes ext que són suportats directament per l'stage1
L'stage 2 es troba al fitxer:
$ ls -lah stage2 -rw-r--r-- 1 root root 119K 2009-04-26 10:51 stage2
Aquest fitxer és la part principal de GRUB. Aquest fitxer és el que realitza tota la feina que realitza tota la feina de carregar el kernel a la memòria RAM de l'ordinador i arrancar-lo. També és el que s'encarrega de mostrar el menú.
TODO:
GRUB Legacy uses stages: stage_1, stage_1.5, and stage_2. Those are replaced in GRUB 2 by boot.img (a 512-byte file that corresponds to stage_1 and is installed to a MBR); there is no stage_1.5 in GRUB 2; and core.img in GRUB 2 takes the place of stage_2 (or, perhaps, of both stage 1.5 and stage_2). Details: See Section 4 the subsection "grub-install: A key command."
Consulteu l'article GRUB 2.
IMPORTANT: Per a Grub 2 consulteu GRUB_2#Notaci.C3.B3_de_Grub_2
La sintaxi és:
(device[,part-num][,bsd-subpart-letter])
`[]' significa opcional. Device pot ser fd or hd seguit d'un digit , com hd0.part-num representa el número de partició. Comença de 0 per les particions primaries i a partir de 4 per a les esteses.
floppy disk drive = (fd0) First hard drive = (hd0) second hard drive = (hd1) third hard drive= (hd2) ... and so on. First partition = 0 second partition = 1 third partition = 2 ... and so on To combine these now: first partition on first hard drive = (hd0,0) = /dev/hda1 in Linux 2nd partition on first hard drive = (hd0,1) = /dev/hda2 in Linux 3rd partition on first hard drive = (hd0,2) = /dev/hda3 in Linux 4th partition on first hard drive = (hd0,3) = /dev/hda4 in Linux 5th partition on first hard drive = (hd0,4) = /dev/hda5 in Linux 6th partition on first hard drive = (hd0,5) = /dev/hda6 in Linux 7th partition on first hard drive = (hd0,6) = /dev/hda7 in Linux 8th partition on first hard drive = (hd0,7) = /dev/hda8 in Linux 9th partition on first hard drive = (hd0,8) = /dev/hda9 in Linux 10th partition on first hard drive = (hd0,9) = /dev/hda10in Linux first partition on second hard drive= (hd1,0) = /dev/hdb1 in Linux 2nd partition on second hard drive= (hd1,1) = /dev/hdb2 in Linux 3rd partition on second hard drive= (hd1,2) = /dev/hdb3 in Linux 4th partition on second hard drive= (hd1,3) = /dev/hdb4 in Linux
A diferencia de LILO, no és necessari reintal·lar GRUB al MBR cada cop que es fa un canvi a la seva configuració. Grub s'executa en dos fases:
En comptes de ser instal·lat al disc dur, GRUB es pot executar des d'un CD, disquet o USB per tal d'arrancar un sistema que no funciona correctament.
Per defecte grub ja està instal·lat. Si cal instal·lar-lo a mà podeu seguir les passes de:
L'argument de grub-install pot ser un despositiu (com '/dev/hda') o una partició especificada en la notació GRUB. Per exemple, la següent ordre instal·la grub al Master Boot Record (MBR) del primer dispositiu IDE:
# grub-install /dev/hda
Si consulteu el manual:
$ man grub-install
Podreu observar que es poden utilitzar opcions i que la documentació completa s'obté amb:
$ info grub_install
Les opcions són:
Quan el grub deixa de funcionar (perquè per exemple un Sistema Operatiu poc fiable te l'esborra durant la seva instal·lació) el podem recuperar amb les següents passes:
Primer cal iniciar un CD-LIVE. Les passes són molt similars a les seguides a: Recuperar_contrasenyes/usuaris_a_Ubuntu. Un cop dins cal identificar la partició on es troba el Linux que té el grub instal·lat
Podeu utilitzar la comanda mount:
$ mount /dev/sda2 on / type ext3 (rw,errors=remount-ro) proc on /proc type proc (rw,noexec,nosuid,nodev) /sys on /sys type sysfs (rw,noexec,nosuid,nodev) /dev/sda6 on /home type ext3 (rw) /dev/sda1 on /media/sda1 type vfat (rw,utf8,umask=007,gid=46) /dev/sdb1 on /linux2 type ext3 (rw,errors=remount-ro) /dev/sda5 on /var type ext3 (rw) securityfs on /sys/kernel/security type securityfs (rw) binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
Per intentar saber si el disc ja esta muntat. Sinó ho està cal identificar la partició amb fdisk o l'editor de Particions del menú Sistema/Administració
$ sudo fdisk -l Disc /dev/sda: 203.9 GB, 203928109056 octets 255 heads, 63 sectors/track, 24792 cylinders Units = cilindres of 16065 * 512 = 8225280 bytes Disk identifier: 0x35e635e6
Dispositiu Arrenc. Inici Final Blocs Id Sistema /dev/sda1 * 1 4178 33559753+ c W95 FAT32 (LBA) /dev/sda2 4179 6728 20482875 83 Linux /dev/sda3 6729 24792 145099080 5 Estesa /dev/sda5 6729 10552 30716248+ 83 Linux /dev/sda6 10553 24537 112334481 83 Linux /dev/sda7 24538 24792 2048256 82 Intercanvi Linux / Solaris
En aquest cas la partició és /dev/sda2. La muntem amb
$ cd $ cd mkdir p $ sudo mount /dev/sda2 p
Quan ja sabem quina és la partició executem:
$ sudo grub-install --root-directory=p /dev/sda
NOTA: Observeu que estem instal·lant grub al MBR del primer disc dur (dev/sda). Aquest és el lloc on la majoria de distribucions instal·len GRUB per defecte. Si voleu instal·lar-lo en el primer sector d'un altre partició o podeu fer amb, per exemple, /dev/sda1.
Fixeu-vos que posem /dev/sda, és a dir que instal·lem al primer sector del disc.
Si teniu una instal·lació d'un sistema servidor d'Ubuntu (Ubuntu Server) típica, el sistema arrel estarà amb LVM i la partició /boot estarà apart en un sistema ext4 o similar (els gestors d'arracanda com Grub no suporten LVM i per aquesta raó la partició de boot ha d'estar en un partició a part.)
El procés de recuperació de gru passa per executar un LIVE CD. Vegem els passos per a recuperar una Ubuntu Server 11.10. Un cop arrancat un LIVE CD hem de:
Instal·Lar, escanejar i activar LVM:
$ sudo apt-get install lvm2
Per si de cas activeu el mòdul:
$ sudo modprobe dm-mod
Ara cal escanejar els dispositius físics de LVM, els grups de volum i els volums lògics:
$ sudo pvscan $ sudo vgscan $ sudo lvscan
Ara cal activar els vg:
$ sudo vgchange -a y
Ara ja podeu muntar l'arrel del sistema:
$ sudo mount /dev/ubuntuserver1110/root /mnt $ sudo mount /dev/sda1 /mnt/boot
Ara ja podem reinstal·lar GRUB:
$ sudo grub-install --recheck --root-directory=/mnt /dev/sda
NOTA: A l'exemple el nom del sistema és ubuntuserver1110 i per això és diu així la partició LVM que muntem
Consulteu:
Un exemple d'instal·lació de l'stage1 (MBR) a un floppy:
cd /usr/share/grub/i386-pc $ sudo dd if=stage1 of=/dev/fd0 bs=512 count=1
Recursos:
Consulteu l'exemple complet a:
#Modificat per Sergi Tur Badenas #Instal·lació de Grub #OJO HDDx on x la partició on estigui la Ubuntu particiolinux=`cat /home/usuari/particiolinux` mount /dev/$particiolinux /home/usuari/p echo "(hd0) /dev/$disc" > /home/usuari/p/boot/grub/device.map grub-install --root-directory=/home/usuari/p /dev/$disc echo "(hd0) /dev/sda" > /home/usuari/p/boot/grub/device.map Xdialog --title "Restauració del Grub" --infobox "Grup restaurat a /dev/$disc" 14 56 5000 Xdialog --title "Imatge a disc $disc" --infobox "Operacions Finalitzades !!!" 14 56 5000 sleep 50
Consulteu la secció LILO#Instal.C2.B7lar_LILO_i_GRUB_junts de l'article sobre LILO
GRUB és el bootloader per defecte d'Ubuntu. Durant la instal·lació d'Ubuntu s'instal·lara GRUB i es configurarà sense necessitat de fer cap pas especial. Per defecte GRUB s'instal·la al MBR. Durant la següent pantalla de la instal·lació:
Si feu clic a "Avançat" podreu instal·lar GRUB en alguna altre lloc que no sigui el MBR.
Si feu això caldrà que configureu el programa que tingueu al MBR per tal de cridar a GRUB.
Consulteu:
Debootstrap#Tasques_a_realitzar_a_la_imatge_buida
Vegeu també:
Els fitxers de configuració es troben a /boot/grub/menu.lst a Debian i a /boot/grub/grub.conf a Fedora.
Exemple de fitxer
$ cat /boot/grub/menu.lst # menu.lst - See: grub(8), info grub, update-grub(8) # grub-install(8), grub-floppy(8), # grub-md5-crypt, /usr/share/doc/grub # and /usr/share/doc/grub-doc/. ## default num # Set the default entry to the entry number NUM. Numbering starts from 0, and # the entry number 0 is the default if the command is not used. # # You can specify 'saved' instead of a number. In this case, the default entry # is the entry saved with the command 'savedefault'. # WARNING: If you are using dmraid do not change this entry to 'saved' or your ## e.g. howmany=all ## howmany=7 # howmany=all ## should update-grub create memtest86 boot option ## e.g. memtest86=true ## memtest86=false # memtest86=true ## should update-grub adjust the value of the default booted system ## can be true or false # updatedefaultentry=false ## ## End Default Options ## title Ubuntu, kernel 2.6.15-27-386 root (hd0,1) kernel /boot/vmlinuz-2.6.15-27-386 root=/dev/sda2 ro quiet splash initrd /boot/initrd.img-2.6.15-27-386 savedefault boot title Ubuntu, kernel 2.6.15-27-386 (recovery mode) root (hd0,1) kernel /boot/vmlinuz-2.6.15-27-386 root=/dev/sda2 ro single initrd /boot/initrd.img-2.6.15-27-386 boot title Ubuntu, kernel 2.6.15-23-386 root (hd0,1) kernel /boot/vmlinuz-2.6.15-23-386 root=/dev/sda2 ro quiet splash initrd /boot/initrd.img-2.6.15-23-386 savedefault boot title Ubuntu, kernel 2.6.15-23-386 (recovery mode) root (hd0,1) kernel /boot/vmlinuz-2.6.15-23-386 root=/dev/sda2 ro single initrd /boot/initrd.img-2.6.15-23-386 boot title Ubuntu, memtest86+ root (hd0,1) kernel /boot/memtest86+.bin boot ### END DEBIAN AUTOMAGIC KERNELS LIST # This is a divider, added to separate the menu items below from the Debian # ones. title Other operating systems: root # This entry automatically added by the Debian installer for a non-linux OS # on /dev/sda1 title Microsoft Windows XP Professional root (hd0,0) savedefault makeactive chainloader +1
Recursos:
Hi ha 3 opcions:
1) Col·locar l'entrada de menú que ens interessa a l'inici, abans de la llista automàtica
IMPORTANT: S'ha de col·locar l'entrada de menú abans de:
### BEGIN AUTOMAGIC KERNELS LIST
Sinó quan s'actualitzi el kernel, aquesta llista es tornarà a crear i s'esborrarà la vostre entrada de menú.
2) Editar el número de l'entrada de menú a iniciar amb el paràmetre default
Es pot modificar el valor del paràmetre default. Per defecte posa
## default num # Set the default entry to the entry number NUM. Numbering starts from 0, and # the entry number 0 is the default if the command is not used. # # You can specify 'saved' instead of a number. In this case, the default entry # is the entry saved with the command 'savedefault'. # WARNING: If you are using dmraid do not change this entry to 'saved' or your # array will desync and will not let you boot your system. default 0
La primera entrada és la 0, la segona la 1, etc... Es compten el número d'entrades amb el paràmetre title i no es compten les entrades comentades.
La entrada per defecte és la 0 que coincidirà amb la última versió del kernel instal·lat
NOTA: El problema d'aquest sistema és que quan s'actualitzi el kernel, és possible que hageu de modificar el número.
3) Utilitzar la comanda savedefault
Aquest mètode és útil per evitar haver d'editar el valor de default. Es pot posar:
default saved
I el GRUB recordarà la entrada de menú que heu iniciat l'últim cop. La pròxima vegada que inicieu el menú de GRUB, es marcarà per defecte la última entrada de menú que heu utilitzat.
Perquè una entrada pugui ser recordada ha de portar la comanda:
savedefault
Un truc per només recordar una entrada concreta és que tota la resta no tinguin la comanda savedefault.
La última opció escollida és guarda al fitxer:
/boot/grub/default
S'ha de modificar la comanda timeout:
## timeout sec # Set a timeout, in SEC seconds, before automatically booting the default entry # (normally the first entry defined). timeout 10
El número és en segons.
IMPORTANT: Si poseu 0 mai més podreu accedir a GRUB i per tant sempre es carregarà el mateix sistema operatiu.
Es pot utilitzar la comanda hiddenmenu:
timeout 10 ## hiddenmenu # Hides the menu by default (press ESC to see the menu) hiddenmenu
Tingueu en compte que durant el temps del TIMEOUT podreu accedir al menú de GRUB pressionant la tecla ESC.
# Pretty colours color cyan/blue white/blue
Amb GRUB 2 tenim força més opcions per controlar l'aspecte gràfic
Es pot canviar la splash image amb:
splashimage=(hd0,1)/boot/grub/Ubuntusplash.xpm.gz foreground ffe4b5 background f4a460
Podeu trobar més exemples a:
Inicieu una shell de grub
$ sudo grub
Executeu:
grub> md5crypt Password: **** Encrypted: $1$I/KTB/$NtsUA1ejfg0t57djGAKUN.
A l'exemple em utilitzat com a paraula de pas 1234. Copieu la paraula de pas xifrada. Ara editeu el fitxer de configuració de GRUB:
$ gksudo gedit /boot/grub/menu.lst
Afegiu (després de la línia amb el comentari '#password topsecret'):
password $1$I/KTB/$NtsUA1ejfg0t57djGAKUN.
Ara a cada entrada de menú que vulgueu protegir afegiu la comanda:
lock
Per exemple:
title Ubuntu 9.04, kernel 2.6.28-15-generic uuid 8b669217-d286-4a45-be7e-69c5f0f29090 kernel /boot/vmlinuz-2.6.28-15-generic root=UUID=8b669217-d286-4a45-be7e-69c5f0f29090 ro quiet splash initrd /boot/initrd.img-2.6.28-15-generic lock quiet
Es pot utilitzat la opció fallback:
fallback 5 6 7 8
On els números són les entrades de menú a provar. L'arrancada s'executa sense mostrar el menú.
title Ubuntu root (hd0,5) kernel /vmlinuz root=/dev/hda6 ro quiet splash initrd /initrd.img boot
Tot el que hi ha entre:
### BEGIN AUTOMAGIC KERNELS LIST
i
### END DEBIAN AUTOMAGIC KERNELS LIST
És la llista que es crear automàticament cada cop que hi ha una actualització del nucli del sistema operatiu. No esborreu aquestes línies.
El DEBIAN AUTOMAGIC KERNELS LIST es pot configurar modificant els paràmetres que hi ha comentats:
IMPORTANT: No s'ha de descomentar, simplement modificar-los.
Les opcions són:
kopt
kopt és kernel options. Per exemple:
# kopt=root=UUID=8b669217-d286-4a45-be7e-69c5f0f29090 ro
Són les opcions que s'afegiran a totes les entrades dels kernels de la llista
groot
És la partició on està el grub a actualitzar.
# groot=8b669217-d286-4a45-be7e-69c5f0f29090
alternative
Mostra les entrades de menú càrrega segura (opció single del kernel)
# alternative=true
lock-alternative
Protegir amb paraula de pas les càrregues segures.
defoptions
Són les opcions a utilitzar a les entrades que no són alternatives:
## additional options to use with the default boot option, but not with the ## alternatives ## e.g. defoptions=vga=791 resume=/dev/hda5 # defoptions=quiet slash
altoptions
És el text a mostrar a les entrades alternatives:
## altoption boot targets option ## multiple altoptions lines are allowed ## e.g. altoptions=(extra menu suffix) extra boot options ## altoptions=(recovery) single # altoptions=(recovery mode) single
howmany
Indica quantes entrades mostrar al menú:
## controls how many kernels should be put into the menu.lst ## only counts the first occurence of a kernel, not the ## alternative kernel options ## e.g. howmany=all ## howmany=7 # howmany=all
memtest86=true
Mostrar una entrada de test de memòria RAM?
## should update-grub create memtest86 boot option ## e.g. memtest86=true ## memtest86=false # memtest86=true
Recursos:
Si el sistema operatiu permet se executat desde un disc secundari el fitxer menu.lst s'ha de configurar de la següent manera:
title Disc Auxiliar root (hd1,0) kernel /boot/vmlinuz-2.6.15-23-386 root=/dev/hdb1 ro quiet splash initrd /boot/initrd.img-2.6.15-23-386 boot
Cal tenir en compte que sovint les numeracions de disc durs de grub no estan en l'ordre més esperat. Si no encertem la unitat (hd1?, hd2?, hd0).
Tot i que al fitxer /bot/grub/device.map es pot fer un mapejat, en el meu cas amb tres discs durs (2 SATA i un IDE) no em feia cas del mapeig que vaig indicar.
NOTA: NO està clar que funcioni. Des de backtrack funciona però...
Si el vostre menú de grub permet modificacions de les entrades del menú amb la telca e, podeu seguir les següents passes per tornar a establir una paraula de pas perduda:
init=/bin/bash
Per exemple, si teníeu:
kernel /boot/vmlinuz-2.6.15-23-386 root=/dev/hdb1 ro quiet splash
Poseu:
kernel /boot/vmlinuz-2.6.15-23-386 root=/dev/hdb1 init=/bin/bash ro quiet splash
# mount -o remount,rw /
# mount /proc
Ara us caldrà muntar la partició de windows:
# mkdir sda1 # mount /dev/sda1 sda1
Aneu a la carpeta config:
# cd sda1/Windows/system32/config
I utilitzeu chntpw:
# chntpw -u Administrador SAM
Per estar segur que no hi ha dades pendents d'escriure al disc executeu:
# sync
Ara ja podeu reiniciar per recuperar la paraula de Linux.
Si el vostre menú de grub permet modificacions de les entrades del menú amb la telca e, podeu seguir les següents passes per tornar a establir una paraula de pas perduda:
init=/bin/bash
Per exemple, si teníeu:
kernel /boot/vmlinuz-2.6.15-23-386 root=/dev/hdb1 ro quiet splash
NOTA: a les versions noves del grub en lloc de sortir kernel surt linux
Poseu:
kernel /boot/vmlinuz-2.6.15-23-386 root=/dev/hdb1 init=/bin/bash ro quiet splash
NOTA: Per evitar el pas de muntar el volum amb els permisos descriptura safegeix nomes el següent: rw init=/bin/bash
# mount -o remount,rw /
# mount /proc
# passwd usuari
Si no poseu cap usuari, canviareu la paraula de pas de root.
Per estar segur que no hi ha dades pendents d'escriure al disc executeu:
# sync
Ara ja podeu reiniciar per recuperar la paraula de Linux.
Per a Windows, prèviament hauríeu d'instal·lar Chntpw i un cop tingueu consola de Linux executeu les passes de l'article Chntpw. Consulteu:
Resetejar la paraula de pas de Windows des de grub amb la opció init
NOTES:
Necessitareu conèixer on estan localitzades algunes tecles del teclat amaerica per tal de poder introduir les comandes. Consulteu l'article:
Teclat Amèrica
Podeu impedir que el menú de GRUB sigui modificable posant una paraula de pas:
Grub#Protegir_amb_paraula_de_pas_GRUB.
Al menu podem selecciona una opció i editar-la temporalment (els canvis no són permanents) prement la tecla e (edit).
Recursos
Si accedeix des del menú de GRUB prement la tecla c. Podeu veure un exemple d'imatge a:
Per exemple, podem investigar un ordinador. Si escribiu
grub> root (hd
I tabuleu us mostrarà el nombre de discs que hi ha al sistema:
Possible disks are: hd0 hd1 hd2
Si escollim el primer disc i tabulem:
grub> root (hd0,
Us mostrarà les particions:
Possible partitions are: Partition num: 0, Filesystem type is ext2fs, partition type 0x83 Partition num: 4, Filesystem type unknown, partition type 0x82
També podem consultar la geometria d'un disc dur i les seves particions amb:
grub > geometry (hd0) drive 0x80: C/H/S = 24792/255/63, The number of sectors = 398297088, /dev/sda Partition num: 0, Filesystem type is ext2fs, partition type 0x83 Partition num: 4, Filesystem type unknown, partition type 0x82
Fixeu-vos que la sortida és similar a fdisk.
Recursos:
> find /vmlinuz (hd0,0) (hd1,0)
grub> find /sbin/init (hd0,0) (hd1,0)
grub> find /bin/ls (hd0,0) (hd1,0)
grub> cat (hd0,0)/etc/lsb-release DISTRIB_ID=Ubuntu DISTRIB_RELEASE=9.04 DISTRIB_CODENAME=jaunty DISTRIB_DESCRIPTION="Ubuntu 9.04"
grub> cat (hd0,0)/boot/grub/menu.lst grub> cat (hd0,7)/etc/fstab grub> cat (hd0,7)/boot/grub/device.map
Cal escollir la partició amb:
grub> root (hdx,y)
Vegeu la notació de grub. Per exemple:
grub> root (hd0,1)
Sovint contesta indicant el sistema de fitxers:
grub> root (hd0,1) Filesystem type is ext2fs, partition type 0x83
Ara cal executar:
grub> kernel /vmlinuz root=/dev/hda..
Cal especificar on està el kernel i quina és la partició que conté el root (/). Per exemple
grub> kernel /boot//vmlinuz-2.6.28-15-generic root=/dev/sdb5
NOTA: Es pot utilitzar el tabulador per trobar els fitxers
Ara cal especificar el initrd
grub> initrd /boot/initrd.img-2.6.28-15-generic
NOTA: Alguns sistemes ja tenen a l'arrel el fitxers /vmlinuz i /initrd.img i són enllaços a les últimes versions d'aquests fitxers a la carpeta /boot
I ara només queda indicar que volem arrancar aquest sistema amb:
grub> boot
Cal buscar una partició on estigui el fitxer de configuració de grub:
grub> find /boot/grub/menu.lst (hd0,0) (hd1,0)
Ara podem executar:
grub> configfile (hd0,0)/boot/grub/menu.lst
I s'executarà el menú de GRUB corresponent. Això també pot ser útil per a provar GRUB si s'executa des de GRUB Shell.
grub> root (hd0,5) Filesystem is ext2fs, partition type is 0x83 grub> chainloader +1 grub> boot
Es fa amb la comanda setup:
grub> find /boot/grub/stage1 (hd0,1) (hd0,5) grub> root (hd0,5) Filesystem is ext2fs, partition type is 0x83 grub> setup (hd0,5) Checking if "/boot/grub/stage1" exists...yes Checking if "/boot/grub/stage2" exists...yes Checking if "/boot/grub/e2fs_stage1_5" exists...yes Running "embed /boot/grub/embed/e2fs_stage1_5 (hd0,5)"...failed (this is not fatal) Running "embed /boot/grub/embed/e2fs_stage1_5 (hd0,5)"...failed (this is not fatal) Running "install /boot/grub/stage1 d (hd0,5) /boot/grub/stage2 p /boot/grub/menu.lst"... succeeded Done. grub> chainloader +1 grub> boot
grub> find /boot.ini (hd0,0) grub> rootnoverify (hd0,0)
grub> makeactive
Marca la partició com activa.
grub> chainloader +1 grub> boot
També es pot fer amb comandes map:
grub> rootnoverify (hd1,0) grub> makeactive grub> map (hd0) (hd1) grub> map (hd1) (hd0) grub> chainloader +1 grub> boot_
A la shell de GRUB es pot accedir des de la línia de comandes:
$ sudo grub
La comanda help ens proporciona les comandes que podem utilitzar en aquesta shell
[ Minimal BASH-like line editing is supported. For the first word, TAB lists possible command completions. Anywhere else TAB lists the possible completions of a device/filename. ] grub> help blocklist FILE boot cat FILE chainloader [--force] FILE clear color NORMAL [HIGHLIGHT] configfile FILE device DRIVE DEVICE displayapm displaymem find FILENAME geometry DRIVE [CYLINDER HEAD SECTOR [ halt [--no-apm] help [--all] [PATTERN ...] hide PARTITION initrd FILE [ARG ...] kernel [--no-mem-option] [--type=TYPE] makeactive map TO_DRIVE FROM_DRIVE md5crypt module FILE [ARG ...] modulenounzip FILE [ARG ...] pager [FLAG] partnew PART TYPE START LEN parttype PART TYPE quit quietboot reboot root [DEVICE [HDBIAS]] rootnoverify [DEVICE [HDBIAS]] serial [--unit=UNIT] [--port=PORT] [-- setkey [TO_KEY FROM_KEY] setup [--prefix=DIR] [--stage2=STAGE2_ terminal [--dumb] [--no-echo] [--no-ed terminfo [--name=NAME --cursor-address testvbe MODE unhide PARTITION uppermem KBYTES vbeprobe [MODE] grub>
Gairebé tot el que s'aplica a a la línia de comandes de GRUB (GRUB CLI) s'aplica a la shell de GRUB.
Recursos:
Consulteu GRUB_2#Grub_shell.
El ChainLoading, simplement és fer que un gestor d'arrancada executi un altre gestor d'arrancada. El gestor d'arrancada a executar pot estar al MBR o a un sector d'arrancada.
Per exemple, per fer que GRUB executi el gestor d'arrancada de Windows (i per tant que s'executi Windows), afegiríem les següents línies al fitxer /boot/grub/menu.lst:
# This entry automatically added by the Debian installer for a non-linux OS # on /dev/sda1 title Microsoft Windows XP Professional root (hd0,0) savedefault makeactive chainloader +1
On (hd0,0) indica que executarem el gestor d'arrancada del sector 0 de la primera partició del primer disc (que en l'exemple és on se suposa que tenim Windows instal·lat).
Com s'explica a Instal·lar LILO i GRUB junts pode fer el mateix per executar una altre gestor d'arrancada com per exemple LILO o un GRUB d'un altre disc.
Els paràmetres del kernel es poden passar mitjançant la comanda kernel de GRUB:
kernel /camí/al/nucli_delinux root={PARTICIó DE ROOT] [opcions del kernel]
Un exemple
kernel /boot/vmlinuz-2.6.28-13-generic root=UUID=8b669217-d286-4a45-be7e-69c5f0f29090 ro quiet splash
En molts sistemes, el kernel més actual es pot trobar a:
/vmlinuz
Que és un link a l'últim kernel:
$ ls -la /vmlinuz lrwxrwxrwx 1 root root 30 2009-08-20 11:46 /vmlinuz -> boot/vmlinuz-2.6.28-15-generic
NOTA: La versió de kernel que es tem utilitzant es pot consultar amb la comanda uname: $uname -r
La partició on està root (/) es pot indicar amb UUIDs:
kernel /boot/vmlinuz-2.6.28-13-generic root=UUID=8b669217-d286-4a45-be7e-69c5f0f29090 ro quiet splash
O indicant el fitxer de dispositiu /dev:
kernel /boot/vmlinuz-2.6.28-13-generic root=/dev/sda1 ro quiet splash
A la documentació del nucli de Linux podeu trobar un fitxer que explica els paràmetres:
$ sudo dpkg -L linux-doc-2.6.28 | grep parameters /usr/share/doc/linux-doc-2.6.28/kernel-parameters.txt.gz $ sudo gunzip /usr/share/doc/linux-doc-2.6.28/kernel-parameters.txt.gz $ joe /usr/share/doc/linux-doc-2.6.28/kernel-parameters.txt
Recursos:
ro són les sigles de readonly. Indica que l'arrel es muntarà en mode només lectura. Això es posa sempre per tal de permetre que fsck pugui comprovar i corregir el sistema de fitxers abans d'utilitzar-lo
Hi ha la opció rw, però tingueu en compte que mai s'ha de fer un fsck amb un sistema muntat amb lectura/escriptura.
Desactiva la majoria de missatges de log:
$ cat /usr/share/doc/linux-doc/kernel-parameters.txt| grep quiet
Format: { quiet (default) | verbose | debug }
Altres opcions són:
Aquesta opció no apareix al fitxer de paràmetres de la documentació. A Ubuntu indica si volem o no mostrar una pantalla gràfica anomenada splash (la imatge es troba al initrd), en comptes de veure els missatges d'arrencada del kernel.
Recursos:
El paràmetre single executa el procés init per entrar en single user mode. Això provoca que el no s'executin tots els serveis i dimonis habituals, i ens proporciona una línia de comandes en un entorn monousuari.
En els menús de GRUB són les opcions Recovery Mode.
Permet millorar/modificar la resolució de les pantalles de les consoles virtual durant el boot. Estableix el mode en que treballa el framebuffer.
Per exemple podem utilitzar:
vga=711
O per exemple:
vga=ask
Ens preguntarà quina resolució volem. Podem mostrar-les totes amb Enter i fins i tot fer un scan amb l'ordre scan.
Podeu provar amb qemu:
$ qemu -kernel /boot/vmlinuz-2.6.31-15-generic -initrd /boot/initrd.img-2.6.31-15-generic -hda image.img -append "vga=ask"
La llista de modes possibles la trobareu a:
http://en.wikipedia.org/wiki/VESA_BIOS_Extensions#Linux_video_mode_numbers
Recursos:
Indiquen el grau de missatgees que es volen mostrar:
$ cat /usr/share/doc/linux-doc-2.6.28/kernel-parameters.txt| grep quiet Format: { quiet (default) | verbose | debug } quiet [KNL] Disable most log messages
Són les opcions contraposades a l'opció quiet.
Aquesta comanda indica quin és la primera comanda que ha d'executar el kernel. El valor per defecte és:
/sbin/init
És a dir el procés init. Si voleu obtenir una línia de comandes, podeu indicar el següent paràmetre del kernel:
init=/bin/bash
Per veure un exemple d'ús utilitzeu:
Grub#Restablir_paraules_de_pas_des_de_grup_amb_la_opci.C3.B3_init
Permet especificar el que farà el nucli en cas d'un error kernel panic
panic=SECONDS
Per defecte el comportament es tornar a iniciar la màquina. Amb secons podem indicar quants segons tardara en tornar a iniciar.
Per exemple:
panic=10
maxcpus=NUMBER
Especifica el nombre màxim de CPUs d'un kernel SMP.
Activa o desactiva selinux:
selinux=[0|1]
Consulteu selinux
raid=/dev/mdN
TODO
This argument tells kernel howto assembly of RAID arrays at boot time. Please note that When md is compiled into the kernel (not as module), partitions of type 0xfd are scanned and automatically assembled into RAID arrays. This autodetection may be suppressed with the kernel parameter "raid=noautodetect". As of kernel 2.6.9, only drives with a type 0 superblock can be autodetected and run at boot time.
mem=MEMORY_SIZE
Indicar la memòria a utilitzar pel nucli. Això s'utilitza per forçar a llegir tota la memòria, quan per exemple, per alguna raó el nucli no veu tota la memòria disponible del sistema.
Per exemple:
mem=1024M
Aquesta opció de disc indica quin és el initrd (init ram disk) que s'utilitzarà com a suport de l'execució/arrancada del nucli
initrd /boot/initrd.img
El procés d'arrencada executarà primer el kernel i després la imatge initrd.img es carregarà en ram i serà executada. La imatge initrd és muntada com a root en mode lectura i escriptura i s'executa el fitxer:
/linuxrc
que es troba dins la imatge. Normalment, quan s'acaba l'execució de la imatge, aleshores es munta el sistema de fitxers arrel inicial i el initrd es mou a /initrd. Aleshores s'inicia la seqüència de boor (procés init).
initrd s'utilitza per proporcionar moduls addicionals com per exemple SCSI o RAID.
Permet desactivar un disc dur:
hdX =noprobe
Per exemple:
hdb=noprobe
Tingueu en compte que per molt que desactiveu un disc a la BIOS, Linux el detectarà igualment excepte si utilitzeu està opció.
Permet configurar la targeta de xarxa:
ether=irq,iobase,[ARG1,ARG2],name
Per exemple per detectar una segona targeta de xarxa:
ether=0,0,eth1
On els zeros indiquen que la detecció serà automàtica.
apm=off
No utilitzis Advanced Power Managment.
acpi=off
Desactiva Advanced Configuration and Power Interface
No utilitzis el Direct Memory Access
Suposeu que el dis esta muntat a:
/media/disk
$ sudo mkdir -p /media/usbdisk/boot
This command makes an empty directory (folder), in your usbdisk named /boot
$ sudo cp -r /boot/grub /media/usbdisk/boot
Now we are copying our operating system's /boot/grub directory and all it's contents, and pasting it in our usbdisk's new /boot directory.
$ sudo grub
Now we open a grub shell, we will have a GRUB prompt.
grub> find /boot/grub/stage1 (hd0,1) (hd1,1) (hd2,0)
This command prints out a list of partitions in GRUB notation that have a copy of GRUB's stage1 files. In this example, I have two hard disk drives inside the computer, plus the USBdisk, so I am a little confused as to which one is which. We have to try to pick out which one of these represents the USB disk. I will use a special GRUB command to find out. It is called the 'geometry' command.
grub> geometry (hd1) drive 0x81: C/H/S = 3648/255/63, The number of sectors = 58605120, /dev/hdb Partition num: 0, Filesystem type is fat, partition type 0xb Partition num: 1, Filesystem type is ext2fs, partition type 0x83 Partition num: 3, Filesystem type is ext2fs, partition type 0x83 Partition num: 4, Filesystem type unknown, partition type 0x82
Here is how I used the 'geometry' command, in the GRUB shell, I typed 'geometry' (without the inverted commas), followed by the hard disk number I want to check out, (in GRUB's notation).
The feedback from this command can be seen right under where the command is shown in the above illustration. That doesn't look like my USB thumb drive to me, my USB thumb drive only has one single partition in it. I recognise that partition information as being that of my second hard disk inside my computer, so (hd1) is not the disk I want to install GRUB to right now.
Let's take a look at (hd2),
grub> geometry (hd2) drive 0x82: C/H/S = 7936/1/32, The number of sectors = 253952, /dev/sde Partition num: 0, Filesystem type is ext2fs, partition type 0x83
Now we're getting somewhere, (hd2) is the correct disk to install GRUB to. That's obviously my USB thumb drive alright! Look, it has '/dev/sde' on the end of the top line (for most people it might be '/dev/sda' instead), and it has just one partition. The cylinders, heads and sectors numbers (geometry) indicate that this is only a small drive, and so does the number of sectors. This is the right hard disk to install GRUB to.
grub> root (hd2,0)
This 'root (hd2,0)' command means it will be the usb disk's grub that will be installed in our usbdisk's first sector. (Not some other GRUB installation from our hard disk). Yours might be different to mine, so be careful here, use one of the GRUB partition designations you see shown in the feedback from your 'find' command, three tables up from here.
grub> setup (hd2) Checking if "/boot/grub/stage1" exists... yes Checking if "/boot/grub/stage2" exists... yes Checking if "/boot/grub/e2fs_stage1_5" exists... yes Running "embed /boot/grub/e2fs_stage1_5 (hd2)"... 15 sectors are embedded. succeeded Running "install /boot/grub/stage1 d (hd2) (hd2)1+15 p (hd2,0)/boot/grub/stage 2 /boot/grub/menu.lst"... succeeded Done.
This 'setup (hd2)' command installs grub's IPL or stage1 in our usbdisk's first sector. The rest of the text you see here is the feedback from the system, so we can see what happened.
grub> quit
This is to quit the GRUB shell and go back to our regular terminal prompt.
$ sudo chmod -R 777 /media/usbdisk/boot/grub
This relaxes any file permissions on the USB thumb drive's GRUB directory and its contents for conveniences to make it easier for you to read and write to.
This is optional, but you can now have fun playing with the GRUB in your USB drive without having to worry about it affecting your hard disk install's GRUB.
If you prefer to leave your USB disk's GRUB secure, it will just mean you will need to use the sudo commands from a terminal every time you want to make changes.
Recursos
És un disc amb un GRUB que permet restaurar el GRUB, i altres utilitats.
Recursos:
Consulteu Startup Manager.
Recursos:
http://www.gnu.org/software/grub/manual/grub.html#Stage2-errors
http://www.gnu.org/software/grub/manual/grub.html#Stage2-errors
1 : Filename must be either an absolute filename or blocklist This error is returned if a file name is requested which doesn't fit the syntax/rules listed in the Filesystem. 2 : Bad file or directory type This error is returned if a file requested is not a regular file, but something like a symbolic link, directory, or FIFO. 3 : Bad or corrupt data while decompressing file This error is returned if the run-length decompression code gets an internal error. This is usually from a corrupt file. 4 : Bad or incompatible header in compressed file This error is returned if the file header for a supposedly compressed file is bad. 5 : Partition table invalid or corrupt This error is returned if the sanity checks on the integrity of the partition table fail. This is a bad sign. 6 : Mismatched or corrupt version of stage1/stage2 This error is returned if the install command points to incompatible or corrupt versions of the stage1 or stage2. It can't detect corruption in general, but this is a sanity check on the version numbers, which should be correct . 7 : Loading below 1MB is not supported This error is returned if the lowest address in a kernel is below the 1MB boundary. The Linux zImage format is a special case and can be handled since it has a fixed loading address and maximum size. 8 : Kernel must be loaded before booting This error is returned if GRUB is told to execute the boot sequence without having a kernel to start. 9 : Unknown boot failure This error is returned if the boot attempt did not succeed for reasons which are unknown. 10 : Unsupported Multiboot features requested This error is returned when the Multiboot features word in the Multiboot header requires a feature that is not recognized. The point of this is that the kernel requires special handling which GRUB is probably unable to provide. 11 : Unrecognized device string This error is returned if a device string was expected, and the string encountered didn't fit the syntax/rules listed in the Filesystem. 12 : Invalid device requested This error is returned if a device string is recognizable but does not fall under the other device errors. 13 : Invalid or unsupported executable format This error is returned if the kernel image being loaded is not recognized as Multiboot or one of the supported native formats (Linux zImage or bzImage, FreeBSD, or NetBSD). 14 : Filesystem compatibility error, cannot read whole file Some of the filesystem reading code in GRUB has limits on the length of the files it can read. This error is returned when the user runs into such a limit. 15 : File not found This error is returned if the specified file name cannot be found, but everything else (like the disk/partition info) is OK. 16 : Inconsistent filesystem structure This error is returned by the filesystem code to denote an internal error caused by the sanity checks of the filesystem structure on disk not matching what it expects. This is usually caused by a corrupt filesystem or bugs in the code handling it in GRUB. 17 : Cannot mount selected partition This error is returned if the partition requested exists, but the filesystem type cannot be recognized by GRUB. 18 : Selected cylinder exceeds maximum supported by BIOS This error is returned when a read is attempted at a linear block address beyond the end of the BIOS translated area. This generally happens if your disk is larger than the BIOS can handle (512MB for (E)IDE disks on older machines or larger than 8GB in general). 19 : Linux kernel must be loaded before initrd This error is returned if the initrd command is used before loading a Linux kernel. 20 : Multiboot kernel must be loaded before modules This error is returned if the module load command is used before loading a Multiboot kernel. It only makes sense in this case anyway, as GRUB has no idea how to communicate the presence of such modules to a non-Multiboot-aware kernel. 21 : Selected disk does not exist This error is returned if the device part of a device- or full file name refers to a disk or BIOS device that is not present or not recognized by the BIOS in the system. 22 : No such partition This error is returned if a partition is requested in the device part of a device- or full file name which isn't on the selected disk. 23 : Error while parsing number This error is returned if GRUB was expecting to read a number and encountered bad data. 24 : Attempt to access block outside partition This error is returned if a linear block address is outside of the disk partition. This generally happens because of a corrupt filesystem on the disk or a bug in the code handling it in GRUB (it's a great debugging tool) . 25 : Disk read error This error is returned if there is a disk read error when trying to probe or read data from a particular disk. 26 : Too many symbolic links This error is returned if the link count is beyond the maximum (currently 5), possibly the symbolic links are looped. 27 : Unrecognized command This error is returned if an unrecognized command is entered on the command-line or in a boot sequence section of a configuration file and that entry is selected. 28 : Selected item cannot fit into memory This error is returned if a kernel, module, or raw file load command is either trying to load its data such that it won't fit into memory or it is simply too big. 29 : Disk write error This error is returned if there is a disk write error when trying to write to a particular disk. This would generally only occur during an install of set active partition command. 30 : Invalid argument This error is returned if an argument specified to a command is invalid. 31 : File is not sector aligned This error may occur only when you access a ReiserFS partition by block-lists (e.g. the command install). In this case, you should mount the partition with the `-o notail' option. 32 : Must be authenticated This error is returned if you try to run a locked entry. You should enter a correct password before running such an entry. 33 : Serial device not configured This error is returned if you try to change your terminal to a serial one before initializing any serial device. 34 : No spare sectors on the disk This error is returned if a disk doesn't have enough spare space. This happens when you try to embed Stage 1.5 into the unused sectors after the MBR, but the first partition starts right after the MBR or they are used by EZ-BIOS.
Aquest error indica que tot esta ben configurat excepte el camí per trobar el kernel. A vegades ens pensem que hem carregat una unitat però és un altre. Per comprovar el que hem escrit al fitxer /boot/grub/menu.lst podem utilitzar la línia de comandes de GRUB:
grub > root (<TAB>)
El tabulador ens indicarà les unitats que estan disponibles. Una vegada carregada la unitat:
grub > root (hd1,0)
Mirem on esta el kernel
grub > kernel <TAB>
Ens mostrarà el sistema de fitxers....
Es pot reinstal·lar el MBR amb grub-install (fins i tot copia amb dd la copia del MBR que es guarda a la carpeta /boot/grub).
També es poden utilitzar eines com nlite per crear un Windows a mida. Entre altres coses permet especificar un sector d'arrencada al nostre gust (per exemple amb el MBR de GRUB).