From Gentoo no-multilib to multilib without reinstalling

When I installed my server I though I will have a only 64bit system. Well that proved to be wrong, whereas the reason is irrelevant. But going back to a multilib profile from a no-multilib one is nearly impossible without some external help, the outside help being a VM with a Gentoo running.

Prerequisits

  1. Get current Gentoo Linux. I used the LiveCD for that, which can be found at https://www.gentoo.org/downloads/
  2. Choose a Hypervisor. I used Hyper-V for this. See Gentoo Linux on Hyper-V on how to set it up
  3. Make sure you current Kernel of the multilib target system supports executing 32bit executable. Check if CONFIG_IA32_EMULATION=y is enabled!

Prepare the VM for compiling

Next step is to prepare the VM for compiling the packages you need which are gcc and glibc.

Disk space

The diskspace of the Live DVD is very limited so we want to use the virtual disk for the storage of portage and swap. So let’s first create a new disk using fdisk /dev/sda and afterwards create a filesystem on the new disk using mkfs.ext3 /dev/sda1.
Then mount the disk: mount /dev/sda1 /mnt/gentoo

Portage

I opted to put the whole portage tree onto the new drive, just to not run out of disk space.

mv /usr/portage /mnt/gentoo
ln -s /mnt/gentoo/portage /usr/portage
mkdir /mnt/gentoo/temp
vim /etc/portage/make.conf

In the make.conf add and set the variable PORTAGE_TMPDIR=/mnt/gentoo/temp

Now run a emege –sync to fetch the current tree

Swap file

I ran into the problem, that the VM’s memory was exhausted and thus needed to setup a Swap. This can be done quite easily by using a swap file  🙂

dd if=/dev/zero of=/mnt/gentoo/swapfile bs=1024 count=$(echo 2*1024*1024|bc)
mkswap /mnt/gentoo/swapfile
swapon /mnt/gentoo/swapfile

Voile la. The command free -h should now give something like. The echo 2*1024*1024 is to create a 2GB file

hyper-v root # free -h
              gesamt       benutzt     frei      gemns.  Puffer/Cache verfügbar
Speicher:         15G        3,5G        6,0G        671M        6,1G         11G
Swap:             31G         16M         31G

Compiling gcc and glibc

To solve the chicken and the egg problem on the multilib target system we use the VM to compile binary packages which we then will install on the multilib target system. A very helpful post about how to switch to multilib can be found at the Gentoo Forums, which I summarized in the following steps:

  1. Set all the values like CFLAGS etc to the likes of the server. In my case that was CFLAGS=“-march=ivybridge -O2 -pipe“.
  2. Look for the versions and use flags of the packages gcc and glibc
  3. Run emerge -avB =sys-libs/glibc-2.23-r3 =sys-devel/gcc-5.4.0-r3 (fix the versions to match yours!)
  4. The the binary packages via WinSCP or similar to your host. They can be found at /usr/portage/packages. Form there copy all the folders.
  5. Upload binary packages to your multilib target system to /usr/portage/packages. If directory does not exist, create it.
  6. Set the profile to a multilib one using eselct profile set <N> and then run emerge -avK gcc glibc
  7. Using the new multilib profile we emerge -av sanbox binutils to make sure to have a basic mutlilib compiling environment
  8. Finally run emerge -eaq @world

After the world was emerged again everything should be in place and you have a full multilib system.

1 Comment

  1. Markus says:

    Thanks this worked, alltough i did it with chrooting in a downloaded stage3 as gentoo steam tells to do , but did it with multilib and didnt have to cpy those gcc .etc. ..

Schreibe einen Kommentar

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.