Networkless Maintenance

Introduction
How do you maintain a Gentoo box that's not on the network? Here are a few tips.

Updating portage
You can update portage using another computer that has an internet connection. Most Gentoo mirrors have a directory with recent portage snapshots, so you can download the latest snapshot to your USB-key or other removable media and take that to your non-networked Gentoo box.

You can then delete your old portage directory and untar the new snapshot in its place. To complete the process you emerge the metadata (which is the last step in a normal emerge sync).

Replacing portage with new snapshot

 * 1) cd /usr
 * 2) rm -rf portage && tar xjvf /mnt/usbkey/portage-latest.tar.bz2 && emerge --metadata

A much cleaner approach uses the emerge-webrsync command:
 * 1)  emerge-webrsync -F  //only download, don't sync
 * 2)  mv /var/tmp/emerge-webrsync/XXXXXXXX.tar.bz2 /mnt/usb //where XXXXXXXX.tar.bz2 is the snapshot file downloaded, and /mnt/usb is a usb key


 * 1)  mkdir /var/tmp/emerge-webrsync
 * 2)  mv /mnt/usb/XXXXXXXXX.tar.bz2 /var/tmp/emerge-webrsync
 * 3)  emerge-webrsync

If the source machine (the one connected to the Internet) is not running Gentoo, manually download the snapshot file and its md5 checksum from your favorite Gentoo mirror (as described in chapter 5 of the Gentoo handbook) and copy both files to /var/tmp/emerge-webrsync/ on the target machine before running emerge-webrsync.

Emerging new programs or updates
When you have updated portage you may want to emerge updates or new programs. Without a network connection though, you cannot download the needed distfiles. So you need to find out what files you need to download and transfer these again from another computer that has an internet connection. After downloading the necessary files, you can place them in your distfiles directory, after which you can emerge them normally.

Get list of files required for emerge and pipe the URL's to a file
http://distfiles.gentoo.org/distfiles/genpatches-2.6.16-11.base.tar.bz2 http://distro.ibiblio.org/pub/linux/distributions/gentoo/distfiles/genpatches-2.6.16-11.base.tar.bz2 http://distfiles.gentoo.org/distfiles/linux-2.6.16.tar.bz2 http://distro.ibiblio.org/pub/linux/distributions/gentoo/distfiles/linux-2.6.16.tar.bz2 http://www.de.kernel.org/pub/linux/kernel/v2.6/linux-2.6.16.tar.bz2 http://distfiles.gentoo.org/distfiles/genpatches-2.6.16-11.extras.tar.bz2 http://distro.ibiblio.org/pub/linux/distributions/gentoo/distfiles/genpatches-2.6.16-11.extras.tar.bz2 ftp://lug.mtu.edu/gentoo/source/distfiles/genpatches-2.6.16-11.extras.tar.bz2 ftp://ftp.shspvr.com/download/wintv-pvr_150-500/inf/pvr_2.0.24.23035.zip http://dl.ivtvdriver.org/ivtv/archive/0.4.x/ivtv-0.4.5.tar.gz ftp://ftp.shspvr.com/download/wintv-pvr_250-350/inf/pvr_1.18.21.22254_inf.zip http://distfiles.gentoo.org/distfiles/mozilla-firefox-1.5.0.4-patches-1.0.tar.bz2 http://distro.ibiblio.org/pub/linux/distributions/gentoo/distfiles/mozilla-firefox-1.5.0.4-patches-1.0.tar.bz2 ftp://gentoo.mirrored.ca/distfiles/mozilla-firefox-1.5.0.4-patches-1.0.tar.bz2 http://distfiles.gentoo.org/distfiles/firefox-1.5.0.4-source.tar.bz2 http://distro.ibiblio.org/pub/linux/distributions/gentoo/distfiles/firefox-1.5.0.4-source.tar.bz2 ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/1.5.0.4/source/firefox-1.5.0.4-source.tar.bz2
 * 1) emerge --pretend --fetchonly world

Using wget to fetch distfiles
While generating a list of files to download is well and good, a large upgrade can require hundreds or thousands of files. You will almost certainly want to fetch your files automatically. This can be easily accomplished with wget.

Using sed and wget to fetch files automatically


 * 1) sed -r '/^(ht|f)tp:\/\//{s/ +/\n/g;p};d' emerge --pretend --fetchonly world | xargs wget -nc -nd -P distfiles

sed formats the URLs the way wget expects them. The -nc argument to wget assures that each file is only downloaded once (remember, there are multiple mirrors of files in the list). The -nd argument forces wget not to create subdirectories, and -P argument puts the downloads in the specified directory.

Note: for wget and sed on Windows, look at Cygwin, a BASH-like shell that runs under Windows. It can even be run from a USB flash drive.

Summary
For the following example, assume your removeable media is mounted under /mnt/usb and that a gentoo/distfiles subdirectory exists on that media.

Complete sequence of commands for networkless update

[online] Fetch portage-latest.tar.bz2 from one of the mirrors using your favorite web browser. Or, alternatively, using wget: [offline] Rename (or remove) /usr/portage. [offline] Untar portage-latest.tar.bz2 into /usr/portage [offline] Update portage metadata. [offline] Update portage. You might be able to skip this. [online] Fetch updated portage files.
 * 1) wget -nd http://distfiles.gentoo.org/snapshots/portage-latest.tar.bz2
 * 1) mv /usr/portage /usr/old-portage
 * 1) tar jxvf /mnt/usb/gentoo/portage-latest.tar.bz2 -C /usr
 * 1) emerge --metadata
 * 1) emerge --pretend --fetchonly --update portage > /mnt/usb/gentoo/portage.emerge
 * 1) sed -r '/^(ht|f)tp:\/\//{s/ +/\n/g;p};d' portage.emerge | xargs wget -nc -nd -P distfiles

[offline] Copy those files into /usr/portage/distfiles. [offline] Emerge latest portage. [offline] Update world. [online] Fetch world update files.
 * 1) cp -uv /mnt/usb/gentoo/distfiles/* /usr/portage/distfiles
 * 1) emerge --ask --update portage
 * 1) emerge  --pretend --fetchonly --update --deep world > /mnt/usb/gentoo/world.emerge
 * 1) sed -r '/^(ht|f)tp:\/\//{s/ +/\n/g;p};d' world.emerge | xargs wget -nc -nd -P distfiles

[offline] Copy those files into /usr/portage/distfiles. [offline] Emerge world.
 * 1) cp -uv /mnt/usb/gentoo/distfiles/* /usr/portage/distfiles
 * 1) emerge --ask --update --deep world