Mostrando las entradas con la etiqueta recuperar grub. Mostrar todas las entradas
Mostrando las entradas con la etiqueta recuperar grub. Mostrar todas las entradas

11 feb 2012

Recovery / Reinstall GRUB CentOS - Scientific Linux - RHEL || Recuperar / Reinstalar GRUB en CentOS - Scientific Linux - RHEL

Well, the guide in CentOS wiki, and RHEL docs, about recovery / reinstall GRUB, does not work fine (and are incomplete), not in CentOS 6.x and SL6.x. After a windows reinstall or resize on the partition that contains /boot, the system may no boot properly. So, materials:

1) Live CD or DVD of Fedora 13 or 14 (not 15 or higher) or 1 live CD or DVD of CentOS 6.x or SL6.x
2) Patience

Steps:

1.- Insert the Live Media into CD-ROM Drive and boot it
2.- After the system is completely started, open a terminal and log in as root using su command
3.- Check what partition contain the /boot, i asume that /boot is into / partition, for /boot in other partition, go to point 4.

A) fdisk -l and see what partition is the / that contains the /boot, for example.

 Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      102400    7  HPFS/NTFS
Partition 1 does not end on cylinder boundary.
/dev/sda2              13        5100    40857600    7  HPFS/NTFS
/dev/sda3   *        5100        7081    15912960   83  Linux
/dev/sda4            7081       60802   431512576    5  Extended
/dev/sda5            7081       28047   168408064   83  Linux
/dev/sda6           28047       28302     2048000   82  Linux swap / Solaris
/dev/sda7           28302       60802   261053440    7  HPFS/NTFS

In the example case, /dev/sda3 is the / and /boot partition, so:

B) Execute step by step the next command

mount /dev/sda3 /mnt
mount --bind /dev /mnt/dev
mount --bind /dev/pts /mnt/dev/pts
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys

chroot /mnt

Done, the system has changed to /mnt live CD, DANGER, ANY CHANGE IN THE DISK IS THE REAL SYSTEM, NOT THE LIVE SYSTEM!!!

Reinstall grub in /dev/sda, executing:

grub-install --recheck /dev/sda && sync

Now is done, execute: shutdown -h now, remove the Live CD and start the system.

4.- In case that /boot is a separated partition to /, do this:

mount /dev/sda3 /mnt  (Assuming that /dev/sda3 is / root partition and NOT /boot)
mount --bind /dev /mnt/dev
mount --bind /dev/pts /mnt/dev/pts
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys

chroot /mnt

and NOW, mount /boot with:  mount /dev/sdaX /boot (when X is number of /boot partition)

grub-install --recheck /dev/sda && sync
Now is done, execute: shutdown -h now, remove the Live CD and start the system.


----------------------------------------------------------------------------------

Saludos, espero que les haya gustado / ayudado.

Greets, I hope you liked it or it has been useful

13 jun 2011

Recuperar grub2 teniendo en distintas particiones /boot y /

Me vi obligado a recuperar grub2 en una pc que tenia Linux Mint y le habian instalado Windows 7 luego, asi que borraron el MBR. Como encontre que todos los tuto estan mal, o solo hablan de tener una particion unica para todo Linux y muchos tenemos, como corresponde, el /boot apartado en ext2, decidi compartir como se hace correctamente. Esto es valido para Mint, Debian, Ubuntu, Fedora (usando grub legacy), ArchLinux, Gentoo, etc.

1)Booteamos en un LiveCD con Mint o Ubuntu o algo que posea grub2.
2)Ejecutamos esto al pie de la letra =>
-----------------------------------------------------------------------------
Abrimos un terminal
Ponemos sudo su para hacernos root si es que no lo somos.
fdisk -l para ver la particion de /boot y / en los /dev/sdaX

Luego:

mount /dev/sdaX /mnt (donde X es la particion /)

(Reemplazamos el /dev /dev/pts /proc y /sys por nuestro sistema virtual para luego hacerle un chroot y que quede completo)

mount --bind /dev /mnt/dev 
mount --bind /dev/pts  /mnt/dev/pts
mount --bind /proc /mnt/proc
mount --bind /sys  /mnt/sys

chroot /mnt   (cambiamos el / del live por nuestro / del disco ojo que todo lo que toquen cambiara el sistema instalado)

mount /dev/sdaX /boot   (donde X es el /boot real del disco, que previamente vimos con fdisk -l

grub-install --recheck /dev/sda (instalamos grub en el MBR)
update-grub2 (al estar en chroot mode, el / es nuestro sistema real, asi que genera un grub.cfg y detecta los sistemas Linux y Windows)

Resultado:

Generating grub.cfg ...
Found background image: linuxmint.png
Found Debian background: linuxmint.png
Found linux image: /boot/vmlinuz-2.6.38-2-686
Found initrd image: /boot/initrd.img-2.6.38-2-686
Found linux image: /boot/vmlinuz-2.6.32-5-686
Found initrd image: /boot/initrd.img-2.6.32-5-686
Found Windows 7 (loader) on /dev/sda1
done


Nota, para los que se pregunten que es --bind:

The bind mounts.
              Since Linux 2.4.0 it is possible to remount part of the file hierarchy somewhere else. The call is
                     mount --bind olddir newdir
              or shortoption
                     mount -B olddir newdir
              or fstab entry is:
                     /olddir /newdir none bind

              After  this  call  the same contents is accessible in two places.  One can also remount a single file (on a
              single file).

              This call attaches only (part of) a single filesystem, not possible submounts. The  entire  file  hierarchy
              including submounts is attached a second place using
                     mount --rbind olddir newdir
              or shortoption
                     mount -R olddir newdir

              Note  that the filesystem mount options will remain the same as those on the original mount point, and can‐
              not be changed by passing the -o option along with --bind/--rbind. The mount options can be  changed  by  a
              separate remount command, for example:

                     mount --bind olddir newdir
                     mount -o remount,ro newdir