Sunday, March 18, 2007

apt-move An Easy Guide







Google

















Hail Ubuntu!

Its been a long time since i blogged! Now i just could not stop myself from posting this.

In this blog I am trying explain how to back up your updates on Ubuntu. Its a known fact that the install CD of Ubuntu is very skeletal. One needs to connect to the net for every complete (by this i mean the programmers' choice of packages)installation. In this blog let me tell some not so unknown method to back up the updates.

Let me add a note here! WARNING : Using this method you can only backup those packages that you have downloaded and installed!! Hell!! you cant backup something you don't have right! ;)

The CD created using the procedure mentioned below can be used as a repository to install the packages in any other machine using Synaptic or apt-cdrom.

I referred the contents in https://help.ubuntu.com/community/AptMoveHowto while writing this blog. I am not putting in anything new!! Its just an attempt to make the content reachable to everyone.

I am going to make use of the same example here too!! I definitely works with a full featured installation.

There are two steps involved in the process of creating the repository CD.

1 : Creating the GPG key for the CD,
2 : Creating the CD from the downloaded packages.

Creating the GPG key
(I am going to update this section with some much simpler procedure, once i am sure it works out!)

Using GnuPG

gpg --gen-key

This will lead to a selection screen with the following options

Please select what kind of key you want: (1) DSA and Elgamal (default) (2) DSA (sign only) (5) RSA (sign only)

The default choice (1) is preferred, since the others cannot be used for encryption.

What keysize do you want? (2048)

A keysize of 2048 (which is the default) is also a good choice.

Key is valid for? (0)

Most people make their keys valid until infinity, which is the default option. If you do this don't forget to revoke the key when you no longer use it (see later). Hit Y and proceed.

You need a user ID to identify your key; the software constructs the user ID from the Real Name, Comment and Email Address in this form: "Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>" Real name: Dennis Kaarsemaker Email address: dennis@kaarsemaker.net Comment: Tutorial key You selected this USER-ID: "Dennis Kaarsemaker (Tutorial key) <dennis@kaarsemaker.net>"

Make sure that the name on the key matches the name in your passport, or other government issued photo-identification! You can add extra e-mail addresses to the key later.

Type O to create your key.

You need a Passphrase to protect your secret key.

You will be asked for your passphrase twice. Usually, a short sentence or phrase that isn't easy to guess can be used.

IMPORTANT - Forgetting your passphrase will result in your key being useless. Remember this passphrase carefully, there is no way to recover it when it's lost. After you type your passphrase twice, the key will be generated. Please follow the instructions on the screen till you reach a screen similiar to the one below.

gpg: key D8FC66D2 marked as ultimately trusted public and secret key created and signed. pub 1024D/D8FC66D2 2005-09-08 Key fingerprint = 95BD 8377 2644 DD4F 28B5 2C37 0F6E 4CA6 D8FC 66D2 uid Dennis Kaarsemaker (Tutorial key) <dennis@kaarsemaker.net> sub 2048g/389AA63E 2005-09-08

The key-id is D8FC66D2 (yours will be different).

Tip: It's probably a good idea to set this key as default in your .bashrc, so that applications using GPG can automatically use your key. Do this by entering the line below in your ~/.bashrc. Please note that will be sourced only during your next session, unless you source it manually.

export GPGKEY=D8FC66D2

Now restart the gpg-agent and source your .bashrc again:

killall -q gpg-agent eval $(gpg-agent --daemon) source ~/.bashrc

Revocation Certificate

A revocation certificate must be generated to revoke your public key if your private key has been compromised in any way. You can create a revocation certificate by doing

gpg --output revoke.asc --gen-revoke
The key may be printed and stored carefully preventing access to it. Anybody having access to your revocation certificate can render the public key useless.


Creating the repository CD

U will need to install the apt-move package

Apt-move is a tool for creating a Debian package repository file structure out of packages that have been downloaded to /var/cache/apt/archives . Archives folder basically contains the packages that are downloaded for installation. apt-move creates a local repository out of this archive in the /mirror/debian folder.

sudo aptitude install apt-move

now you have to change the setting in
/etc/apt-move.conf to allow retention of files in the
/var/cache/apt/archives/ folder.

Find the line


COPYONLY=no

and change it to

COPYONLY=yes


Select the packages that should be added to the CD.


To add only the packages that were downloaded and install , we shall clean the
/var/cache/apt/archives/
folder off the old packages.

sudo aptitude autoclean


Now run apt-move to create the archive structure

WARNING : Make sure you have enough disk space!!

/mirrors/debian is root owned. Becoming root makes the steps easier. Avoids typing a lot of sudo :)

sudo -s

All the following command run as root.

First we clean-up previous mirrors (if exists) then we run apt-move.

rm -rf /mirrors/debian
apt-move -d dapper update

Because Ubuntu repository structure, not all packages are inserted into the Packages.gz file by apt-move. We must remake Packages.gz with the help of apt-ftparchive.

cd /mirrors/debian
apt-ftparchive packages pool/main/ \
| gzip -9c > dists/dapper/main/binary-i386/Packages.gz
apt-ftparchive packages pool/restricted/ \
| gzip -9c > dists/dapper/restricted/binary-i386/Packages.gz

Now remake Release file, to do this we must make an apt configuration file named ~/myapt.conf it contents is like this :

APT::FTPArchive::Release {
Origin "APT-Move";
Label "APT-Move";
Suite "dapper";
Codename "dapper";
Architectures "i386";
Components "main restricted";
Description "Ubuntu Updates CD";
};
Next, run the following commands:
rm dists/dapper/Release
apt-ftparchive -c ~/myapt.conf release dists/dapper/ > Release
mv Release dists/dapper/
Next make a Release.gpg, to make it you must already have your GPG Key (explained earliet) set and ready to sign.
gpg -bao dists/dapper/Release.gpg dists/dapper/Release

Delete unwanted .apt-move directory
rm -rf .apt-move

You can identify the CD by making a .disk directory and making an info file in it. (Suggested for first timers)
mkdir .disk
echo Ubuntu-Updates `date +%Y-%m-%d` > .disk/info

Then put the public keys in it.

gpg --export -a  > public.key  to be replaced with the name that you use in your PGP.

And thats the end of the task. exit the root account.

exit


Time to burn the CD :)

You could make an iso by following command:
mkisofs -r -A "Ubuntu Updates `date +%Y%m%d`" -o ubuntu-updates.iso \
/mirrors/debian
Before you could use the CD, you need to add our GPG key to apt GPG keys. Put the CD on CD-ROM Drive, mount it (if it not automatically mounted) then run the following:
apt-key add /cdrom/public.key

Use this CD like any other Ubuntu CD. On a non-networked Ubuntu machine, you can run synaptic, insert the CD and go into Synaptic -> Edit -> Add Cdrom and it will add the contents of the CD to your repositories.

You can also do it from the command-line with

sudo apt-cdrom add


Hope you folks can get this thing working without hassle!!!

Cheers


Akshay
Lin-Aks

BMSCE