Grub

From campisano.org
Jump to navigation Jump to search

Vademecum

Install

[root@host ~]$ grub
grub> help install
install: install [--stage2=STAGE2_FILE] [--force-lba] STAGE1 [d] DEVICE STAGE2 [ADDR] [p] [CONFIG_FILE] [REAL_CONFIG_FILE]
    Install STAGE1 on DEVICE, and install a blocklist for loading
    STAGE2 as a Stage 2. If the option `d' is present, the Stage 1
    will always look for the disk where STAGE2 was installed, rather
    than using the booting drive. The Stage 2 will be loaded at
    address ADDR, which will be determined automatically if you don't
    specify it. If the option `p' or CONFIG_FILE is present, then the
    first block of Stage 2 is patched with new values of the
    partition and name of the configuration file used by the true
    Stage 2 (for a Stage 1.5, this is the name of the true Stage 2)
    at boot time. If STAGE2 is a Stage 1.5 and REAL_CONFIG_FILE is
    present, then the Stage 2 CONFIG_FILE is patched with the
    configuration filename REAL_CONFIG_FILE. If the option
    `--force-lba' is specified, disable some sanity checks for LBA
    mode. If the option `--stage2' is specified, rewrite the Stage 2
    via your OS's filesystem instead of the raw device.

grub>

install file_stage1 [d] disco_di_avvio file_stage2 [p] [file_di_configurazione]

Questa è la sintassi già mostrata per il comando install. Si tratta di una forma semplificata rispetto a quella reale, che è sufficiente nelle situazioni più comuni. L'opzione d serve a stabilire la collocazione del file stage2 nel disco e nella partizione indicati, senza una relazione con il disco di avvio; l'opzione p è necessaria quasi sempre e serve a richiedere una serie di modifiche al file stage2 e anche al settore di avvio. Si veda eventualmente la documentazione originale per un dettaglio maggiore nell'uso di questo comando.


example:

  1. install (hd0,6)/grub/stage1 d (hd0) (hd0,6)/grub/stage2 p (hd0,6)/grub/menu.lst
  2. write the "install partition" number into the first sector of the stage2 (the "p" at the end)

install= (hd0,2)/boot/grub/stage1 (hd1) (hd1,a)/boot/grub/stage2 0x8000 p /grubdir/configfile


Installare Grub in in pendrive USB

# dopo aver creato una partizione e formattato la stessa,
# monto la partizione, copio componenti di Grub e smonto
[root@host ~]$ mount /dev/sdd1 /mnt/usb
[root@host ~]$ mkdir /mnt/grub
[root@host ~]$ cp -a /usr/lib/grub/i386-pc/* /mnt/usb/grub
[root@host ~]$ umount /dev/sdd1

# avvio grub
[root@host ~]$ grub

# indico come radice la partizione del device dove ho copiato grub
grub> root (hd3,0)
 Filesystem type is ext2fs, partition type 0x83

# installo i componenti di Grub nel device
grub> install /grub/stage1 (hd3) /grub/stage2 p /grub/menu.lst

# fine
grub> quit


Installare Grub in una immagine su file

# CREO L'IMMAGINE
[root@host ~]$ dd if=/dev/zero of=grub-initrd.raw bs=1024 count=2880

# FORMATTO L'IMMAGINE
[root@host ~]$ mkfs.ext3 -cFq -m0 grub-initrd.raw 

# MONTO L'IMMAGINE
[root@host ~]$ mount -o loop grub-initrd.raw tmp/

# CREO NELL'IMMAGINE LA CARTELLA PER GRUB
[root@host ~]$ mkdir -p tmp/boot/grub

# COPIO NELL'IMMAGINE I FILES DI GRUB
[root@host ~]$ cp /usr/share/grub/i386-pc/* tmp/boot/grub/

# SMONTO L'IMMAGINE DA DOVE L'AVEVO MONTATA
[root@host ~]$ umount tmp
NON SO PERCHE' MA FORSE SE IL PERCORSO E' TROPPO LUNGO IL COMANDO device DI GRUB NON FUNZIONA

# DUNQUE SPOSTO L'IMMAGINE APPENA CREATA SULLA DIRECTORY RADICE
[root@host ~]$ mv grub-initrd.raw /

# AVVIO IL BINARIO DI GRUB PER LINUX
[root@host ~]$ grub
Probing devices to guess BIOS drives. This may take a long time.
 
    GNU GRUB  version 0.94  (640K lower / 3072K upper memory)

 [ 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. ]

# MONTO LA MIA DIRECTORY RADICE
grub> root (hd0,7)
 Filesystem type is ext2fs, partition type 0x83

# DICO A GRUB DI CONSIDERARE LA MIA IMMAGINE COME IL DEVICE (fd1)
grub> device (fd1) /grub-initrd.raw 

# INSTALLO GLI STAGES DI GRUB NELL FINTO DEVICE
grub> install (fd1)/boot/grub/stage1 d (fd1) (fd1)/boot/grub/stage2 p (fd1)/boot/grub/menu.lst

# ESCO
grub> quit

# FINE
[root@host ~]$ mv /grub-initrd.raw ./
[root@host ~]$