Article Index

Step 2: download packages and prepare image for installation

Download packages

There are two ways of downloading the initial packages:

  • Download the tar file I have available¬†here (md5sum: 3b4236ffb0fb97c36dda6179db4d7359) and unpack the tar to /root/packages. This is really quick and you have the same package versions I used. The drawback is that over time, these packages will really become outdated (up until the point that I decide to remove this option all together).
  • Or download the most recent versions directly from the Raspbian repository. This will require some manual work to find out where to download them from, but you will install up-2-date packages right from the start. To do this, follow these steps:
  1.  Create a location for downloading the first packages:
    mkdir /root/packages
  2. Download all packages that we will install without apt. We download this directly from the Raspbian repository, for which we can find the location on the Raspbian website. At the time of writing the location is http://archive.raspbian.org/raspbian/
  3. Here we can find a directory 'dists', containing the different versions of Raspbian. We are working with Wheezy (but this can change in the future of course), so enter that directory. Now choose for the main repository and there for the binary-armhf packages.
  4. Here you can find a file Packages, which contains the list of packages in this repository. A shortcut: http://archive.raspbian.org/raspbian/dists/wheezy/main/binary-armhf/Packages Open this file with a text editor. Here you can search for 'Package: apt'. You can see the 'Filename' field, which points you to where the package can be downloaded from (prepend the location with the repository root: http://archive.raspbian.org/raspbian/ ). Download this package:
    cd /root/packages
    wget http://archive.raspbian.org/raspbian/pool/main/a/apt/apt_0.9.7.9+rpi1+deb7u1_armhf.deb
    These commands are just an example. The location can change in the future if there is a new version of apt, so create the url based on the information in the Packages file!
  5. Are we there yet? No, by far not. As I've told before, packages can have dependencies and we need to download and install those packages first. In the 'Packages' file, look at the 'Depends' field (and at the 'Pre-Depends' field if it is present). There is a list of other packages which need to be installed before we can install apt. You can lookup those packages and will find that they too depend on packages. Basically we will have to find and download all dependencies (of dependencies of dependencies of dependencies.....) until we reach a level where the packages have no dependencies any more. And then we are still not there yet, because, besides apt, we will need some other tools/packages to be able to run the installation scripts: core-utils (contains basic commands like cp), sed, grep and findutils. You will need to lookup and download those packages and their dependencies too. To save you the trouble, here is the current list of packages needed:
    apt
    coreutils
    debianutils
    dpkg
    findutils gcc-4.7-base gnupg gpgv grep libacl1 libapt-pkg4.12 libattr1 libbz2-1.0 libc6 libc-bin libgcc1 liblzma5 libreadline6 libselinux1 libstdc++6 libtinfo5 libusb-0.1-4 multiarch-support raspbian-archive-keyring readline-common sed sensible-utils tar zlib1g
    In short; find these packages and their download location in the Packages file and then download them to the directory /root/packages/

Prepare image for installation

Because dpkg will 'chroot' into the /target/ directory, there should be some directories and files present which dpkg needs to keep track of what is installed etc. If you don't know what 'chroot' is, please look it up. In short; chroot will 'fool' an application into believing some directory is the root of the file system (so while the application thinks it writes to /etc/somefile, in 'reality' it writes to /target/etc/somefile).
Here are the commands for creating the locations required by dpkg:

mkdir -p /target/var/lib/dpkg/updates
touch /target/var/lib/dpkg/status
touch /target/var/lib/dpkg/available
mkdir /target/var/lib/dpkg/info
touch /target/var/lib/dpkg/info/format-new

And last but not least; all installation scripts require (/target)/bin/sh, but of course we don't have that available yet. There is a package bash-static, which contains a statically linked bash (so it does not need any libraries to be installed). Let's install that on the host system and copy it to the new image and link sh to it. Later on this will automatically be overwritten when we install the normal bash package.

apt-get install bash-static
mkdir /target/bin
cp /bin/bash-static /target/bin/bash
cd /target/bin
ln -s bash sh

Add comment


Security code
Refresh