Restoring After Deleting Libraries

Whilst performing the rescue but I had a command line login so all was (relatively) good. A search of the Gentoo Forums lead to a really useful thread with a solution from none other than the hero of Gentoo Forums NeddySeagoon who explained that a stage3 chrooted to with your existing /usr/portage as per the Gentoo Handbook and from here it is, after having synced the portage tree emerge --sync, possible to install any package and build a binpkg that is saved under /usr/portage/packages. These can then be installed under the normal non-chroot environment using emerge -K =category/package-version, or in the case of gcc you treat the created package as a mini Stage3 tarball and extract it to /.

Here are the exact steps I took after hosing my system to recover it.

Download a Stage 3

Download the latest stage3, I use a no-multib profile so grabbed that.

cd /tmp
wget http://distfiles.gentoo.org/releases/amd64/autobuilds/20190605T214501Z/stage3-amd64-nomultilib-20190605T214501Z.tar.xz

Make a mount point for stage3 and extract

mkdir /mnt/stage3
mv /tmp/stage3-amd64-nomultilib-20190605T214501Z.tar.xz /mnt/stage3/.
cd /mnt/stage3
tar xvf stage3-amd64-nomultilib-20190605T214501Z.tar.xz

Copy DNS

cp --dereference /etc/resolv.conf /mnt/stage3/etc/

Mount /proc and /dev

mount --types proc /proc /mnt/stage3/proc
mount --rbind /sys /mnt/stage3/sys
mount --make-rslave /mnt/stage3/sys
mount --rbind /dev /mnt/stage3/dev
mount --make-rslave /mnt/stage3/dev 

Mount bind additional locations

mkdir -p /mnt/stage3/var/cache/distfiles /mnt/stage3/var/db/repos /mnt/stage3/var/cache/binpkgs
mount -o bind /var/db/repos/gentoo /mnt/stage3/var/db/repos/gentoo
# mount -o bind /var/cache/distfiles /mnt/stage3/var/cache/distfiles
mount -o bind /var/cache/binpkgs /mnt/stage3/var/cache/binpkgs

Copy your /etc to /mnt/stage3

cp -r /etc/portage /mnt/stage3/etc/portage

chroot to stage3

chroot /mnt/stage3 /bin/bash
source /etc/profile
export PS1="(stage3) ${PS1}"

Modified ACCEPT_KEYWORDS

On my system I run ACCEPT_KEYWORDS="~amd64 so I added the line to /etc/portage/make.conf (in the chrooted environment)

echo 'ACCEPT_KEYWORDS="~amd64' >> /etc/portage/make.conf

Synced portage and installed eix and genlop

emerge --sync && emerge -q genlop eix && eix-update

Emerged gcc

Check what version of gcc you are running with gcc-config -l and emerge it…

gcc-config -l
emerge -qv =sys-devel/gcc-9.1.0-r1

Switch to new gcc

gcc-config -l
gcc-config 2 # Be sure to select the new one you want
. /etc/profile
export PS1="(stage3) ${PS1}"

Package gcc

NB Despite switching to the new gcc BOTH installed versions were packaged by the following.

quickpkg gcc

Install newly packaged gcc in main system

Switch to a non-chroot environment, if you are still in a desktop environment and haven't rebooted then this is as simple as starting a new terminal and su, if you rebooted then use Ctrl+F2 to go to a new console, login and su. Install the newly packaged gcc with

tar xpf /mnt/stage3/usr/portage/packages/gcc-9.1.0-r1.tar.xz -C /

Test gcc on your main system

Try compiling a simple program on your main system

#include <stdio.h>
void main()
{
   printf("Hello world\n");
}
gcc test.c
./a.out

If that works try re-emerging gcc on your main system, if there are complaints about missing libraries compile them under the Stage3 environment, package them and then install on the main system. I was missing libmpfr.so.4 part of dev-lib/mpfr and needed to build and package =dev-libs/mpfr-4.0.2

Stage 3

emerge =dev-libs/mpfr-4.0.2
quickpkg dev-libs/mpfr-4.0.2

Main System

rsync -av /mnt/stage3/usr/portage/packages/* /var/cache/binpkgs/.
emerge -Kv =dev-libs/mpfr-4.0.2
===== Re-emerge missing packages or @world =====
 
You can now install in your normal install any packages for which you deleted their libraries.
 
<code bash>
time emerge -ev @world

Unmount /mnt/stage3

umount -l /mnt/stage3/dev{/shm,/pts,/proc}
umount -l /mnt/stage3/proc
umount /mnt/stage3

Links

linux/gentoo/rescue.txt · Last modified: 2021/03/20 19:21 by 127.0.0.1
CC Attribution-Share Alike 4.0 International
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0