This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

Fix My Gentoo

From Gentoo Wiki (test)
Jump to:navigation Jump to:search

Preamble

Introduction

This guide is something I've posted on the forums several times in response to users posting about nothing works. If your gcc is broken after a --depclean, this guide is not for you. You almost certainly need gcc-config. Be more careful in future.

This guide is for rescuing your install when you can't chroot in, almost nothing seems to work but you have determined that you need some binary packages to fix your system.

Its actually very difficult to break Gentoo so badly, it can't be fixed.

Overview

You need some binary packages to fix your Gentoo. You might find them on a BINHOST or tinderbox on the web but they are unlikely to be built for your system, with your USE and your CCFLAGS. This guide shows you how to make your own binary packages to use to fix your own system. You will not need another system, a spare partition or even another install.

Prerequsites

You need

  • A working internet connection.
  • A way to boot your broken box, e.g. System Rescue CD, if it won't boot
  • About 20G of free space on your broken install. 5G may do, depending on what you need to build.

Summary

As the bootable install is not working and we need a working install to build binary packages, we need another install. This install need not be bootable. Its sufficient to be able to chroot into it and run emerge. This rescue install will share some elements with the main install that is to be rescued. It saves space and makes thing easier in the final steps.

Getting Started

Terminology

/mnt/gentoo Mount your own broken install here.

/mnt/gentoo/home/rescue The new rescue install, it can be anywhere but it needs to be on a hard disk.

The Rescue Install

Mount your broken install at /mnt/gentoo so we can use its hard drive space and its /usr/portage

Make a directory at /mnt/gentoo/home/rescue or wherever you have some free space.

root #mkdir /mnt/gentoo/home/rescue

Follow the handbook to fetch a stage3 tarball and untar it to /mnt/gentoo/home/rescue.

Do not get a portage snapshot, we will use the one in the main install.

Follow the handbook for all the odds and ends, like copying /etc/resolv.conf

Mount /dev and friends in /mnt/gentoo/home/rescue just as if you were doing a new install but do not chroot yet.

Bind mount /mnt/gentoo/usr/portage onto /mnt/gentoo/home/rescue/usr/portage.

root #mount -o bind /mnt/gentoo/usr/portage /mnt/gentoo/home/rescue/usr/portage

This makes your tree and distfiles available to the rescue system.

Copy over /mnt/gentoo/etc/portage to /mnt/home/rescue/etc/portage

root #cp -r /mnt/gentoo/etc/portage /mnt/gentoo/home/rescue/etc/portage

Now the rescue install has all your own settings too.

Change Root

Just like the handbook says but into /mnt/gentoo/home/rescue

Edit /etc/portage/make.conf

Now we are in the new working chroot, we need to tell portage we want it to save binary packages of everything we build.

Edit /etc/portage/make.conf by adding buildpkg to the FEATURES statement. This causes portage to save binary tarballs of every package built to /usr/portaage/packages.

Note
Due to the bind mount of /mnt/gentoo/usr/portage, /usr/portage/packages will exist in your main install too
Warning
Do not emerge --sync. You need packages that match your installed system

Building Packages

gcc C++ ABI Version

Important
C++ packages must be built with the correct C++ ABI.

Its possible that the rescue install and the main install differ. In which case, the first step is to upgrade the rescue install to gcc-5.x.

root #/usr/portage/scripts/bootstrap.sh

will rebuild the entire toolchain. That's the stage1 of a stage1 install.

When that command completes, use gcc-config to select the correct gcc.

Quick Package

Maybe the package you need in a part of the stage3, so you don't actually need to build it. The quickpkg tool can make binary packages of things already installed.

Take care with quickpkg, it either drops configuration files or copies them in their current state from the install. You may not want that. Building pristine packages is safer and there may be the gcc C++ ABI Version issue to avoid too.

Emerge

Emerge will just work. Build something small as a test then check that the package has appeared in /usr/portage/packages

More Packages

emerge whatever you need. You don't need to do it all in one go. /home/rescue will stay around until you delete it and its only a chroot away. When you come back, don't forget the /usr/portage bind mount.

Installing Binary Packages

How you install binary packages depends on what is broken. The alternatives are presented in increasing order of risk.

Using Emerge

This requires that you can chroot into the install to be rescued. If you have managed to remove a part of your toolchain, this should work for you.

root #emerge -K <package/atom>

will either install the binary tarball and its dependencies or fail if the binaries cannot be found.

Using tar

So you can't chroot in, emerge is not an option. Maybe you removed glibc and you don't have a statically linked busybox?

Each binary package is like a single package stage3. It has some extra information on the end that portage uses, which will provoke a warning from tar. This can be safely ignored.

Warning
there is no safety net, tar will just spray files all over your filesystem.

tar Step by Step

For safetys sake, unmount the rescue install at /mnt/gentoo/home/rescue

root #umount /mnt/gentoo/home/rescue

You may need to unmount all the things mounted inside /mnt/gentoo/home/rescue first.

Sanity Checks

Before you issue the tar command

  • Your install is mounted at /mnt/gentoo
  • You understand the -xpf and -C options to tar - review
root #man tar
The tar command
root #tar --xattrs -xpf /mnt/gentoo/usr/portage/packages/<package/atom> -C /mnt/gentoo

This tells tar to extract, preserving permissions, the file /mnt/gentoo/usr/portage/packages/<package/atom> and Change directory to /mnt/gentoo before it does anything else.

In fact, the input file name above is not correct. The full path to the tarball is required. Tab completion helps a lot.

Warning
the -p option is essential. Without it, tar will work, the files will be installed but execute permissions will be dropped
Warning
do check the -C /mnt/gentoo - thats where all the output files will be sent
Note
tar will work out the compression for itself, so the -j option is not required

Nervous users can add the -v option to tar.

Tidying Up

Once the damage is fixed, you can delete /home/rescue, or keep it around for next time.

If you have the space, you may want to add buildpkg to your FEATURES as a regular thing. Then you will have the tarballs you need for rescuing your system already.

Both /usr/portage/distfiles and /usr/portage/packages will grow without limit. Run eclean from time to time to prune them.