Migrating the ebuild repository locations in my Gentoo Linux installations to the current defaults

I installed Gentoo Linux on my two laptops in 2010 and 2015 respectively, long before the distribution’s developers changed the default locations of the repositories for ebuilds and packages in an installation. In 2023 I modified the two installations to use an eselect module instead of the superseded Layman overlay manager (see my earlier post ‘Layman overlay manager in Gentoo Linux superseded by eselect module‘), and the installations continued to function normally. In 2019 the distribution’s developers changed the default locations for the PORTDIR, DISTDIR, REPO_NAME and REPO_BASEDIR directories, although I do not recall seeing any notifications about the change or instructions on how to migrate the repository locations in existing installations. Anyway, today I decided to bite the bullet and migrate the repository locations in my two installations to the latest defaults specified by the developers. The old and new directories are listed in Gentoo Wiki article ‘Default Gentoo ebuild repository location change‘:

Old location
CODE Location before 2019-04-29

REPO_BASEDIR="/usr"
REPO_NAME="portage"
DISTDIR="/usr/portage/distfiles"
PORTDIR="/usr/portage"
TARGET_DISTDIR="/usr/portage/distfiles"
TARGET_PKGDIR="/usr/portage/packages"

New location
CODE Location as of 2019-04-29 and later

REPO_BASEDIR="/var/db/repos"
REPO_NAME="gentoo"
DISTDIR="/var/cache/distfiles"
PORTDIR="/var/db/repos/gentoo"
TARGET_DISTDIR="/var/cache/distfiles"
TARGET_PKGDIR="/var/cache/binpkgs"

The file /etc/portage/make.conf in one of my installations contained the following pertinent variables:

root # grep DIR /etc/portage/make.conf
PORTDIR="/usr/portage"
DISTDIR="${PORTDIR}/distfiles"
PKGDIR="${PORTDIR}/packages"
PORTDIR_OVERLAY="/usr/local/portage ${PORTDIR_OVERLAY}"
PORT_LOGDIR="/var/log/portage"

The repos.conf files contained:

root # cat /etc/portage/repos.conf/eselect-repo.conf
# created by eselect-repo

[guru]
location = /var/db/repos/guru
sync-type = git
sync-uri = https://anongit.gentoo.org/git/repo/proj/guru.git

[torbrowser]
location = /var/db/repos/torbrowser
sync-type = git
sync-uri = https://github.com/gentoo-mirror/torbrowser.git
root # cat /etc/portage/repos.conf/local_overlay.conf 
[local_overlay]
location = /usr/local/portage
masters = gentoo
auto-sync = no

I set about migrating the repository directories to the new default locations using the following steps:

1. I checked what was the current profile

root # eselect profile show
Current /etc/portage/make.profile symlink:
  default/linux/amd64/17.1/desktop/plasma

2. I commented out any PORTDIR, DISTDIR, PKGDIR, PORTDIR_OVERLAY and PORT_LOGDIR entries in /etc/portage/make.conf (man make.conf(5) states that PORTDIR, PORTDIR_OVERLAY and PORT_LOGDIR are deprecated anyway).

3. The directory /var/db/repos/ already existed, so I did not need to create it (I would have created it had it not already existed)

root # ls /var/db/repos/
guru  seden  torbrowser

4. I moved /usr/portage/distfiles/ to /var/cache/distfiles/

root # mv /usr/portage/distfiles /var/cache

5. There was no directory /usr/portage/packages/ in one of the installations, so I did not need to move it to /var/cache/binpkgs/ but I created the latter directory

root # mkdir /var/cache/binpkgs

In the other installation I moved /usr/portage/packages/ to /var/cache/binpkgs/

root # mv /usr/portage/packages /var/cache/binpkgs

6. I moved /usr/portage/ to /var/db/repos/gentoo/

root # mv /usr/portage /var/db/repos/gentoo

So now /var/db/repos/ contained directories with the ebuilds for the main Portage tree and for the third-party overlays:

root # ls /var/db/repos
gentoo  guru  seden  torbrowser

7. I moved /usr/local/portage/ to /var/db/repos/local/

root # mv /usr/local/portage /var/db/repos/local

The ebuild repositories for the main tree, third-party overlays and my local overlay have now all been moved:

root # ls /var/db/repos
gentoo  guru  local  seden  torbrowser

8. I edited the location variable in /etc/portage/repos.conf/gentoo.conf to contain ‘/var/db/repos/gentoo

root # grep location /etc/portage/repos.conf/gentoo.conf
location = /usr/portage
root # nano /etc/portage/repos.conf/gentoo.conf
root # grep location /etc/portage/repos.conf/gentoo.conf 
location = /var/db/repos/gentoo

9. I edited the location variable in /etc/portage/repos.conf/local_overlay.conf to contain ‘/var/db/repos/local

root # grep location /etc/portage/repos.conf/local_overlay.conf 
location = /usr/local/portage
root # nano /etc/portage/repos.conf/local_overlay.conf 
root # grep location /etc/portage/repos.conf/local_overlay.conf 
location = /var/db/repos/local

10. The location variable in the only other files in directory /etc/portage/repos.conf/ was already set to the correct location, otherwise I would have edited that too

root # ls /etc/portage/repos.conf/
eselect-repo.conf  eselect-repo.conf~  gentoo.conf  local_overlay.conf
root # grep location /etc/portage/repos.conf/eselect-repo.conf*
/etc/portage/repos.conf/eselect-repo.conf:location = /var/db/repos/guru
/etc/portage/repos.conf/eselect-repo.conf:location = /var/db/repos/torbrowser
/etc/portage/repos.conf/eselect-repo.conf~:location = /var/db/repos/guru
/etc/portage/repos.conf/eselect-repo.conf~:location = /var/db/repos/torbrowser

11. I edited any files that I found in /etc/portage/ and in its sub-directories that referenced the old locations

root # grep DIR /etc/portage/make.conf.catalyst
PORTDIR="/usr/portage"
DISTDIR="${PORTDIR}/distfiles"
PKGDIR="${PORTDIR}/packages"
root # nano /etc/portage/make.conf.catalyst
root # grep DIR /etc/portage/make.conf.catalyst
PORTDIR="/var/db/repos/gentoo"
DISTDIR="/var/cache/distfiles"
PKGDIR="/var/cache/binpkgs"
root # grep DIR /etc/portage/make.conf
#PORTDIR="/usr/portage"
#DISTDIR="${PORTDIR}/distfiles"
#PKGDIR="${PORTDIR}/packages"
#PORTDIR_OVERLAY="/usr/local/portage ${PORTDIR_OVERLAY}"
#PORT_LOGDIR="/var/log/portage"
root # nano /etc/portage/make.conf
root # grep DIR /etc/portage/make.conf
PORTDIR="/var/db/repos/gentoo"
DISTDIR="/var/cache/distfiles"
PKGDIR="/var/cache/binpkgs"
#PORTDIR_OVERLAY=""  <<<< Deprecated (see man make.conf)
#PORT_LOGDIR=""  <<<< Deprecated (see man make.conf)

12. I reinstated the profile symlink previously ascertained in Step 1 earlier

root # eselect profile list
realpath: /etc/portage/make.profile: No such file or directory
Available profile symlink targets:
  [1]   default/linux/amd64/17.1 (stable)
  [2]   default/linux/amd64/17.1/selinux (stable)
  [3]   default/linux/amd64/17.1/hardened (stable)
  [4]   default/linux/amd64/17.1/hardened/selinux (stable)
  [5]   default/linux/amd64/17.1/desktop (stable)
  [6]   default/linux/amd64/17.1/desktop/gnome (stable)
  [7]   default/linux/amd64/17.1/desktop/gnome/systemd (stable)
  [8]   default/linux/amd64/17.1/desktop/gnome/systemd/merged-usr (stable)
  [9]   default/linux/amd64/17.1/desktop/plasma (stable)
  [10]  default/linux/amd64/17.1/desktop/plasma/systemd (stable)
  [11]  default/linux/amd64/17.1/desktop/plasma/systemd/merged-usr (stable)
  [12]  default/linux/amd64/17.1/desktop/systemd (stable)
  [13]  default/linux/amd64/17.1/desktop/systemd/merged-usr (stable)
  [14]  default/linux/amd64/17.1/developer (exp)
  [15]  default/linux/amd64/17.1/no-multilib (stable)
  [16]  default/linux/amd64/17.1/no-multilib/hardened (stable)
  [17]  default/linux/amd64/17.1/no-multilib/hardened/selinux (stable)
  [18]  default/linux/amd64/17.1/no-multilib/systemd (dev)
  [19]  default/linux/amd64/17.1/no-multilib/systemd/merged-usr (dev)
  [20]  default/linux/amd64/17.1/no-multilib/systemd/selinux (exp)
  [21]  default/linux/amd64/17.1/no-multilib/systemd/selinux/merged-usr (exp)
  [22]  default/linux/amd64/17.1/systemd (stable)
  [23]  default/linux/amd64/17.1/systemd/merged-usr (stable)
  [24]  default/linux/amd64/17.1/systemd/selinux (exp)
  [25]  default/linux/amd64/17.1/systemd/selinux/merged-usr (exp)
  [26]  default/linux/amd64/17.1/clang (exp)
  [27]  default/linux/amd64/17.1/systemd/clang (exp)
  [28]  default/linux/amd64/17.1/systemd/clang/merged-usr (exp)
  [29]  default/linux/amd64/17.0/x32 (dev)
  [30]  default/linux/amd64/17.0/x32/systemd (exp)
  [31]  default/linux/amd64/17.0/x32/systemd/merged-usr (exp)
  [32]  default/linux/amd64/17.0/musl (dev)
  [33]  default/linux/amd64/17.0/musl/clang (exp)
  [34]  default/linux/amd64/17.0/musl/hardened (exp)
  [35]  default/linux/amd64/17.0/musl/hardened/selinux (exp)
root # eselect profile set 9
root # eselect profile show
Current /etc/portage/make.profile symlink:
  default/linux/amd64/17.1/desktop/plasma

13. I reinstalled Portage for the new repository locations

root # DISTDIR=/var/cache/distfiles PKGDIR=/var/cache/binpkgs emerge -1v portage

14. That completed the migration. I then rebooted and performed the usual ebuild repository update and package upgrade as shown in an earlier post.

About Fitzcarraldo
A Linux user with an interest in all things technical.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.