Difference between revisions of "System resurrection"

From Funtoo Linux
Jump to: navigation, search
(Building binary packages)
 
(19 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Here is some ideas on how to resurrect a dead Funtoo system without reinstalling everything from scratch.   
+
Although it is always possible to resurrect a machine back to life by reinstalling it, it is not always suitable to reinstall from scratch. Sometimes the best approach is to try to repair, or "resurrect," a broken system so that is it fully functional again. This document will show you how to resurrect a broken Funtoo system without reinstalling everything from scratch.   
 +
 +
== Building binary packages ==
  
= Core package removal =
+
The best approach for critical system repair is to boot on a SystemRescueCD or other similar LiveCD, and use this as working platform to resurrect your system.
  
Several packages at the heart of your Funtoo system, these mainly are:
+
For creating binary packages, you can use any of the following for a ''source environment'':
  
* '''Python:''' As Portage (the software package management system used in Funtoo) is written in Python, the romoval of Python has obvious consequences;
+
* Use the most recent Funtoo stage3 for your architecture
* '''GNU Compiler collection:''' GNU/GCC is a compiler collection for various languages like C or C++. Many of your Funtoo packages are written in C and C++ and a dead compiler suite will prevent you to recompile those (GCC contains some bootstrap code that allows it to compile itself).
+
* If available, use a recent system backup (tar or cpio archive) or snapshot
* '''Binutils:''' GNU Binutils are several tools used behind the scene by the GNU Compiler collection (e.g. assembler, linker,  so on) to produce executables. No binutils leaves you with the impossibility to recompile the vast majority of Funtoo packages.
+
* '''LibC:''' LibC is a kind of software interface between a program launched by the user and the lower services provided by the system kernel. It is used by the huge majority of the binary executables present in a Funtoo box and its mostly common implementation used in the Funtoo Linux world is the GNU Lib C (glibc). '''This component is probably the most critical one because on removal or corruption most of the binary executables (such as the C compiler or the Python interpreter) will simply cease to function. '''
+
* '''Zlib:''' Zlib is a general compression library used by some Python bindings. In the case zlib is removed or corrupted, Portage will no longer be functional.
+
* '''wget:''' Wget is the tool used by portage to fetch source archives on a remote servers
+
* '''
+
  
== How to recover from core packages removal? ==
+
On a working Linux system, which can be either your broken system booted with a LiveCD, or any type of Linux system on your network with similar processor, you will want to build a chroot environment using the "source environment" you selected above, and use this as a platform for building binary packages to restore your system. Once these packages are created, they can be copied to your broken system and installed using the steps later in this document.
  
Although it is always possible to resurrect a machine back to life by reinstalling it, it is not always suitable to reinstall from scratch and sometimes the best is to try to fix a broken system even with some last resort options.
+
The binary package creation environment would typically be set up as follows:
  
* If your portage is totally knocked out, the only options you are to get binaries archives of pre-compiled core packages and untar them in your live arborescence (e.g. live VFS), notice the '''-C /''' at the end:
+
<pre>
 +
# install -d /mnt/rescue
 +
# tar xpvf backup.tar.bz2 -C /mnt/rescue
 +
# cp /etc/resolv.conf /mnt/rescue/etc
 +
# mount --bind /proc /mnt/rescue/proc
 +
# mount --bind /sys /mnt/rescue/sys
 +
# mount --bind /dev /mnt/rescue/dev
 +
# mount --bind /dev/pts /mnt/rescue/dev/pts
 +
# chroot /mnt/rescue
 +
# source /etc/profile
 +
# env-update
 +
</pre>
 +
 
 +
No matter of the way you jump in a functional Funtoo/Gentoo environment, the magic command to create a binary package archive once inside is to use the <tt>quickpkg</tt> command. <tt>quickpkg</tt> will capture the package in the exact form it is actually deployed on the environment and create an archive of it placed in <tt>/usr/portage/packages/<package-category>/<package-name>-<package-version>.tbz2</tt>.  
 +
 
 +
In the following example capture everything installed within the "source environment" that is related <tt>sys-devel/gcc</tt> (4.4.5 is present on the system) is captured in a single archive named gcc-4.4.5.tbz2 located in <tt>/usr/portage/packages/sys-devel</tt>:
  
 
<pre>
 
<pre>
# tar -jxvf /tmp/glibc-2.11.2-r2.tbz2 -C /
+
# quickpkg sys-devel/gcc
 
</pre>
 
</pre>
  
It is always recommended to use -t instead of -x to make sure no critical configuration file is overwritten in case of doubt.
+
If you need to recompile a package instead of archiving an already deployed version (and of course without installing it on your "source environment"), just do:
  
* If your portage is still functional, prefer to use it it is a good way to not bring in potential additional problems
+
<pre>
 +
# emerge --buildpkgonly sys-devel/gcc
 +
</pre>
  
== Building binary packages ==
+
== Restoring the binary packages on the broken system ==
  
At this point you have tree options:
+
There are a couple of methods that can be used to restore binary packages to a broken system.
  
* Boot on a SystemRescueCD (which is a Gentoo liveCD).
+
=== Chroot/Emerge Method ===
* Use a more or less recent system backup (e.g. snapshot if you use a BTRFS or ZFS filesystem or LVM voulume, a copy taken off-line of your hard drive...) and chroot there
+
* Lon on another functional machine of your network with similar architecture, it is of course possible to use a Gentoo host instead of a Funtoo host but again remember not all of packages are exactly the same. 
+
* Build a parallel stage3 chroot environment on the same machine with a stage 3 downloaded from a Funtoo mirror. Again, the downloaded stage must match your CPU and architecture and of course the Portage tree you are using (''stable'' or ''current'').
+
  
No matter of the way you jump in a functional Funtoo/Gentoo environment, the magic command to create a binary package archive is '''quickpkg'''. '''quickpkg''' will capture the package in the exact form it is actually deployed on the environment and create an archive of it placed in /usr/portage/packages/<package-category>/<package-name>-<package-version>.tbz2
+
This first approach can be used for lightly damaged systems that still have a functional Portage and to which you can still <tt>chroot</tt> and perform all basic Linux commands. To use this method, you would mount your broken system to <tt>/mnt/broken</tt> using steps similar to the way we set up <tt>/mnt/rescue</tt>, above.  
  
In the following example capture everything deployed by ''sys-devel/gcc''(4.4.5  is present on the system) and put the captured files in a single archive named gcc-4.4.5.tbz2 located in /usr/portage/packages/sys-devel/gcc.
+
Before or after chrooting, copy the binary packages created in the step above in the exact same location on your broken system (e.g. in <tt>/usr/portage/packages/'''sys-devel'''</tt> in the case of <tt>'''sys-devel'''/gcc</tt>).
 +
 
 +
Once chrooted inside your system, you will be able to merge your packages using <tt>emerge</tt> as follows:
  
 
<pre>
 
<pre>
# quickpkg sys-devel/gcc
+
# emerge -k  sys-devel/gcc
 
</pre>
 
</pre>
  
If you need to recompile a package instead of archiving an already deployed version (and of course without installing it on your "safety boat"), just do:
+
=== Tbz2 Extract Method ===
 +
 
 +
This alternate method for installing binary packages is simpler and does not require the use of the <tt>chroot</tt> command. To prepare for using this approach, you just need to mount all key filesystems to <tt>/mnt/broken</tt> as follows -- and bind mounts are not necessary:
  
 
<pre>
 
<pre>
# emerge --buildpkgonly  sys-devel/gcc
+
# install -d /mnt/broken
 +
# mount /dev/sdaX /mnt/broken
 +
# mount /dev/sdaY /mnt/broken/usr
 
</pre>
 
</pre>
  
 +
Then, use the following commands to extract the .tbz2 archive to your broken filesystem that you mounted at <tt>/mnt/broken</tt>:
  
== Restoring the
+
<pre>
 +
# tar xjpvf gcc-4.4.5.tbz2 -C /mnt/broken
 +
</pre>
  
== I don't have pre-packages binaries what can I do? ==
+
You will see a note about the trailing garbage at the end of the file being ignored. This is normal -- tar is ignoring the Portage .tbz2 metadata that is tacked on to the end of the file.
  
In last resort, one the Gentoo developer setup a public server known as ''tinderbox'' with various pre-compiled binary packages for various platforms (x86, AMD64 and SPARC64 amongst others) ready for deployment. They act as kind of spare tires, one everything is in place it is recommended to recompile @system:
+
At this point, you can set up bind mounts (see <tt>/mnt/rescue</tt> example earlier in this document for those steps), <tt>chroot</tt> inside <tt>/mnt/broken</tt>, and perform a few tests to determine if your issue has been resolved.
  
<pre>
+
= Fixing broken portage =
# emerge -e @system
+
sometimes <tt>sys-apps/portage</tt> may fail and the above <tt>binpkg</tt> mentioned way to ressurect system will not work because of portage being broken itself. To fix portage manually the following steps required:
</pre>
+
<console>
 +
# cd /tmp
 +
tmp # wget https://www.github.com/funtoo/portage-funtoo/tarball/funtoo-2.3.3-r4
 +
tmp # tar xf funtoo-2.3.3-r4
 +
tmp # cd funtoo-portage-funtoo-84fe4a7
 +
funtoo-portage-funtoo-84fe4a7 # rm -rf /usr/lib/portage/*
 +
funtoo-portage-funtoo-84fe4a7 # cp -a bin pym /usr/lib/portage/
 +
funtoo-portage-funtoo-84fe4a7 # ln -s /usr/lib/portage/bin/emerge /usr/bin/emerge
 +
</console>
 +
This will back a working portage again. To ensure everything is consistent re-emerge portage itself immediately.
 +
<console>
 +
# emerge portage </console>
 +
File collision warning, if any, can be skipped at this point.
 +
= Critical System Packages =
 +
 
 +
 
 +
Several packages at the heart of your Funtoo system, these mainly are:
 +
 
 +
{| {{Table}}
 +
|-
 +
!Component
 +
!Package
 +
!Functional role
 +
|-
 +
|GNU Binutils
 +
|sys-devel/binutils
 +
|Binutils are a set a tools (linker, assembler...) used behind the scene by the GNU Compiler Collection to produce executable files.
 +
|-
 +
|GNU Compiler collection (GCC)
 +
|sys-devel/gcc
 +
|GCC is a collection of compilers for several languages (FORTRAN, Java, C and C++, plus some libraries like the Standard Template Library or ''STL''). A wide spectrum of software in a Funtoo system is written in C/C++.
 +
|-
 +
|C Library
 +
|sys-libs/glibc
 +
|The C library contains an implementation of a wide range of commonly needed functionalities like memory allocation, strings manipulation, I/O operations and so on. It is maybe one of the most critical system components as nearly everything on a Funtoo system depends on this component (including the Python interpreter which executes the vairous Python scripts at the heart of the Funtoo core utilities and package management system).
 +
|-
 +
|Z library
 +
|sys-libs/zlib
 +
|This library contain several lossless compression/decompression routines.It is used by many other components on a Funtoo system like the bzip2/bunzip2 commands (app-arch/bzip2) for example (xz archive utilities depends on another standalone set of libraries).
 +
|-
 +
|Python
 +
|dev-lang/python
 +
|The Python interpreter is the heart of Portage as is written in Python (the same is also true for various second line utilities).
 +
|}
  
 
= Various weird issues =
 
= Various weird issues =
Line 68: Line 131:
 
'''P2:''' Same problem as described in P1 but I use another machine on my network or a public mirror on the Internet  <br>
 
'''P2:''' Same problem as described in P1 but I use another machine on my network or a public mirror on the Internet  <br>
 
'''S2:''' See the solution given in S1 but with providing the IP of the machine you are downloading for.
 
'''S2:''' See the solution given in S1 but with providing the IP of the machine you are downloading for.
 +
 +
[[Category:Internals]]
 +
[[Category:Portage]]
 +
[[Category:HOWTO]]

Latest revision as of 19:10, 21 April 2012

Although it is always possible to resurrect a machine back to life by reinstalling it, it is not always suitable to reinstall from scratch. Sometimes the best approach is to try to repair, or "resurrect," a broken system so that is it fully functional again. This document will show you how to resurrect a broken Funtoo system without reinstalling everything from scratch.

Contents

[edit] Building binary packages

The best approach for critical system repair is to boot on a SystemRescueCD or other similar LiveCD, and use this as working platform to resurrect your system.

For creating binary packages, you can use any of the following for a source environment:

  • Use the most recent Funtoo stage3 for your architecture
  • If available, use a recent system backup (tar or cpio archive) or snapshot

On a working Linux system, which can be either your broken system booted with a LiveCD, or any type of Linux system on your network with similar processor, you will want to build a chroot environment using the "source environment" you selected above, and use this as a platform for building binary packages to restore your system. Once these packages are created, they can be copied to your broken system and installed using the steps later in this document.

The binary package creation environment would typically be set up as follows:

# install -d /mnt/rescue
# tar xpvf backup.tar.bz2 -C /mnt/rescue
# cp /etc/resolv.conf /mnt/rescue/etc
# mount --bind /proc /mnt/rescue/proc
# mount --bind /sys /mnt/rescue/sys
# mount --bind /dev /mnt/rescue/dev
# mount --bind /dev/pts /mnt/rescue/dev/pts
# chroot /mnt/rescue
# source /etc/profile
# env-update

No matter of the way you jump in a functional Funtoo/Gentoo environment, the magic command to create a binary package archive once inside is to use the quickpkg command. quickpkg will capture the package in the exact form it is actually deployed on the environment and create an archive of it placed in /usr/portage/packages/<package-category>/<package-name>-<package-version>.tbz2.

In the following example capture everything installed within the "source environment" that is related sys-devel/gcc (4.4.5 is present on the system) is captured in a single archive named gcc-4.4.5.tbz2 located in /usr/portage/packages/sys-devel:

# quickpkg sys-devel/gcc

If you need to recompile a package instead of archiving an already deployed version (and of course without installing it on your "source environment"), just do:

# emerge --buildpkgonly sys-devel/gcc

[edit] Restoring the binary packages on the broken system

There are a couple of methods that can be used to restore binary packages to a broken system.

[edit] Chroot/Emerge Method

This first approach can be used for lightly damaged systems that still have a functional Portage and to which you can still chroot and perform all basic Linux commands. To use this method, you would mount your broken system to /mnt/broken using steps similar to the way we set up /mnt/rescue, above.

Before or after chrooting, copy the binary packages created in the step above in the exact same location on your broken system (e.g. in /usr/portage/packages/sys-devel in the case of sys-devel/gcc).

Once chrooted inside your system, you will be able to merge your packages using emerge as follows:

# emerge -k  sys-devel/gcc

[edit] Tbz2 Extract Method

This alternate method for installing binary packages is simpler and does not require the use of the chroot command. To prepare for using this approach, you just need to mount all key filesystems to /mnt/broken as follows -- and bind mounts are not necessary:

# install -d /mnt/broken
# mount /dev/sdaX /mnt/broken
# mount /dev/sdaY /mnt/broken/usr

Then, use the following commands to extract the .tbz2 archive to your broken filesystem that you mounted at /mnt/broken:

# tar xjpvf gcc-4.4.5.tbz2 -C /mnt/broken

You will see a note about the trailing garbage at the end of the file being ignored. This is normal -- tar is ignoring the Portage .tbz2 metadata that is tacked on to the end of the file.

At this point, you can set up bind mounts (see /mnt/rescue example earlier in this document for those steps), chroot inside /mnt/broken, and perform a few tests to determine if your issue has been resolved.

[edit] Fixing broken portage

sometimes sys-apps/portage may fail and the above binpkg mentioned way to ressurect system will not work because of portage being broken itself. To fix portage manually the following steps required:

# cd /tmp
tmp # wget https://www.github.com/funtoo/portage-funtoo/tarball/funtoo-2.3.3-r4
tmp # tar xf funtoo-2.3.3-r4
tmp # cd funtoo-portage-funtoo-84fe4a7
funtoo-portage-funtoo-84fe4a7 # rm -rf /usr/lib/portage/*
funtoo-portage-funtoo-84fe4a7 # cp -a bin pym /usr/lib/portage/
funtoo-portage-funtoo-84fe4a7 # ln -s /usr/lib/portage/bin/emerge /usr/bin/emerge

This will back a working portage again. To ensure everything is consistent re-emerge portage itself immediately.

# emerge portage 

File collision warning, if any, can be skipped at this point.

[edit] Critical System Packages

Several packages at the heart of your Funtoo system, these mainly are:

Component Package Functional role
GNU Binutils sys-devel/binutils Binutils are a set a tools (linker, assembler...) used behind the scene by the GNU Compiler Collection to produce executable files.
GNU Compiler collection (GCC) sys-devel/gcc GCC is a collection of compilers for several languages (FORTRAN, Java, C and C++, plus some libraries like the Standard Template Library or STL). A wide spectrum of software in a Funtoo system is written in C/C++.
C Library sys-libs/glibc The C library contains an implementation of a wide range of commonly needed functionalities like memory allocation, strings manipulation, I/O operations and so on. It is maybe one of the most critical system components as nearly everything on a Funtoo system depends on this component (including the Python interpreter which executes the vairous Python scripts at the heart of the Funtoo core utilities and package management system).
Z library sys-libs/zlib This library contain several lossless compression/decompression routines.It is used by many other components on a Funtoo system like the bzip2/bunzip2 commands (app-arch/bzip2) for example (xz archive utilities depends on another standalone set of libraries).
Python dev-lang/python The Python interpreter is the heart of Portage as is written in Python (the same is also true for various second line utilities).

[edit] Various weird issues

P1: I have a local distfiles mirror and wget complains about not being able to resolve 'localhost'.
S1: libnss (which handles name resolution) is probably damaged or suffers of inconsistencies, in your /etc/make.conf, change 'localhost' in GENTOO_MIRRORS for 127.0.0.1 (IPv4) or ::1 (IPv6)

P2: Same problem as described in P1 but I use another machine on my network or a public mirror on the Internet
S2: See the solution given in S1 but with providing the IP of the machine you are downloading for.

Personal tools
Namespaces

Variants
Actions
Categories
Toolbox
Stuff