注意:

The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.

Difference between revisions of "System resurrection"

From Funtoo
Jump to navigation Jump to search
 
(13 intermediate revisions by 2 users not shown)
Line 27: Line 27:
</console>
</console>


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>.  
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 {{c|quickpkg}} command. {{c|quickpkg}} will capture the package in the exact form it is actually deployed on the environment and create an archive of it placed in {{c|/var/cache/portage/packages/<package-category>/<package-name>-<package-version>.tbz2}}.  


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>:
In the following example capture everything installed within the "source environment" that is related {{c|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 {{c|/var/cache/portage/packages/sys-devel}}:


<console>
<console>
Line 47: Line 47:
=== Chroot/Emerge Method ===
=== 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 <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.  
This first approach can be used for lightly damaged systems that still have a functional Portage and to which you can still {{c|chroot}} and perform all basic Linux commands. To use this method, you would mount your broken system to {{c|/mnt/broken}} using steps similar to the way we set up {{c|/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 <tt>/usr/portage/packages/'''sys-devel'''</tt> in the case of <tt>'''sys-devel'''/gcc</tt>).
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 {{c|/var/cache/portage/packages/'''sys-devel'''}} in the case of {{c|'''sys-devel'''/gcc}}.


Once chrooted inside your system, you will be able to merge your packages using <tt>emerge</tt> as follows:
Once chrooted inside your system, you will be able to merge your packages using {{c|emerge}} as follows:


<console>
<console>
Line 59: Line 59:
=== Tbz2 Extract Method ===
=== 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:
This alternate method for installing binary packages is simpler and does not require the use of the {{c|chroot}} command. To prepare for using this approach, you just need to mount all key filesystems to {{c|/mnt/broken}} as follows -- and bind mounts are not necessary:


<console>
<console>
Line 67: Line 67:
</console>
</console>


Then, use the following commands to extract the .tbz2 archive to your broken filesystem that you mounted at <tt>/mnt/broken</tt>:
Then, use the following commands to extract the .tbz2 archive to your broken filesystem that you mounted at {{c|/mnt/broken}}:


<console>
<console>
Line 75: Line 75:
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.
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 <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.
At this point, you can set up bind mounts (see {{c|/mnt/rescue}} example earlier in this document for those steps), {{c|chroot}} inside {{c|/mnt/broken}}, and perform a few tests to determine if your issue has been resolved.


== Fixing broken portage ==
== Fixing broken portage ==
Line 82: Line 82:
<console>
<console>
# ##i##cd /tmp
# ##i##cd /tmp
# ##i##wget http://distfiles.gentoo.org/distfiles/portage-2.2.26.tar.bz2
# ##i##wget http://distfiles.gentoo.org/distfiles/portage-2.3.41.tar.bz2
# ##i##tar -xjf portage-2.2.26.tar.bz2
# ##i##tar -xjf portage-2.3.41.tar.bz2
# ##i##rm -fr /usr/lib/portage /usr/lib*/python*/site-packages/{_emerge,portage,repoman}
# ##i##rm -fr /usr/lib/portage /usr/lib*/python*/site-packages/{_emerge,portage,repoman}
# ##i##/tmp/portage-2.2.26/bin/emerge -atv1 sys-apps/portage
# ##i##/tmp/portage-2.3.41/bin/emerge -atv1 sys-apps/portage
</console>
</console>


Line 92: Line 92:
<console>
<console>
# ##i##cd /tmp
# ##i##cd /tmp
# ##i##wget https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tar.xz
# ##i##wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz
# ##i##tar -xJf Python-3.5.0.tar.xz
# ##i##tar -xJf Python-3.6.6.tar.xz
# ##i##cd Python-3.5.0
# ##i##cd Python-3.6.6
# ##i##./configure --enable-shared --with-system-expat --with-system-ffi
# ##i##./configure --enable-shared --with-fpectl --with-system-expat --with-system-ffi
# ##i##make
# ##i##make
# ##i##cd /tmp
# ##i##cd /tmp
# ##i##wget http://distfiles.gentoo.org/distfiles/portage-2.2.26.tar.bz2
# ##i##wget http://distfiles.gentoo.org/distfiles/portage-2.3.41.tar.bz2
# ##i##tar xvf portage-2.2.26.tar.bz2
# ##i##tar xvf portage-2.3.41.tar.bz2
# ##i##LD_LIBRARY_PATH="/tmp/Python-3.5.0" /tmp/Python-3.5.0/python /tmp/portage-2.2.26/bin/emerge -atv1 dev-lang/python sys-apps/portage
# ##i##rm -fr /usr/lib/portage /usr/lib*/python*/site-packages/{_emerge,portage,repoman}
# ##i##LD_LIBRARY_PATH="/tmp/Python-3.6.6" /tmp/Python-3.6.6/python /tmp/portage-2.3.41/bin/emerge -atv1 dev-lang/python sys-apps/portage
</console>
File collision warning, if any, can be skipped at this point. A temporary files can be removed from /tmp when completed.
 
= Critical System Packages =
 
 
Several packages at the heart of your Funtoo system, these mainly are:
 
{| {{Table}}
|-
!Component
!Package
!Functional role
|-
|GNU Binutils
|{{Package|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)
|{{Package|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
|{{Package|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
|{{Package|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
|{{Package|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 =
 
'''P1:''' I have a local distfiles mirror and wget complains about not being able to resolve 'localhost'. <br>
'''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)<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.
 
[[Category:Internals]]
[[Category:Portage]]
[[Category:HOWTO]]
[[Category:pt_BR]]

Latest revision as of 16:20, August 16, 2018

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

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:

root # install -d /mnt/rescue
root # tar xpvf backup.tar.bz2 -C /mnt/rescue
root # cp /etc/resolv.conf /mnt/rescue/etc
root # mount --bind /proc /mnt/rescue/proc
root # mount --bind /sys /mnt/rescue/sys
root # mount --bind /dev /mnt/rescue/dev
root # mount --bind /dev/pts /mnt/rescue/dev/pts
root # chroot /mnt/rescue
root # source /etc/profile
root # 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 /var/cache/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 /var/cache/portage/packages/sys-devel:

root # 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:

root # emerge --buildpkgonly sys-devel/gcc

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.

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 /var/cache/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:

root # emerge -k  sys-devel/gcc

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:

root # install -d /mnt/broken
root # mount /dev/sdaX /mnt/broken
root # 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:

root # 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.

Fixing broken portage

Broken portage only

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

root # cd /tmp
root # wget http://distfiles.gentoo.org/distfiles/portage-2.3.41.tar.bz2
root # tar -xjf portage-2.3.41.tar.bz2
root # rm -fr /usr/lib/portage /usr/lib*/python*/site-packages/{_emerge,portage,repoman}
root # /tmp/portage-2.3.41/bin/emerge -atv1 sys-apps/portage

Broken python and portage

A more extreme case, when both python and portage are broken. It's hard to determine if they really both broken, so this method suitable for updating a very old boxes, with dated python and portage versions.

root # cd /tmp
root # wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tar.xz
root # tar -xJf Python-3.6.6.tar.xz
root # cd Python-3.6.6
root # ./configure --enable-shared --with-fpectl --with-system-expat --with-system-ffi
root # make
root # cd /tmp
root # wget http://distfiles.gentoo.org/distfiles/portage-2.3.41.tar.bz2
root # tar xvf portage-2.3.41.tar.bz2
root # rm -fr /usr/lib/portage /usr/lib*/python*/site-packages/{_emerge,portage,repoman}
root # LD_LIBRARY_PATH="/tmp/Python-3.6.6" /tmp/Python-3.6.6/python /tmp/portage-2.3.41/bin/emerge -atv1 dev-lang/python sys-apps/portage

File collision warning, if any, can be skipped at this point. A temporary files can be removed from /tmp when completed.

Critical System Packages

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

Component Package Functional role
GNU Binutils No results 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) No results 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 No results 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 No results 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 No results 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

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.