# Mini-HOW-TO: Recover a broken / partial Gentoo installation

## Helena

Sometimes an error occurs while installing Gentoo, or you forget to install a boot loader before you reboot. At other times your partitions get messed up, or you've done a backup of an entire installation and after restoring partitions you find that GRUB is unable to boot.

In such a situation, you would like to go into your (partial) installation, repair things and get working. Fortunately this is possible and even easy. Thanks to Linux' simple yet powerful architecture there are even multiple ways to do this. However, I wil describe only 1 method, which use the Gentoo LiveCD, since that will probably always be available.

To use the Live CD to boot into a partial or non-booting Gentoo Linux installation, perform the following steps:

1. Boot your computer from the LiveCD

Any version that boots on that computer will do, even the basic CD if you don't need the stage tarballs. However, I recommend using the same LIveCD that was used for the installation, this will be much easier generally. Of course, you ,may have to specify certain LiveCD parameters, likeacpi

doataraid

...Consult the installation handbook http://www.gentoo.org/doc/en/handbook/handbook.xml?part=1 for information.

2. Mount the partitions you want to use

Normally this would be achieved by

```
mount /dev/hdax /mnt/gentoo

mount /dev/hday /mnt/gentoo/boot

swapon /dev/hdaz]

mount -t proc none  /mnt/gentoo/proc

```

Replace x, y and z in the above command lines with the correct numbers, of course. If your network installation was not finished you may have to insert another

```
cp /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
```

3. Enter the installation

 with 

```
cd /mnt/gentoo

chroot /mnt/gentoo /bin/bash 

env-update

source /etc/profile
```

From here you may resume the installation at any point.

----------

## scorchen

and this actually works quite well. I had to do this exact thing a few days ago.

----------

## tristure

Thanks for these useful tips!

I wish I had read such a post one or two months ago... Could have saved time!

----------

## humpback

Nice information. If you could extend this info on how to recover from a broken system i would move it to the Documentation, Tips and Tricks.

Also, the Gentoo Live cd is a very good recover tool. I have used it to fix problems in many Linux (non Gentoo) systems.

----------

## ett_gramse_nap

Ah! I was just wondering about this... Thanks!

----------

## D. M. P. inc

i have a few time in my hand so ill finish up on behalf of Helena work. ill start it again due to somepoeple get confuse fast. 

 *Quote:*   

> Sometimes an error occurs while installing Gentoo, or you forget to install a boot loader before you reboot. At other times your partitions get messed up, or you've done a backup of an entire installation and after restoring partitions you find that GRUB is unable to boot.
> 
> In such a situation, you would like to go into your (partial) installation, repair things and get working. Fortunately this is possible and even easy. Thanks to Linux' simple yet powerful architecture there are even multiple ways to do this. However, I wil describe only 1 method, which use the Gentoo LiveCD, since that will probably always be available.
> 
> To use the Live CD to boot into a partial or non-booting Gentoo Linux installation, perform the following steps:

 

HOW TO Fix Basic Gentoo Installation Errors Using  Gentoo LiveCD :

1st Step : 

Boot your computer from the LiveCD

Any version that boots on that computer will do, even the basic CD if you don't need the stage tarballs. However, I recommend using the same LIveCD that was used for the installation, this will be much easier generally. Of course, you ,may have to specify certain LiveCD parameters, like

      acpi

      doataraid

      ...

Consult the installation handbook http://www.gentoo.org/doc/en/handbook/handbook.xml?part=1 for information. 

2nd Step : 

Mount the partitions you want to use

Normally this would be achieved by

```

mount /dev/hdax /mnt/gentoo

mount /dev/hday /mnt/gentoo/boot

swapon /dev/hdaz]

mount -t proc none  /mnt/gentoo/proc

```

Replace x, y and z in the above command lines with the correct numbers, of course. If your network installation was not finished you may have to insert another

```

cp /etc/resolv.conf /mnt/gentoo/etc/resolv.conf

```

3rd Step :

Enter the installation with

```

cd /mnt/gentoo

chroot /mnt/gentoo /bin/bash

env-update

source /etc/profile

```

From here just look for Errors You Got

- ERROR ON : /etc/fstab

```
nano -w /etc/fstab
```

```

/dev/BOOT           /boot       ext2        noauto,noatime  1 2

/dev/ROOT           /           reiserfs    noatime         0 1

/dev/SWAP           none        swap        sw              0 0

/dev/cdroms/cdrom0  /mnt/cdrom  iso9660     noauto,ro,user  0 0

none                /proc       proc        defaults        0 0

```

- ERROR ON : GRUB 

just re-emerge grub to make sure your doing it right

```

# emerge -k grub

# grub

```

 Code listing 23.2: GRUB on the MBR  *Quote:*   

> this is if u have only gentoo on ur system

 

```

grub> root (hd0,0) (Your boot partition)

grub> setup (hd0) (Where the boot record is installed; here, it is the MBR)

```

 Code listing 23.3: GRUB not on the MBR  *Quote:*   

> this is if u have another operating system

 

Alternatively, if you wanted to install the bootloader somewhere other than the MBR:

```
grub> root (hd0,0) (Your boot partition)

grub> setup (hd0,4) (Where the boot record is installed; here it is /dev/hda5)

grub> quit

```

- ERROR ON : grub.conf 

```
# nano -w /boot/grub/grub.conf
```

```

 Code listing 23.4: grub.conf for GRUB

default 0

timeout 30

splashimage=(hd0,0)/boot/grub/splash.xpm.gz

# If you compiled your own kernel, use something like this:

title=My example Gentoo Linux

root (hd0,0) 

kernel (hd0,0)/boot/bzImage root=/dev/hda3 

# If you're using genkernel, use something like this instead:

title=My example Gentoo Linux (genkernel)

root (hd0,0)

kernel (hd0,0)/boot/kernel-KV root=/dev/hda3

initrd (hd0,0)/boot/initrd-KV

# Below needed only for people who dual-boot

title=Windows XP

root (hd0,5) 

chainloader (hd0,5)+1

```

-  ERROR ON :  Kernel 

 Code listing 16.1: Emerging Kernel Sources

```

# emerge -k gentoo-sources

```

 Code listing 16.2: Emerging genkernel

```

# emerge -k genkernel

```

```

If you're using genkernel 1.2 (included in the 1.4-20030803 x86/i686 GRP set), use the following:

# genkernel gentoo-sources

If you're using genkernel 1.4 or newer, there's no need to specify a kernel:

# genkernel

```

 Code listing 16.5: Configuring the Linux Kernel  *Quote:*   

> Manual Configuration

 

```

# cd /usr/src/linux

# make menuconfig

```

 Code listing 16.6: make menuconfig options

```

Code maturity level options --->

[*] Prompt for development and/or incomplete code/drivers"

(You need this to enable some of the options below)

...

File systems --->

<*> Reiserfs support

(Only needed if you are using reiserfs)

... 

<*> Ext3 journalling file system support

(Only needed if you are using ext3)

...

[*] Virtual memory file system support (former shm fs)

(Required for Gentoo Linux)

...

<*> JFS filesystem support

(Only needed if you are using JFS)

...

[*] /proc file system support

(Required for Gentoo Linux)

[*] /dev file system support (EXPERIMENTAL)

[*]   Automatically mount at boot          

(Required for Gentoo Linux)

[ ] /dev/pts file system for Unix98 PTYs

(Uncheck this, it is not needed unless you use a 2.6 kernel)

...

<*> Second extended fs support

(Only needed if you are using ext2)

...

<*> XFS filesystem support

(Only needed if you are using XFS)

```

 Code listing 16.7: Compiling and Installing the kernel  *Quote:*   

> Do This After genkernell or even manual config of kernel 

 

```

# make dep && make clean bzImage modules modules_install

# cp /usr/src/linux/arch/i386/boot/bzImage /boot

```

hope this helps all

----------

## ian!

Moved to 'Documentation, Tips & Tricks'.

----------

## Braempje

Don't forget mounting dev for non-livecd installers. This guide is awsome, I just posted a bug last night regarding this information   :Very Happy: 

----------

## Helena

Thanks D. M. P. inc for your contribution. I will update the guide later, using your work and maybe some others'; I also want to correct a few minor errors. I feel something useful work is being done!  :Very Happy: 

----------

## viperlin

although i knew this i guess it wasn't as pbvious to everyone else, so thanks for giving the community this howto  :Smile: 

----------

